Skip to content

fix(VirtualInput): should not block of long press #6477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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