fix(datetime): enter closes keyboard when typing time (#28848)

Issue number: resolves #28325

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

When typing the time into the date picker pressing "Enter" does not
close the on-screen keyboard.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Pressing "Enter" closes the on-screen keyboard

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->


Test:

⚠️ While I have a test for this, please also test this on a physical
Android device.

1. Go to `src/components/datetime/test/basic`
2. Open the time picker (in any of the date times)
3. Tap the time to open the keyboard
4. Press "Enter" on Android. Observe that the keyboard closes.

Dev build: `7.6.6-dev.11705528328.1ef5e17b`
This commit is contained in:
Liam DeBeasi
2024-01-18 13:15:22 -05:00
committed by GitHub
parent 0847c2ac2c
commit c47a16d6c3
2 changed files with 55 additions and 0 deletions

View File

@ -265,6 +265,7 @@ export class PickerInternal implements ComponentInterface {
inputEl.focus();
} else {
// TODO FW-5900 Use keydown instead
el.addEventListener('keypress', this.onKeyPress);
this.destroyKeypressListener = () => {
el.removeEventListener('keypress', this.onKeyPress);
@ -550,6 +551,21 @@ export class PickerInternal implements ComponentInterface {
tabindex={-1}
inputmode="numeric"
type="number"
onKeyDown={(ev: KeyboardEvent) => {
/**
* The "Enter" key represents
* the user submitting their time
* selection, so we should blur the
* input (and therefore close the keyboard)
*
* Updating the picker's state to no longer
* be in input mode is handled in the onBlur
* callback below.
*/
if (ev.key === 'Enter') {
this.inputEl?.blur();
}
}}
ref={(el) => (this.inputEl = el)}
onInput={() => this.onInputChange()}
onBlur={() => this.exitInputMode()}