Skip to content

Commit c47a16d

Browse files
authored
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`
1 parent 0847c2a commit c47a16d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

core/src/components/picker-internal/picker-internal.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ export class PickerInternal implements ComponentInterface {
265265

266266
inputEl.focus();
267267
} else {
268+
// TODO FW-5900 Use keydown instead
268269
el.addEventListener('keypress', this.onKeyPress);
269270
this.destroyKeypressListener = () => {
270271
el.removeEventListener('keypress', this.onKeyPress);
@@ -550,6 +551,21 @@ export class PickerInternal implements ComponentInterface {
550551
tabindex={-1}
551552
inputmode="numeric"
552553
type="number"
554+
onKeyDown={(ev: KeyboardEvent) => {
555+
/**
556+
* The "Enter" key represents
557+
* the user submitting their time
558+
* selection, so we should blur the
559+
* input (and therefore close the keyboard)
560+
*
561+
* Updating the picker's state to no longer
562+
* be in input mode is handled in the onBlur
563+
* callback below.
564+
*/
565+
if (ev.key === 'Enter') {
566+
this.inputEl?.blur();
567+
}
568+
}}
553569
ref={(el) => (this.inputEl = el)}
554570
onInput={() => this.onInputChange()}
555571
onBlur={() => this.exitInputMode()}

core/src/components/picker-internal/test/keyboard-entry/picker-internal.e2e.ts

+39
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,44 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
133133
await expect(ionChange).toHaveReceivedEventDetail({ text: '00', value: 12 });
134134
await expect(column).toHaveJSProperty('value', 12);
135135
});
136+
test('pressing Enter should dismiss the keyboard', async ({ page }) => {
137+
test.info().annotations.push({
138+
type: 'issue',
139+
description: 'https://github.com/ionic-team/ionic-framework/issues/28325',
140+
});
141+
await page.setContent(
142+
`
143+
<ion-picker-internal>
144+
<ion-picker-column-internal></ion-picker-column-internal>
145+
</ion-picker-internal>
146+
147+
<script>
148+
const column = document.querySelector('ion-picker-column-internal');
149+
column.items = [
150+
{ text: '00', value: 12 },
151+
{ text: '01', value: 1 },
152+
{ text: '02', value: 2 },
153+
{ text: '03', value: 3 },
154+
{ text: '04', value: 4 },
155+
{ text: '05', value: 5 }
156+
];
157+
column.value = 5;
158+
column.numericInput = true;
159+
</script>
160+
`,
161+
config
162+
);
163+
164+
const column = page.locator('ion-picker-column-internal');
165+
await column.click();
166+
167+
const input = page.locator('ion-picker-internal input');
168+
await expect(input).toBeFocused();
169+
170+
// pressing Enter should blur the input and therefore close the keyboard
171+
await page.keyboard.press('Enter');
172+
173+
await expect(input).not.toBeFocused();
174+
});
136175
});
137176
});

0 commit comments

Comments
 (0)