Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tooltip): accessibility improvements for tooltip #1463

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/tooltip/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const Tooltip = ({
modifiers={[offsetModifier, flipModifier, hideModifier]}
>
<div
className={className}
id="tooltipContenDhis2Ui"
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
Expand Down
28 changes: 21 additions & 7 deletions components/tooltip/src/tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,20 @@ describe('Keyboard interaction', () => {

expect(document.querySelector(tooltipContentSelector)).toBe(null)

// wait for 'open delay' to elapse to open tooltip
act(() => {
jest.advanceTimersByTime(200)
})

// expect tooltip to be open after delay
const res = document.querySelector(tooltipContentSelector)
expect(res).not.toBe(null)
expect(res.textContent).toBe(tooltipContent)

wrapper.simulate('blur')
act(() => {
jest.advanceTimersByTime(200) // Assuming default closeDelay is 200ms
jest.advanceTimersByTime(200)
})
expect(document.querySelector(tooltipContentSelector)).toBe(null)
// this last part clears a warning about "code should be wrapped in `act(...)`"
// and clears the tooltip

act(() => {
jest.runAllTimers()
})
Expand All @@ -187,10 +184,27 @@ describe('Keyboard interaction', () => {

// open tooltip
wrapper.simulate('mouseover')

act(() => {
jest.advanceTimersByTime(200) // open the tooltip
jest.advanceTimersByTime(200)
})
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))

// verify tooltip is open
expect(document.querySelector(tooltipContentSelector)).not.toBe(null)

//Press the Escape key
act(() => {
document.dispatchEvent(
alaa-yahia marked this conversation as resolved.
Show resolved Hide resolved
new KeyboardEvent('keydown', { key: 'Escape' })
)
})

// wait for close delay
act(() => {
jest.advanceTimersByTime(200)
})

// expect tooltip to be closed
expect(document.querySelector(tooltipContentSelector)).toBe(null)
})
})
Loading