Skip to content

Commit

Permalink
fix(VirtualInput): should not block of long press (#6477)
Browse files Browse the repository at this point in the history
* fix(VirtualInput): should not  block of long press

* chore: adjust blur logic
  • Loading branch information
zombieJ authored Dec 13, 2023
1 parent dcff0b8 commit 1756288
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/number-keyboard/number-keyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export const NumberKeyboard: FC<NumberKeyboardProps> = p => {
onKeyPress(e, 'BACKSPACE')
onBackspacePressEnd()
}}
onContextMenu={e => {
// Long press should not trigger native context menu
e.preventDefault()
}}
title='BACKSPACE'
role='grid'
tabIndex={-1}
Expand Down
11 changes: 10 additions & 1 deletion src/components/virtual-input/virtual-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ export const VirtualInput = forwardRef<VirtualInputRef, VirtualInputProps>(
},
visible: hasFocus,
onClose: () => {
rootRef.current?.blur()
const activeElement = document.activeElement as HTMLElement

// Long press makes `activeElement` to be the child of rootRef
// We will trigger blur on the child element instead
if (activeElement && rootRef.current?.contains(activeElement)) {
activeElement.blur()
} else {
rootRef.current?.blur()
}

keyboard.props.onClose?.()
},
getContainer: null,
Expand Down

0 comments on commit 1756288

Please sign in to comment.