Skip to content

Commit

Permalink
feat: support a11y for menu divider (#661)
Browse files Browse the repository at this point in the history
* feat: support a11y for menu divider

* test: cover a11y support for divider

* Update tests/Menu.spec.tsx

chore: adapt to feedback

Co-authored-by: Amumu <yoyo837@hotmail.com>

* test: update a11y test expect

* test: update snapshot

---------

Co-authored-by: phatIntern <phat.pham@saleshood.com>
Co-authored-by: Amumu <yoyo837@hotmail.com>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent d896516 commit 7d70b6c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Divider({ className, style }: DividerProps) {

return (
<li
role="separator"
className={classNames(`${prefixCls}-item-divider`, className)}
style={style}
/>
Expand Down
16 changes: 16 additions & 0 deletions tests/Menu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 +730,21 @@ describe('Menu', () => {

expect(document.activeElement).toBe(last(container.querySelectorAll('li')));
});

it('should render a divider with role="separator"', () => {
const menuRef = React.createRef<MenuRef>();
const { container } = render(
<Menu ref={menuRef} activeKey="cat">
<MenuItem key="light">Light</MenuItem>
<Divider />
<MenuItem key="cat">Cat</MenuItem>
</Menu>,
);
// Get the divider element with the rc-menu-item-divider class
const divider = container.querySelector('.rc-menu-item-divider');

// Assert that the divider element with rc-menu-item-divider class has role="separator"
expect(divider).toHaveAttribute('role', 'separator');
});
});
/* eslint-enable */
6 changes: 6 additions & 0 deletions tests/__snapshots__/Menu.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down Expand Up @@ -190,6 +191,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down Expand Up @@ -304,6 +306,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down Expand Up @@ -424,6 +427,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down Expand Up @@ -614,6 +618,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down Expand Up @@ -728,6 +733,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
<li
class="rc-menu-item"
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/Options.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ HTMLCollection [
</li>
<li
class="rc-menu-item-divider"
role="separator"
/>
</ul>,
<div
Expand Down

0 comments on commit 7d70b6c

Please sign in to comment.