Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Select] Right click opens select menu #19434

Merged
merged 7 commits into from
Jan 30, 2020
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
24 changes: 24 additions & 0 deletions packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,30 @@ describe('<Select />', () => {

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

it('open only with the left mouse button click', () => {
// Test for https://github.com/mui-org/material-ui/issues/19250#issuecomment-578620934
// Right/middle mouse click shouldn't open the Select
const { getByRole, queryByRole } = render(
<Select value="">
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>,
);

const trigger = getByRole('button');

// If clicked by the right/middle mouse button, no options list should be opened
fireEvent.mouseDown(trigger, { button: 1 });
expect(queryByRole('listbox')).to.not.exist;

fireEvent.mouseDown(trigger, { button: 2 });
expect(queryByRole('listbox')).to.not.exist;
});
});

describe('prop: autoWidth', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/material-ui/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
};

const handleMouseDown = event => {
if (event.button !== 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised the CI passes without the bracket. Should we care or ignore it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no lint complain, no problem

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To expand a bit: The point of a common formatting and linting ruleset is to not care about nitpicks in human code reviews. These discussions always slow down development. They can happen but on a per-ruleset basis not for each and every individual case.

Should we care about single-line brackets: Probably (main argument being diff noise here). But then we should change the rules globally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon I couldn't agree more with you

Copy link
Member

@oliviertassinari oliviertassinari Jan 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this rule in mind: https://github.com/airbnb/javascript#blocks--braces. If we agree to enforce it globally (I thought we were), I will add it to a backlog of small changes. It's not really important, I think that it could be handled later, like a Friday later afternoon, to rest.

// ignore everything but left-click
return;
// Hijack the default focus behavior.
event.preventDefault();
displayNode.focus();
Expand Down