Skip to content

Commit eaface1

Browse files
committed
fix(select): add Enter keypress to dismiss
1 parent a2e803a commit eaface1

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

core/src/components/select-modal/select-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class SelectModal implements ComponentInterface {
9595
labelPlacement="end"
9696
onClick={() => this.closeModal()}
9797
onKeyUp={(ev) => {
98-
if (ev.key === ' ') {
98+
if (ev.key === 'Enter' || ev.key === ' ') {
9999
/**
100100
* Selecting a radio option with keyboard navigation,
101101
* either through the Enter or Space keys, should

core/src/components/select-modal/test/basic/select-modal.e2e.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
6464
await expect(selectModalPage.modal).not.toBeVisible();
6565
});
6666

67+
test('pressing Enter on an unselected option should dismiss the modal', async () => {
68+
await selectModalPage.setup(config, options, false);
69+
70+
await selectModalPage.pressEnterOnOption('apple');
71+
await selectModalPage.ionModalDidDismiss.next();
72+
await expect(selectModalPage.modal).not.toBeVisible();
73+
});
74+
75+
test('pressing Enter on a selected option should dismiss the modal', async ({ browserName }) => {
76+
test.skip(browserName === 'firefox', 'Same behavior as ROU-5437');
77+
78+
await selectModalPage.setup(config, checkedOptions, false);
79+
80+
await selectModalPage.pressEnterOnOption('apple');
81+
await selectModalPage.ionModalDidDismiss.next();
82+
await expect(selectModalPage.modal).not.toBeVisible();
83+
});
84+
6785
test('clicking the close button should dismiss the modal', async () => {
6886
await selectModalPage.setup(config, options, false);
6987

core/src/components/select-modal/test/fixtures.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class SelectModalPage {
6363
await option.press('Space');
6464
}
6565

66+
async pressEnterOnOption(value: string) {
67+
const option = this.getOption(value);
68+
await option.press('Enter');
69+
}
70+
6671
private getOption(value: string) {
6772
const { multiple, selectModal } = this;
6873
const selector = multiple ? 'ion-checkbox' : 'ion-radio';

core/src/components/select-popover/select-popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class SelectPopover implements ComponentInterface {
160160
disabled={option.disabled}
161161
onClick={() => this.dismissParentPopover()}
162162
onKeyUp={(ev) => {
163-
if (ev.key === ' ') {
163+
if (ev.key === 'Enter' || ev.key === ' ') {
164164
/**
165165
* Selecting a radio option with keyboard navigation,
166166
* either through the Enter or Space keys, should

core/src/components/select-popover/test/basic/select-popover.e2e.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
6363
await selectPopoverPage.ionPopoverDidDismiss.next();
6464
await expect(selectPopoverPage.popover).not.toBeVisible();
6565
});
66+
67+
test('pressing Enter on an unselected option should dismiss the popover', async () => {
68+
await selectPopoverPage.setup(config, options, false);
69+
70+
await selectPopoverPage.pressEnterOnOption('apple');
71+
await selectPopoverPage.ionPopoverDidDismiss.next();
72+
await expect(selectPopoverPage.popover).not.toBeVisible();
73+
});
74+
75+
test('pressing Enter on a selected option should dismiss the popover', async ({ browserName }) => {
76+
test.skip(browserName === 'firefox', 'Same behavior as ROU-5437');
77+
78+
await selectPopoverPage.setup(config, checkedOptions, false);
79+
80+
await selectPopoverPage.pressEnterOnOption('apple');
81+
await selectPopoverPage.ionPopoverDidDismiss.next();
82+
await expect(selectPopoverPage.popover).not.toBeVisible();
83+
});
6684
});
6785
});
6886
});

core/src/components/select-popover/test/fixtures.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class SelectPopoverPage {
6363
await option.press('Space');
6464
}
6565

66+
async pressEnterOnOption(value: string) {
67+
const option = this.getOption(value);
68+
await option.press('Enter');
69+
}
70+
6671
private getOption(value: string) {
6772
const { multiple, selectPopover } = this;
6873
const selector = multiple ? 'ion-checkbox' : 'ion-radio';

0 commit comments

Comments
 (0)