Skip to content
Open
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
13 changes: 13 additions & 0 deletions core/src/components/radio-group/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ export class RadioGroup implements ComponentInterface {
// to the bottom of the screen
ev.preventDefault();
}

// Inside a select interface, Enter commits the focused radio
// value (matching native <select>). The !ev.repeat guard stops
// a held Enter on the triggering ion-select from re-committing
// once focus lands in the opened popover/modal.
if (ev.key === 'Enter' && inSelectInterface && !ev.repeat) {
const previousValue = this.value;
this.value = current.value;
if (previousValue !== this.value) {
this.emitValueChange(ev);
}
ev.preventDefault();
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions core/src/components/radio-group/test/basic/radio-group.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
await radioFixture.expectChecked(false);
});

test('Enter outside a select interface should not change the value', async ({ page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30561',
});

await page.setContent(
`
<ion-radio-group value="one">
<ion-item>
<ion-radio id="one" value="one">One</ion-radio>
</ion-item>
<ion-item>
<ion-radio id="two" value="two">Two</ion-radio>
</ion-item>
</ion-radio-group>
`,
config
);

await radioFixture.checkRadio('keyboard', 'ion-radio#two', 'Enter');

const group = page.locator('ion-radio-group');
await expect(group).toHaveJSProperty('value', 'one');
});

test('click should not deselect without allowEmptySelection', async ({ page }) => {
await page.setContent(
`
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/radio-group/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class RadioFixture {
this.page = page;
}

async checkRadio(method: 'keyboard' | 'mouse', selector = 'ion-radio') {
async checkRadio(method: 'keyboard' | 'mouse', selector = 'ion-radio', key: 'Space' | 'Enter' = 'Space') {
const { page } = this;
const radio = (this.radio = page.locator(selector));

if (method === 'keyboard') {
await radio.focus();
await page.keyboard.press('Space');
await page.keyboard.press(key);
} else {
await radio.click();
}
Expand Down
22 changes: 17 additions & 5 deletions core/src/components/select-modal/select-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import type { SelectModalOption } from './select-modal-interface';
export class SelectModal implements ComponentInterface {
@Element() el!: HTMLIonSelectModalElement;

// Tracks the option that received Enter-keydown so keyup only
// dismisses when the press started on the same option. Prevents
// Enter on the triggering ion-select from auto-dismissing.
private pendingEnterTarget: HTMLElement | null = null;

@Prop() header?: string;

/**
Expand Down Expand Up @@ -99,14 +104,21 @@ export class SelectModal implements ComponentInterface {
justify="start"
labelPlacement="end"
onClick={() => this.closeModal()}
onKeyDown={(ev) => {
if (ev.key === 'Enter' && !ev.repeat) {
this.pendingEnterTarget = ev.currentTarget as HTMLElement;
}
}}
onKeyUp={(ev) => {
if (ev.key === ' ') {
/**
* Selecting a radio option with keyboard navigation,
* either through the Enter or Space keys, should
* dismiss the modal.
*/
// Space selects and dismisses in one press.
this.closeModal();
} else if (ev.key === 'Enter') {
const shouldClose = this.pendingEnterTarget === ev.currentTarget;
this.pendingEnterTarget = null;
if (shouldClose) {
this.closeModal();
}
}
}}
>
Expand Down
29 changes: 29 additions & 0 deletions core/src/components/select-modal/test/basic/select-modal.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
await expect(selectModalPage.modal).not.toBeVisible();
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
test('pressing Enter on an unselected option should dismiss the modal', async ({ page: _page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30561',
});

await selectModalPage.setup(config, options, false);

await selectModalPage.pressEnterOnOption('apple');
await selectModalPage.ionModalDidDismiss.next();
await expect(selectModalPage.modal).not.toBeVisible();
});

test('pressing Enter on a selected option should dismiss the modal', async ({ browserName }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30561',
});

test.skip(browserName === 'firefox', 'Same behavior as ROU-5437');

await selectModalPage.setup(config, checkedOptions, false);

await selectModalPage.pressEnterOnOption('apple');
await selectModalPage.ionModalDidDismiss.next();
await expect(selectModalPage.modal).not.toBeVisible();
});

test('clicking the close button should dismiss the modal', async () => {
await selectModalPage.setup(config, options, false);

Expand Down
5 changes: 5 additions & 0 deletions core/src/components/select-modal/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export class SelectModalPage {
await option.press('Space');
}

async pressEnterOnOption(value: string) {
const option = this.getOption(value);
await option.press('Enter');
}

private getOption(value: string) {
const { multiple, selectModal } = this;
const selector = multiple ? 'ion-checkbox' : 'ion-radio';
Expand Down
23 changes: 18 additions & 5 deletions core/src/components/select-popover/select-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import type { SelectPopoverOption } from './select-popover-interface';
})
export class SelectPopover implements ComponentInterface {
@Element() el!: HTMLIonSelectPopoverElement;

// Tracks the option that received Enter-keydown so keyup only
// dismisses when the press started on the same option. Prevents
// Enter on the triggering ion-select from auto-dismissing.
private pendingEnterTarget: HTMLElement | null = null;

/**
* The header text of the popover
*/
Expand Down Expand Up @@ -159,14 +165,21 @@ export class SelectPopover implements ComponentInterface {
value={option.value}
disabled={option.disabled}
onClick={() => this.dismissParentPopover()}
onKeyDown={(ev) => {
if (ev.key === 'Enter' && !ev.repeat) {
this.pendingEnterTarget = ev.currentTarget as HTMLElement;
}
}}
onKeyUp={(ev) => {
if (ev.key === ' ') {
/**
* Selecting a radio option with keyboard navigation,
* either through the Enter or Space keys, should
* dismiss the popover.
*/
// Space selects and dismisses in one press.
this.dismissParentPopover();
} else if (ev.key === 'Enter') {
const shouldDismiss = this.pendingEnterTarget === ev.currentTarget;
this.pendingEnterTarget = null;
if (shouldDismiss) {
this.dismissParentPopover();
}
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
await selectPopoverPage.ionPopoverDidDismiss.next();
await expect(selectPopoverPage.popover).not.toBeVisible();
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
test('pressing Enter on an unselected option should dismiss the popover', async ({ page: _page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30561',
});

await selectPopoverPage.setup(config, options, false);

await selectPopoverPage.pressEnterOnOption('apple');
await selectPopoverPage.ionPopoverDidDismiss.next();
await expect(selectPopoverPage.popover).not.toBeVisible();
});

test('pressing Enter on a selected option should dismiss the popover', async ({ browserName }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/30561',
});

test.skip(browserName === 'firefox', 'Same behavior as ROU-5437');

await selectPopoverPage.setup(config, checkedOptions, false);

await selectPopoverPage.pressEnterOnOption('apple');
await selectPopoverPage.ionPopoverDidDismiss.next();
await expect(selectPopoverPage.popover).not.toBeVisible();
});
});
});
});
Expand Down
5 changes: 5 additions & 0 deletions core/src/components/select-popover/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export class SelectPopoverPage {
await option.press('Space');
}

async pressEnterOnOption(value: string) {
const option = this.getOption(value);
await option.press('Enter');
}

private getOption(value: string) {
const { multiple, selectPopover } = this;
const selector = multiple ? 'ion-checkbox' : 'ion-radio';
Expand Down
Loading
Loading