Skip to content

Commit

Permalink
update test to prevent regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 19, 2020
1 parent 65e8123 commit 4e175e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/material-ui/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ const ButtonBase = React.forwardRef(function ButtonBase(props, ref) {
});
}

if (event.target === event.currentTarget && isNonNativeButton() && event.key === ' ') {
event.preventDefault();
}

if (onKeyDown) {
onKeyDown(event);
}

if (event.target === event.currentTarget && isNonNativeButton() && event.key === ' ') {
event.preventDefault();
}
// Keyboard accessibility for non interactive elements
if (event.target === event.currentTarget && isNonNativeButton() && event.key === 'Enter') {
event.preventDefault();
Expand Down
5 changes: 4 additions & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,10 @@ describe('<ButtonBase />', () => {

describe('keyboard accessibility for non interactive elements', () => {
it('does not call onClick when a spacebar is pressed on the element', () => {
const onKeyDown = spy(event => event.defaultPrevented);
const onClickSpy = spy(event => event.defaultPrevented);
const { getByRole } = render(
<ButtonBase onClick={onClickSpy} component="div">
<ButtonBase onClick={onClickSpy} onKeyDown={onKeyDown} component="div">
Hello
</ButtonBase>,
);
Expand All @@ -694,6 +695,8 @@ describe('<ButtonBase />', () => {
});

expect(onClickSpy.callCount).to.equal(0);
// defaultPrevented?
expect(onKeyDown.returnValues[0]).to.equal(true);
});

it('does call onClick when a spacebar is released on the element', () => {
Expand Down

0 comments on commit 4e175e6

Please sign in to comment.