Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,4 +971,20 @@ describe('<Select />', () => {
expect(keyUpSpy.callCount).to.equal(1);
expect(keyUpSpy.returnValues[0]).to.equal(true);
});

it('should pass onClick prop to MenuItem', () => {
const onClick = spy();
const { getAllByRole } = render(
<Select open value="30">
<MenuItem onClick={onClick} value={30}>
Thirty
</MenuItem>
</Select>,
);

const options = getAllByRole('option');
fireEvent.click(options[0]);

expect(onClick.callCount).to.equal(1);
});
});
10 changes: 7 additions & 3 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
newValue = child.props.value;
}

if (child.props.onClick) {
child.props.onClick(event);
}

if (value === newValue) {
return;
}
Expand Down Expand Up @@ -252,9 +256,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
// the select to close immediately since we open on space keydown
event.preventDefault();
}
const { onKeyUp } = child.props;
if (typeof onKeyUp === 'function') {
onKeyUp(event);

if (child.props.onKeyUp) {
child.props.onKeyUp(event);
}
},
role: 'option',
Expand Down