Skip to content

Commit

Permalink
fix two interaction issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 21, 2019
1 parent 06221ce commit 58f66b9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
20 changes: 2 additions & 18 deletions packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,14 @@ describe('<Select />', () => {
// this means the trigger is blurred immediately
const handleBlur = spy();
const { getByRole, getAllByRole, queryByRole } = render(
<Select
onBlur={handleBlur}
onMouseDown={event => {
// simulating certain platforms that focus on mousedown
if (event.defaultPrevented === false) {
event.currentTarget.focus();
}
}}
value=""
>
<Select onBlur={handleBlur} value="">
<MenuItem value="">none</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
</Select>,
);
const trigger = getByRole('button');

// simulating user click
act(() => {
fireEvent.mouseDown(trigger);
trigger.click();
});
fireEvent.mouseDown(trigger);

expect(handleBlur.callCount).to.equal(0);
expect(getByRole('listbox')).to.be.ok;
Expand Down Expand Up @@ -611,7 +598,6 @@ describe('<Select />', () => {
const { getByRole, queryByRole } = render(<ControlledWrapper />);

fireEvent.mouseDown(getByRole('button'));

expect(getByRole('listbox')).to.be.ok;

act(() => {
Expand Down Expand Up @@ -651,7 +637,6 @@ describe('<Select />', () => {
stub(button, 'clientWidth').get(() => 14);

fireEvent.mouseDown(button);

expect(getByTestId('paper').style).to.have.property('minWidth', '14px');
});

Expand All @@ -665,7 +650,6 @@ describe('<Select />', () => {
stub(button, 'clientWidth').get(() => 14);

fireEvent.mouseDown(button);

expect(getByTestId('paper').style).to.have.property('minWidth', '');
});
});
Expand Down
4 changes: 4 additions & 0 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
};

const handleMouseDown = event => {
// Hijack the default focus behavior.
event.preventDefault();
displayNode.focus();

update(true, event);
};

Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui/test/integration/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('<Select> integration', () => {
const trigger = getByRole('button');
// Let's open the select component
// in the browser user click also focuses
trigger.focus();
fireEvent.mouseDown(trigger);

const options = getAllByRole('option');
Expand All @@ -81,7 +80,6 @@ describe('<Select> integration', () => {
expect(trigger).to.have.text('Ten');
// Let's open the select component
// in the browser user click also focuses
trigger.focus();
fireEvent.mouseDown(trigger);

const options = getAllByRole('option');
Expand Down

0 comments on commit 58f66b9

Please sign in to comment.