Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 11, 2019
1 parent 46e495e commit c138097
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
18 changes: 0 additions & 18 deletions packages/material-ui/src/Chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ const Chip = React.forwardRef(function Chip(props, ref) {
label,
onClick,
onDelete,
onKeyDown,
onKeyUp,
size = 'medium',
variant = 'default',
Expand All @@ -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);
Expand Down Expand Up @@ -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}
Expand Down
30 changes: 30 additions & 0 deletions packages/material-ui/src/Chip/Chip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,36 @@ describe('<Chip />', () => {
});
});

it(`should not call onClick for child keyup event when 'Space' is released`, () => {
const handleClick = spy();
const handleKeyUp = spy();
render(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyUp={handleKeyUp} />}
/>,
);

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(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyDown={handleKeyDown} />}
/>,
);

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();
Expand Down

0 comments on commit c138097

Please sign in to comment.