Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: default aria-hidden on NavCategoryItem's expandIcon slot",
"packageName": "@fluentui/react-headless-components-preview",
"email": "array.knight@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,34 @@ describe('Nav', () => {
expect(link.tagName).toBe('A');
expect(link).toHaveAttribute('href', 'https://example.com');
});

it('hides NavCategoryItem expandIcon from assistive technology by default', () => {
const result = render(
<Nav>
<NavCategory value="cat1">
<NavCategoryItem expandIcon={{ children: <img alt="expand" src="chevron.png" /> }}>
Category 1
</NavCategoryItem>
</NavCategory>
</Nav>,
);

expect(result.getByRole('button', { name: 'Category 1' })).toBeInTheDocument();
expect(result.getByAltText('expand').parentElement).toHaveAttribute('aria-hidden', 'true');
});

it('allows a consumer to override NavCategoryItem expandIcon aria-hidden', () => {
const result = render(
<Nav>
<NavCategory value="cat1">
<NavCategoryItem expandIcon={{ 'aria-hidden': false, children: <img alt="expand" src="chevron.png" /> }}>
Category 1
</NavCategoryItem>
</NavCategory>
</Nav>,
);

expect(result.getByRole('button', { name: 'Category 1 expand' })).toBeInTheDocument();
expect(result.getByAltText('expand').parentElement).toHaveAttribute('aria-hidden', 'false');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const useNavCategoryItem = (
elementType: 'span',
}),
expandIcon: slot.optional(expandIcon, {
defaultProps: { 'aria-hidden': true },
elementType: 'span',
}),
components: {
Expand Down