diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js index 190ecdb05c5a09..f7de4db23f96f5 100644 --- a/packages/material-ui/src/Chip/Chip.js +++ b/packages/material-ui/src/Chip/Chip.js @@ -301,7 +301,6 @@ const Chip = React.forwardRef(function Chip(props, ref) { label, onClick, onDelete, - onKeyDown, onKeyUp, size = 'medium', variant = 'default', @@ -319,22 +318,6 @@ const Chip = React.forwardRef(function Chip(props, ref) { } }; - const handleKeyDown = event => { - if (onKeyDown) { - onKeyDown(event); - } - - // Ignore events from children of `Chip`. - // TODO: Remove in v5. It doesn't handle library code - if (event.currentTarget !== event.target) { - return; - } - - if ([' ', 'Enter', 'Backspace', 'Delete', 'Escape'].indexOf(event.key) !== -1) { - event.preventDefault(); - } - }; - const handleKeyUp = event => { if (onKeyUp) { onKeyUp(event); @@ -438,7 +421,6 @@ const Chip = React.forwardRef(function Chip(props, ref) { aria-disabled={disabled ? true : undefined} tabIndex={clickable ? 0 : undefined} onClick={onClick} - onKeyDown={handleKeyDown} onKeyUp={handleKeyUp} ref={handleRef} {...moreProps} diff --git a/packages/material-ui/src/Chip/Chip.test.js b/packages/material-ui/src/Chip/Chip.test.js index a62bacaf135463..853610d7cd1296 100644 --- a/packages/material-ui/src/Chip/Chip.test.js +++ b/packages/material-ui/src/Chip/Chip.test.js @@ -383,6 +383,36 @@ describe('', () => { }); }); + it(`should not call onClick for child keyup event when 'Space' is released`, () => { + const handleClick = spy(); + const handleKeyUp = spy(); + render( + } + />, + ); + + fireEvent.keyUp(document.activeElement, { key: ' ' }); + expect(handleKeyUp.callCount).to.equal(1); + expect(handleClick.callCount).to.equal(0); + }); + + it(`should not call onClick for child keydown event when 'Enter' is pressed`, () => { + const handleClick = spy(); + const handleKeyDown = spy(); + render( + } + />, + ); + + fireEvent.keyDown(document.activeElement, { key: 'Enter' }); + expect(handleKeyDown.callCount).to.equal(1); + expect(handleClick.callCount).to.equal(0); + }); + it('should not call onClick for child event when `space` is released', () => { const handleClick = spy(); const handleKeyUp = spy();