Skip to content
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

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

Merged
merged 5 commits into from
Jan 18, 2024
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
16 changes: 16 additions & 0 deletions core/src/components/picker-internal/picker-internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
averyjohnston marked this conversation as resolved.
Show resolved Hide resolved
*
* 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()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,44 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
await expect(ionChange).toHaveReceivedEventDetail({ text: '00', value: 12 });
await expect(column).toHaveJSProperty('value', 12);
});
test('pressing Enter should dismiss the keyboard', async ({ page }) => {
test.info().annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/28325',
});
await page.setContent(
`
<ion-picker-internal>
<ion-picker-column-internal></ion-picker-column-internal>
</ion-picker-internal>

<script>
const column = document.querySelector('ion-picker-column-internal');
column.items = [
{ text: '00', value: 12 },
{ text: '01', value: 1 },
{ text: '02', value: 2 },
{ text: '03', value: 3 },
{ text: '04', value: 4 },
{ text: '05', value: 5 }
];
column.value = 5;
column.numericInput = true;
</script>
`,
config
);

const column = page.locator('ion-picker-column-internal');
await column.click();

const input = page.locator('ion-picker-internal input');
await expect(input).toBeFocused();

// pressing Enter should blur the input and therefore close the keyboard
await page.keyboard.press('Enter');

await expect(input).not.toBeFocused();
});
});
});
Loading