Skip to content

Commit 5dec2f3

Browse files
committed
fix(landing): blur legacy inert focus
1 parent b0d7484 commit 5dec2f3

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

apps/sim/app/(landing)/demo/components/legacy-inert-fallback.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ describe('applyLegacyInertFallback', () => {
3333
expect(button?.getAttribute('tabindex')).toBeNull()
3434
expect(link?.getAttribute('tabindex')).toBe('2')
3535
})
36+
37+
it('moves focus out of a panel before hiding it', () => {
38+
const panel = document.createElement('div')
39+
const button = document.createElement('button')
40+
panel.append(button)
41+
document.body.append(panel)
42+
button.focus()
43+
44+
expect(document.activeElement).toBe(button)
45+
46+
const restore = applyLegacyInertFallback(panel)
47+
48+
expect(document.activeElement).not.toBe(button)
49+
50+
restore()
51+
panel.remove()
52+
})
3653
})

apps/sim/app/(landing)/demo/components/legacy-inert-fallback.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function applyLegacyInertFallback(node: HTMLElement): () => void {
2121
const previousAriaHidden = node.getAttribute('aria-hidden')
2222
const previousPointerEvents = node.style.pointerEvents
2323
const previousTabIndexes = new Map<HTMLElement, string | null>()
24+
const activeElement = node.ownerDocument.activeElement
25+
26+
if (activeElement instanceof HTMLElement && node.contains(activeElement)) activeElement.blur()
2427

2528
node.setAttribute('aria-hidden', 'true')
2629
node.style.pointerEvents = 'none'

0 commit comments

Comments
 (0)