Skip to content

Commit

Permalink
fix(overlays): add tabindex="-1" to prevent tooltips get focus in Saf…
Browse files Browse the repository at this point in the history
…ari and Firefox
  • Loading branch information
gerjanvangeest authored and tlouisse committed Jan 21, 2025
1 parent 5344fde commit 2155e45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-humans-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

[overlays] add tabindex="-1" to prevent tooltips get focus in Safari and Firefox
4 changes: 4 additions & 0 deletions packages/ui/components/overlays/src/OverlayController.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,10 @@ export class OverlayController extends EventTarget {
});
// @ts-ignore
wrappingDialogElement.open = true;
if (this.isTooltip) {
// needed to prevent tooltip getting focus in Safari and Firefox
wrappingDialogElement.setAttribute('tabindex', '-1');
}

this.__wrappingDialogNode.style.display = 'none';
this.contentWrapperNode.style.zIndex = '1';
Expand Down
13 changes: 13 additions & 0 deletions packages/ui/components/overlays/test/OverlayController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,19 @@ describe('OverlayController', () => {
expect(ctrl.contentNode.getAttribute('role')).to.equal('tooltip');
});

it('adds tabindex="-1" to the wrappingDialog element', async () => {
const invokerNode = /** @type {HTMLElement} */ (
await fixture('<div role="button">invoker</div>')
);
const ctrl = new OverlayController({
...withLocalTestConfig(),
handlesAccessibility: true,
isTooltip: true,
invokerNode,
});
expect(ctrl.__wrappingDialogNode?.getAttribute('tabindex')).to.equal('-1');
});

describe('Teardown', () => {
it('restores [role] on dialog content', async () => {
const invokerNode = /** @type {HTMLElement} */ (
Expand Down

0 comments on commit 2155e45

Please sign in to comment.