From bac10659e06504d6452c3134fa546c3e7a0d7a62 Mon Sep 17 00:00:00 2001 From: samunohito <46447427+samunohito@users.noreply.github.com> Date: Sun, 28 Jul 2024 07:37:18 +0900 Subject: [PATCH] fix focus --- .../src/components/grid/MkDataCell.vue | 30 ++++++++++++------- .../src/components/grid/cell-validators.ts | 11 ++----- .../custom-emojis-manager.local.list.vue | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/packages/frontend/src/components/grid/MkDataCell.vue b/packages/frontend/src/components/grid/MkDataCell.vue index ce1aabefd9..d20ba00f5a 100644 --- a/packages/frontend/src/components/grid/MkDataCell.vue +++ b/packages/frontend/src/components/grid/MkDataCell.vue @@ -135,7 +135,7 @@ watch(() => [cell.value.value], () => { watch(() => cell.value.selected, () => { if (cell.value.selected) { - rootEl.value?.focus(); + requestFocus(); } }); @@ -151,8 +151,7 @@ function onCellDoubleClick(ev: MouseEvent) { function onOutsideMouseDown(ev: MouseEvent) { const isOutside = ev.target instanceof Node && !rootEl.value?.contains(ev.target); if (isOutside || !equalCellAddress(cell.value.address, getCellAddress(ev.target as HTMLElement))) { - endEditing(true, editingValue.value); - editingValue.value = undefined; + endEditing(true, false); } } @@ -170,15 +169,13 @@ function onCellKeyDown(ev: KeyboardEvent) { } else { switch (ev.code) { case 'Escape': { - endEditing(false, editingValue.value); - editingValue.value = undefined; + endEditing(false, true); break; } case 'NumpadEnter': case 'Enter': { if (!ev.isComposing) { - endEditing(true, editingValue.value); - editingValue.value = undefined; + endEditing(true, true); } } } @@ -203,7 +200,7 @@ function unregisterOutsideMouseDown() { } async function beginEditing(target: HTMLElement) { - if (editing.value || !cell.value.column.setting.editable) { + if (editing.value || !cell.value.selected || !cell.value.column.setting.editable) { return; } @@ -221,7 +218,7 @@ async function beginEditing(target: HTMLElement) { emitValueChange(newValue); } - rootEl.value?.focus(); + requestFocus(); } else { switch (cellType.value) { case 'number': @@ -249,11 +246,14 @@ async function beginEditing(target: HTMLElement) { } } -function endEditing(applyValue: boolean, newValue: CellValue) { +function endEditing(applyValue: boolean, requireFocus: boolean) { if (!editing.value) { return; } + const newValue = editingValue.value; + editingValue.value = undefined; + emit('operation:endEdit', cell.value); unregisterOutsideMouseDown(); @@ -263,7 +263,15 @@ function endEditing(applyValue: boolean, newValue: CellValue) { editing.value = false; - rootEl.value?.focus(); + if (requireFocus) { + requestFocus(); + } +} + +function requestFocus() { + nextTick(() => { + rootEl.value?.focus(); + }); } function emitValueChange(newValue: CellValue) { diff --git a/packages/frontend/src/components/grid/cell-validators.ts b/packages/frontend/src/components/grid/cell-validators.ts index f0f6af31fc..949cab2ec6 100644 --- a/packages/frontend/src/components/grid/cell-validators.ts +++ b/packages/frontend/src/components/grid/cell-validators.ts @@ -81,16 +81,9 @@ class ValidatorPreset { regex(pattern: RegExp): GridCellValidator { return { name: 'regex', - validate: ({ value, column }): ValidatorResult => { - if (column.setting.type !== 'text') { - return { - valid: false, - message: i18n.ts._gridComponent._error.columnTypeNotSupport, - }; - } - + validate: ({ value }): ValidatorResult => { return { - valid: pattern.test(value?.toString() ?? ''), + valid: (typeof value !== 'string') || pattern.test(value.toString() ?? ''), message: i18n.tsx._gridComponent._error.patternNotMatch({ pattern: pattern.source }), }; }, diff --git a/packages/frontend/src/pages/admin/custom-emojis-manager.local.list.vue b/packages/frontend/src/pages/admin/custom-emojis-manager.local.list.vue index 417bd72c9c..8c80ee61f9 100644 --- a/packages/frontend/src/pages/admin/custom-emojis-manager.local.list.vue +++ b/packages/frontend/src/pages/admin/custom-emojis-manager.local.list.vue @@ -580,7 +580,7 @@ async function refreshCustomEmojis() { query: query, limit: limit, page: currentPage.value, - sortKeys: sortOrders.value.map(({ key, direction }) => `${direction}${key}`), + sortKeys: sortOrders.value.map(({ key, direction }) => `${direction}${key}` as any), }), () => { },