-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Drawer): added focustrap functionality (#9469)
* feat(Drawer): added focustrap functionality * Added tests * Updated failing integration test * Updated example description and integration tests
- Loading branch information
1 parent
dd6e6a4
commit 41fedc5
Showing
6 changed files
with
409 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/react-core/src/components/Drawer/__tests__/DrawerPanelContent.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { DrawerPanelContent } from '../DrawerPanelContent'; | ||
import { Drawer } from '../Drawer'; | ||
|
||
test('Does not render with aria-labelledby by default', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content')).not.toHaveAccessibleName(); | ||
}); | ||
|
||
test('Renders with aria-labelledby when focusTrap.enabled is true', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent focusTrap={{ enabled: true }}>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content')).toHaveAccessibleName('Drawer panel content'); | ||
}); | ||
|
||
test('Renders with aria-labelledby when id is passed in', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent id="drawer-panel-content" focusTrap={{ enabled: true }}> | ||
Drawer panel content | ||
</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content')).toHaveAccessibleName('Drawer panel content'); | ||
}); | ||
|
||
test('Renders with custom aria-labelledby', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent focusTrap={{ enabled: true, 'aria-labelledby': 'drawer-panel-title' }}> | ||
<span id="drawer-panel-title">Title</span> | ||
<span>Drawer panel content</span> | ||
</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content').parentElement).toHaveAccessibleName('Title'); | ||
}); | ||
|
||
test('Does not render with aria-modal="true" by default', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content')).not.toHaveAttribute('aria-modal'); | ||
}); | ||
|
||
test('Renders with aria-modal="true" when focusTrap.enabled is true', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent focusTrap={{ enabled: true }}>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByText('Drawer panel content')).toHaveAttribute('aria-modal', 'true'); | ||
}); | ||
|
||
test('Does not render with role="dialog" by default', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('Renders with role="dialog" when focusTrap.enabled is true', () => { | ||
render( | ||
<Drawer isExpanded> | ||
<DrawerPanelContent focusTrap={{ enabled: true }}>Drawer panel content</DrawerPanelContent> | ||
</Drawer> | ||
); | ||
|
||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
}); |
Oops, something went wrong.