Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJDev committed Dec 20, 2023
1 parent b750fa3 commit 755f319
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/__tests__/focus-zone.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,36 @@ it('Shoud move to tabbable elements if onlyTabbable', async () => {

controller.abort()
})

it('Should ignore hidden elements after focus zone is enabled', async () => {
const user = userEvent.setup()
const {container, rerender} = render(
<div id="focusZone">
<button tabIndex={0}>Apple</button>
<button tabIndex={0}>Banana</button>
<button tabIndex={0}>Cantaloupe</button>
</div>,
)

const focusZoneContainer = container.querySelector<HTMLElement>('#focusZone')!
const [firstButton, , thirdButton] = focusZoneContainer.querySelectorAll('button')
const controller = focusZone(focusZoneContainer)

firstButton.focus()
expect(document.activeElement).toEqual(firstButton)

rerender(
<div id="focusZone">
<button tabIndex={0}>Apple</button>
<button tabIndex={0} hidden>
Banana
</button>
<button tabIndex={0}>Cantaloupe</button>
</div>,
)

await user.keyboard('{arrowdown}')
expect(document.activeElement).toEqual(thirdButton)

controller.abort()
})

0 comments on commit 755f319

Please sign in to comment.