Skip to content

Commit

Permalink
fix(select-rich): only close the overlay on tab when trapsKeyboardFoc…
Browse files Browse the repository at this point in the history
…us is false (#2273)
  • Loading branch information
gerjanvangeest authored Apr 29, 2024
1 parent 2b68845 commit 36f0bbc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-laws-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

[select-rich] only close the overlay on tab when trapsKeyboardFocus is false
3 changes: 3 additions & 0 deletions packages/ui/components/select-rich/src/LionSelectRich.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ export class LionSelectRich extends SlotMixin(ScopedElementsMixin(OverlayMixin(L
switch (key) {
case 'Tab':
// Tab can only be caught in keydown
if (this._overlayCtrl.config.trapsKeyboardFocus === true) {
return;
}
this.opened = false;
break;
case 'Escape':
Expand Down
12 changes: 12 additions & 0 deletions packages/ui/components/select-rich/test/lion-select-rich.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ describe('lion-select-rich', () => {
_listboxNode.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab' }));
expect(el.opened).to.be.false;
});

it('does not close the listbox with [Tab] key once opened when trapsKeyboardFocus is true', async () => {
const el = await fixture(
html`
<lion-select-rich opened .config=${{ trapsKeyboardFocus: true }}> </lion-select-rich>
`,
);
// tab can only be caught via keydown
const { _listboxNode } = getSelectRichMembers(el);
_listboxNode.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab' }));
expect(el.opened).to.be.true;
});
});

describe('Mouse navigation', () => {
Expand Down

0 comments on commit 36f0bbc

Please sign in to comment.