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 1 commit
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
38 changes: 38 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,44 @@ 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, getByTestId } = render(
<Select
MenuProps={{
fyodor-e marked this conversation as resolved.
Show resolved Hide resolved
transitionDuration: 0,
BackdropProps: { 'data-testid': 'select-backdrop' },
}}
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');

// Click by the left mouse button. Options list should be present
eps1lon marked this conversation as resolved.
Show resolved Hide resolved
fireEvent.mouseDown(trigger);
expect(queryByRole('listbox')).to.be.ok;

// Now close the options list.
getByTestId('select-backdrop').click();
clock.tick(0);

// 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
23 changes: 0 additions & 23 deletions packages/material-ui/test/integration/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,6 @@ describe('<Select> integration', () => {
expect(trigger).to.have.focus;
expect(trigger).to.have.text('Twenty');
});

it('open only with 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, getByTestId } = render(<SelectAndDialog />);

const trigger = getByRole('button');

// Click by the left mouse button. Options list should be present
fireEvent.mouseDown(trigger);
expect(queryByRole('listbox')).to.not.be.null;

// Now close the options list.
getByTestId('select-backdrop').click();
clock.tick(0);

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

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

describe('with label', () => {
Expand Down