Skip to content
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
9 changes: 7 additions & 2 deletions core/src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,8 +1175,13 @@ export class Modal implements ComponentInterface, OverlayInterface {
*/
private onModalFocus = (ev: FocusEvent) => {
const { dragHandleEl, el } = this;
// Only handle focus if the modal itself was focused (not a child element)
if (ev.target === el && dragHandleEl && dragHandleEl.tabIndex !== -1) {
/**
* Shadow DOM focus is retargeted to the host, so `ev.target === el` is also
* true when a shadow child (the dialog wrapper present() focuses) is focused.
* shadowRoot's activeElement is null only when the host was focused directly,
* so redirect to the handle only then and leave present()'s wrapper focus intact.
*/
Comment on lines +1178 to +1183

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this comment is different than the one on major-9.0. I assume that this was intentional.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just a little more concise. I'll probably take this when I merge main into major-9.0

if (ev.target === el && el.shadowRoot?.activeElement == null && dragHandleEl && dragHandleEl.tabIndex !== -1) {
dragHandleEl.focus();
}
};
Expand Down
26 changes: 26 additions & 0 deletions core/src/utils/test/overlays/overlays.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,32 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
await expect(wrapper).toBeFocused();
});

test('should focus the sheet modal wrapper on present when handleBehavior is cycle', async ({ page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'FW-7611',
});
// present()'s wrapper focus must survive the cycle-handle focus redirect.
await page.setContent(
`
<ion-modal initial-breakpoint="0.5" breakpoints="[0, 0.5, 1]" handle-behavior="cycle">
<ion-content>Sheet Modal Content</ion-content>
</ion-modal>
`,
config
);

const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent');
const modal = page.locator('ion-modal');
const wrapper = page.locator('ion-modal .modal-wrapper');

await modal.evaluate((el: HTMLIonModalElement) => el.present());
await ionModalDidPresent.next();

await expect(wrapper).toHaveAttribute('role', 'dialog');
await expect(wrapper).toBeFocused();
});

test('should focus the card modal wrapper on present', async ({ page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
Expand Down
Loading