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
35 changes: 35 additions & 0 deletions core/src/components/popover/test/basic/popover.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,38 @@ describe('popover: focus trap', () => {
expect(popover.classList.contains(FOCUS_TRAP_DISABLE_CLASS)).toBe(false);
});
});

describe('popover: keyboardClose', () => {
const presentWithFocusedInput = async (keyboardClose: boolean) => {
const page = await newSpecPage({
components: [Popover],
template: () => (
<div>
<input />
<ion-popover keyboardClose={keyboardClose} overlayIndex={1}></ion-popover>
</div>
),
});

const input = page.body.querySelector('input')!;
const popover = page.body.querySelector('ion-popover')!;
const blur = jest.spyOn(input, 'blur');
Object.defineProperty(page.doc, 'activeElement', { configurable: true, get: () => input });

await popover.present();

return blur;
};

it('should not blur the focused element when keyboardClose is false', async () => {
const blur = await presentWithFocusedInput(false);

expect(blur).not.toHaveBeenCalled();
});

it('should blur the focused element when keyboardClose is true', async () => {
const blur = await presentWithFocusedInput(true);

expect(blur).toHaveBeenCalled();
});
});
9 changes: 7 additions & 2 deletions core/src/utils/overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,13 @@ const restoreElementFocus = async (overlayEl: any) => {
return;
}

// Ensure active element is blurred to prevent a11y warning issues
previousElement.blur();
/**
* Ensure active element is blurred to prevent a11y warning issues.
* Skip this when keyboardClose is false so the keyboard stays open.
*/
if (overlayEl.keyboardClose !== false) {
previousElement.blur();
}

const shadowRoot = previousElement?.shadowRoot;
if (shadowRoot) {
Expand Down
Loading