Skip to content

Commit 1756288

Browse files
authored
fix(VirtualInput): should not block of long press (#6477)
* fix(VirtualInput): should not block of long press * chore: adjust blur logic
1 parent dcff0b8 commit 1756288

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/components/number-keyboard/number-keyboard.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ export const NumberKeyboard: FC<NumberKeyboardProps> = p => {
229229
onKeyPress(e, 'BACKSPACE')
230230
onBackspacePressEnd()
231231
}}
232+
onContextMenu={e => {
233+
// Long press should not trigger native context menu
234+
e.preventDefault()
235+
}}
232236
title='BACKSPACE'
233237
role='grid'
234238
tabIndex={-1}

src/components/virtual-input/virtual-input.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ export const VirtualInput = forwardRef<VirtualInputRef, VirtualInputProps>(
107107
},
108108
visible: hasFocus,
109109
onClose: () => {
110-
rootRef.current?.blur()
110+
const activeElement = document.activeElement as HTMLElement
111+
112+
// Long press makes `activeElement` to be the child of rootRef
113+
// We will trigger blur on the child element instead
114+
if (activeElement && rootRef.current?.contains(activeElement)) {
115+
activeElement.blur()
116+
} else {
117+
rootRef.current?.blur()
118+
}
119+
111120
keyboard.props.onClose?.()
112121
},
113122
getContainer: null,

0 commit comments

Comments
 (0)