From ed823fffef6fc2f55c6b625579e09fdbc53e3273 Mon Sep 17 00:00:00 2001 From: fyodore82 Date: Tue, 28 Jan 2020 12:06:34 +1000 Subject: [PATCH 1/7] [Select] Right click opens select menu --- .../material-ui/src/Select/SelectInput.js | 4 ++++ .../test/integration/Select.test.js | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js index b809d3cbdc6c88..2e2c689af511e7 100644 --- a/packages/material-ui/src/Select/SelectInput.js +++ b/packages/material-ui/src/Select/SelectInput.js @@ -105,6 +105,9 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { }; const handleMouseDown = event => { + if (event.button !== 0) + // ignore everything but left-click + return; // Hijack the default focus behavior. event.preventDefault(); displayNode.focus(); @@ -318,6 +321,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { aria-haspopup="listbox" onKeyDown={handleKeyDown} onMouseDown={disabled || readOnly ? null : handleMouseDown} + onClick={disabled || readOnly ? null : handleMouseDown} onBlur={handleBlur} onFocus={onFocus} {...SelectDisplayProps} diff --git a/packages/material-ui/test/integration/Select.test.js b/packages/material-ui/test/integration/Select.test.js index b8d4e52b8b5f3c..0644dcb5c60017 100644 --- a/packages/material-ui/test/integration/Select.test.js +++ b/packages/material-ui/test/integration/Select.test.js @@ -91,6 +91,29 @@ describe(' integration', () => { }); 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 select + // 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(); const trigger = getByRole('button'); @@ -103,7 +103,7 @@ describe('', () => { 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( + , + ); + + const trigger = getByRole('button'); + + // Click by the left mouse button. Options list should be present + 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', () => { diff --git a/packages/material-ui/test/integration/Select.test.js b/packages/material-ui/test/integration/Select.test.js index 77b2792de24bd4..b8d4e52b8b5f3c 100644 --- a/packages/material-ui/test/integration/Select.test.js +++ b/packages/material-ui/test/integration/Select.test.js @@ -91,29 +91,6 @@ describe('', () => { const trigger = getByRole('button'); - // Click by the left mouse button. Options list should be present - 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; From f07d13bc8762ac78c513080a1f44bf32279af80e Mon Sep 17 00:00:00 2001 From: fyodore82 Date: Wed, 29 Jan 2020 19:12:18 +1000 Subject: [PATCH 6/7] [Select] Cleanup unused staff --- packages/material-ui/src/Select/Select.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/material-ui/src/Select/Select.test.js b/packages/material-ui/src/Select/Select.test.js index a4663727a9bd38..6cf5577a186a38 100644 --- a/packages/material-ui/src/Select/Select.test.js +++ b/packages/material-ui/src/Select/Select.test.js @@ -675,14 +675,8 @@ describe(' + const { getByRole, queryByRole } = render( + ', () => { 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 + // Right/middle mouse click shouldn't open the Select const { getByRole, queryByRole } = render(