-
Notifications
You must be signed in to change notification settings - Fork 14
feat(dial-pad): add long press on '0' button to render '+' (VIV-2876) #2585
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,16 @@ function handleKeyDown(x: DialPad, e: KeyboardEvent) { | |
| e.target instanceof HTMLInputElement | ||
| ) { | ||
| x._onDial(); | ||
| } else if (e.key === ' ' || e.key === 'Space') { | ||
| // Handle long-press Space for '0' button when input is active | ||
| if (e.target instanceof HTMLInputElement) { | ||
| e.preventDefault(); | ||
| // Only start on first keydown, ignore repeat events | ||
| // keydown events repeat while key is held, so we only start the timer once | ||
| if (!e.repeat) { | ||
| x._startKeyboardLongPress(); | ||
| } | ||
| } | ||
| } else { | ||
| const elementIndex = DIAL_PAD_BUTTONS.findIndex((x) => x.value === e.key); | ||
| if (elementIndex > -1) { | ||
|
|
@@ -93,6 +103,23 @@ function handleKeyDown(x: DialPad, e: KeyboardEvent) { | |
| return true; | ||
| } | ||
|
|
||
| function handleKeyUp(x: DialPad, e: KeyboardEvent) { | ||
| if (e.key === ' ' || e.key === 'Space') { | ||
| if (e.target instanceof HTMLInputElement) { | ||
| e.preventDefault(); | ||
|
|
||
| const wasLongPress = x._endKeyboardLongPress(); | ||
| if (!wasLongPress && !x.disabled && !x.callActive) { | ||
| // Short press - add space character (normal space input) | ||
| x.value += ' '; | ||
| x.$emit('input'); | ||
| x.$emit('change'); | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| function syncFieldAndPadValues(x: DialPad) { | ||
| x.value = x._textFieldEl.value; | ||
| } | ||
|
|
@@ -122,6 +149,7 @@ function renderTextField( | |
| x.helperText}" pattern="${(x) => x.pattern}" | ||
| aria-label="${(x) => x.locale.dialPad.inputLabel}" | ||
| @keydown="${(x, c) => handleKeyDown(x, c.event as KeyboardEvent)}" | ||
| @keyup="${(x, c) => handleKeyUp(x, c.event as KeyboardEvent)}" | ||
| @input="${syncFieldAndPadValues}" | ||
| @change="${syncFieldAndPadValues}" | ||
| @focus="${stopPropagation}" | ||
|
|
@@ -147,6 +175,11 @@ function onDigitClick( | |
| digit: DialPadButton, | ||
| { parent: dialPad, event }: { parent: DialPad; event: MouseEvent } | ||
| ) { | ||
| if (dialPad._suppressNextClick) { | ||
| // Skip the click insertion if a long-press already handled it | ||
| dialPad._suppressNextClick = false; | ||
| return; | ||
| } | ||
| dialPad.value += digit.value; | ||
|
|
||
| dialPad.$emit('keypad-click', event.currentTarget); | ||
|
|
@@ -175,6 +208,11 @@ function renderDigits( | |
| c.parent.autofocus && c.parent.noInput && c.index === 0}" | ||
| aria-label="${(x, c) => c.parent.locale.dialPad[x.ariaLabel]}" | ||
| ?disabled="${(_, c) => c.parent.disabled}" | ||
| @pointerdown="${(x, c) => | ||
| c.parent._startLongPress(x.value, c.event as PointerEvent)}" | ||
| @pointerup="${(_, c) => c.parent._endLongPress()}" | ||
| @pointercancel="${(_, c) => c.parent._cancelLongPress()}" | ||
| @pointerleave="${(_, c) => c.parent._cancelLongPress()}" | ||
| @click="${onDigitClick}"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about long-pressing with the keyboard? It should probably long-press with space as well
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For 'long-press with space' it should be handled by input, but not digit buttons. I have added the implementation |
||
| <${iconTag} slot="icon" | ||
| name="${(x) => x.icon}" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.