Skip to content

Commit 076070c

Browse files
fix(Nav): added role presentation to NavItemSeparator (#11730)
* fix(Nav): added role presentation to NavItemSeparator * Updated role prop type to generic string * Reverted role prop type to union
1 parent 5485f4b commit 076070c

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

packages/react-core/src/components/Divider/Divider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ export interface DividerProps extends React.HTMLProps<HTMLElement> {
3131
xl?: 'vertical' | 'horizontal';
3232
'2xl'?: 'vertical' | 'horizontal';
3333
};
34+
/** The ARIA role of the divider when the component property has a value other than "hr". */
35+
role?: 'separator' | 'presentation';
3436
}
3537

3638
export const Divider: React.FunctionComponent<DividerProps> = ({
3739
className,
3840
component = DividerVariant.hr,
3941
inset,
4042
orientation,
43+
role = 'separator',
4144
...props
4245
}: DividerProps) => {
4346
const Component: any = component;
@@ -50,7 +53,7 @@ export const Divider: React.FunctionComponent<DividerProps> = ({
5053
formatBreakpointMods(orientation, styles),
5154
className
5255
)}
53-
{...(component !== 'hr' && { role: 'separator' })}
56+
{...(component !== 'hr' && { role })}
5457
{...props}
5558
/>
5659
);

packages/react-core/src/components/Divider/__tests__/Divider.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ test(`Test all insets`, () => {
9191
});
9292
});
9393

94+
test('Does not render with value passed to role by default', () => {
95+
render(<Divider role="presentation" />);
96+
expect(screen.queryByRole('presentation')).not.toBeInTheDocument();
97+
});
98+
99+
test('Renders with value passed to role when component is not "hr"', () => {
100+
render(<Divider component="li" role="presentation" />);
101+
expect(screen.getByRole('presentation')).toBeInTheDocument();
102+
});
103+
94104
test('Matches the snapshot', () => {
95105
const { asFragment } = render(<Divider />);
96106
expect(asFragment()).toMatchSnapshot();

packages/react-core/src/components/Nav/NavItemSeparator.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Divider, DividerProps } from '../Divider';
22

33
export const NavItemSeparator: React.FunctionComponent<DividerProps> = ({
44
component = 'li',
5+
role = 'presentation',
56
...props
6-
}: DividerProps) => <Divider component={component} {...props} />;
7+
}: DividerProps) => <Divider component={component} role={role} {...props} />;
78
NavItemSeparator.displayName = 'NavItemSeparator';

packages/react-core/src/components/Toolbar/ToolbarItem.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,19 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
185185
children,
186186
isAllExpanded,
187187
isOverflowContainer,
188+
role,
188189
...props
189190
}: ToolbarItemProps) => {
190191
if (variant === ToolbarItemVariant.separator) {
191-
return <Divider className={css(className)} orientation={{ default: 'vertical' }} {...props} />;
192+
const isDividerRoleValid = role === 'separator' || role === 'presentation';
193+
return (
194+
<Divider
195+
className={css(className)}
196+
orientation={{ default: 'vertical' }}
197+
{...props}
198+
{...(isDividerRoleValid && { role: role as 'separator' | 'presentation' })}
199+
/>
200+
);
192201
}
193202

194203
return (
@@ -217,6 +226,7 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
217226
)}
218227
{...(variant === 'label' && { 'aria-hidden': true })}
219228
id={id}
229+
role={role}
220230
{...props}
221231
>
222232
{children}

0 commit comments

Comments
 (0)