Skip to content

Commit 9cdf860

Browse files
nehaaprasadheloiseluisangeethababu9223tay1orjonesmaradwan26
authored
fix(switcher): wrap SwitcherDivider hr in li for a11y compliance (#20632)
* fix(switcher): wrap SwitcherDivider hr in li for a11y compliance * fix: remove duplicate SwitcherDivider in Header w/Actions and Switcher story * fix: override default hr styles in SwitcherDivider and restore both dividers in story * update * fix(switcher): apply className to hr element for a11y compliance * Apply suggestion from @maradwan26 Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com> * test(SwitcherDivider): update hr to inside li --------- Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com> Co-authored-by: Sangeetha Babu <sangeetha9223@gmail.com> Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com> Co-authored-by: Mahmoud <132728978+maradwan26@users.noreply.github.com> Co-authored-by: Taylor Jones <taylor.jones826@gmail.com>
1 parent ff3e1f5 commit 9cdf860

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

packages/react/src/components/UIShell/SwitcherDivider.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { usePrefix } from '../../internal/usePrefix';
1212

1313
export interface SwitcherDividerProps {
1414
/**
15-
* Optionally provide a custom class to apply to the underlying `<li>` node
15+
* Optionally provide a custom class to apply to the underlying `<hr>` node
1616
*/
1717
className?: string;
1818
}
@@ -26,12 +26,16 @@ const SwitcherDivider = ({
2626
[customClassName || '']: !!customClassName,
2727
});
2828

29-
return <hr {...other} className={classNames} />;
29+
return (
30+
<li>
31+
<hr {...other} className={classNames} />
32+
</li>
33+
);
3034
};
3135

3236
SwitcherDivider.propTypes = {
3337
/**
34-
* Optionally provide a custom class to apply to the underlying `<li>` node
38+
* Optionally provide a custom class to apply to the underlying `<hr>` node
3539
*/
3640
className: PropTypes.string,
3741
};

packages/react/src/components/UIShell/__tests__/SwitcherDivider-test.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ import { render } from '@testing-library/react';
1111

1212
describe('SwitcherDivider', () => {
1313
describe('renders as expected - Component API', () => {
14-
it('should spread extra props onto outermost element', () => {
14+
it('should spread extra props onto the separator element', () => {
1515
const { container } = render(<SwitcherDivider data-testid="test-id" />);
1616

17-
expect(container.firstChild).toHaveAttribute('data-testid', 'test-id');
17+
// SwitcherDivider renders as `li > hr`, so assert against the separator.
18+
expect(container.firstChild.firstChild).toHaveAttribute(
19+
'data-testid',
20+
'test-id'
21+
);
1822
});
1923

20-
it('should support a custom `className` prop on the outermost element', () => {
24+
it('should support a custom `className` prop on the separator element', () => {
2125
const { container } = render(
2226
<SwitcherDivider className="custom-class" />
2327
);
2428

25-
expect(container.firstChild).toHaveClass('custom-class');
29+
// SwitcherDivider renders as `li > hr`, so assert against the separator.
30+
expect(container.firstChild.firstChild).toHaveClass('custom-class');
2631
});
2732
});
2833
});

0 commit comments

Comments
 (0)