Skip to content

Commit

Permalink
fix: respect disabled interactive elements in focus trap (#3108)
Browse files Browse the repository at this point in the history
Closes #3109
  • Loading branch information
jeripeierSBB authored Sep 23, 2024
1 parent f349463 commit fb0a1bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/elements/core/a11y/focus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ describe('focus', () => {
<button style="visibility: hidden" id="hidden-button">Button</button>
</div>
<slot></slot>
<button id="disabled-button" disabled>Disabled button</button>
<span id="disabled-interactive-button" disabled disabled-interactive tabindex="0">Disabled interactive button</span>
`;
}
},
Expand All @@ -126,13 +128,16 @@ describe('focus', () => {
expect(document.activeElement!.shadowRoot!.activeElement!.id).to.equal('custom-link');

await sendKeys({ press: tabKey });

expect(document.activeElement!.shadowRoot!.activeElement!.id).to.equal('input');

await sendKeys({ press: tabKey });

expect(document.activeElement!.id).to.equal('slotted-button');

await sendKeys({ press: tabKey });
expect(document.activeElement!.shadowRoot!.activeElement!.id).to.equal(
'disabled-interactive-button',
);

// Wrap around
await sendKeys({ press: tabKey });
expect(document.activeElement!.shadowRoot!.activeElement!.id).to.equal('custom-button');
Expand Down
2 changes: 1 addition & 1 deletion src/elements/core/a11y/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const IS_FOCUSABLE_QUERY = [
'summary:not(:disabled)',
'[tabindex]',
]
.map((selector) => `${selector}:not([disabled],[tabindex="-1"])`)
.map((selector) => `${selector}:not([disabled]:not([disabled-interactive]),[tabindex="-1"])`)
.join(',');

// Note: the use of this function for more complex scenarios (with many nested elements) may be expensive.
Expand Down

0 comments on commit fb0a1bb

Please sign in to comment.