Skip to content

Commit

Permalink
[Divider] Add aria role if it's not implicit (#16256)
Browse files Browse the repository at this point in the history
* [Divider] Add aria role if it's not implicit

* Better name for role override test
  • Loading branch information
eps1lon authored Jun 17, 2019
1 parent 33ae697 commit 545612c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/material-ui/src/Divider/Divider.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ const Divider = React.forwardRef(function Divider(props, ref) {
className,
component: Component = 'hr',
light = false,
role = Component !== 'hr' ? 'separator' : undefined,
variant = 'fullWidth',
...other
} = props;

if (Component === 'li' && !other.role) {
other.role = 'separator';
}

return (
<Component
className={clsx(
Expand All @@ -62,6 +59,7 @@ const Divider = React.forwardRef(function Divider(props, ref) {
},
className,
)}
role={role}
ref={ref}
{...other}
/>
Expand Down Expand Up @@ -91,6 +89,10 @@ Divider.propTypes = {
* If `true`, the divider will have a lighter color.
*/
light: PropTypes.bool,
/**
* @ignore
*/
role: PropTypes.string,
/**
* The variant to use.
*/
Expand Down
18 changes: 18 additions & 0 deletions packages/material-ui/src/Divider/Divider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ describe('<Divider />', () => {
});
});
});

describe('role', () => {
it('avoids adding implicit aria semantics', () => {
const wrapper = mount(<Divider />);
assert.strictEqual(wrapper.find('hr').props().role, undefined);
});

it('adds a proper role if none is specified', () => {
const wrapper = mount(<Divider component="div" />);
assert.strictEqual(wrapper.find('div').props().role, 'separator');
});

it('overrides the computed role with the provided one', () => {
// presentation is the only valid aria role
const wrapper = mount(<Divider role="presentation" />);
assert.strictEqual(wrapper.find('hr').props().role, 'presentation');
});
});
});

0 comments on commit 545612c

Please sign in to comment.