Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion packages/react-core/src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ export interface DividerProps extends React.HTMLProps<HTMLElement> {
xl?: 'vertical' | 'horizontal';
'2xl'?: 'vertical' | 'horizontal';
};
/** The ARIA role of the divider when the component property has a value other than "hr". */
role?: string;
}

export const Divider: React.FunctionComponent<DividerProps> = ({
className,
component = DividerVariant.hr,
inset,
orientation,
role = 'separator',
...props
}: DividerProps) => {
const Component: any = component;
Expand All @@ -50,7 +53,7 @@ export const Divider: React.FunctionComponent<DividerProps> = ({
formatBreakpointMods(orientation, styles),
className
)}
{...(component !== 'hr' && { role: 'separator' })}
{...(component !== 'hr' && { role })}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ test(`Test all insets`, () => {
});
});

test('Does not render with value passed to role by default', () => {
render(<Divider role="presentation" />);
expect(screen.queryByRole('presentation')).not.toBeInTheDocument();
});

test('Renders with value passed to role when component is not "hr"', () => {
render(<Divider component="li" role="presentation" />);
expect(screen.getByRole('presentation')).toBeInTheDocument();
});

test('Matches the snapshot', () => {
const { asFragment } = render(<Divider />);
expect(asFragment()).toMatchSnapshot();
Expand Down
3 changes: 2 additions & 1 deletion packages/react-core/src/components/Nav/NavItemSeparator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Divider, DividerProps } from '../Divider';

export const NavItemSeparator: React.FunctionComponent<DividerProps> = ({
component = 'li',
role = 'presentation',
...props
}: DividerProps) => <Divider component={component} {...props} />;
}: DividerProps) => <Divider component={component} role={role} {...props} />;
NavItemSeparator.displayName = 'NavItemSeparator';
2 changes: 2 additions & 0 deletions packages/react-core/src/components/Toolbar/ToolbarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({
...props
}: ToolbarItemProps) => {
if (variant === ToolbarItemVariant.separator) {
// TODO: consider removing spread props here so we can update Divider role prop to union of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an issue for this? Otherwise should we remove this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated some logic to have the union type on the new prop so removed this comment

// separator or presentation rather than generic string
return <Divider className={css(className)} orientation={{ default: 'vertical' }} {...props} />;
}

Expand Down
Loading