-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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] Dispatch click event with same target of the mousedown event #25630
Changes from all commits
e6ceb6b
e7a5fbb
36b249b
2426215
fa77bf5
902118f
3f84217
d3b4a0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,7 @@ describe('<Select />', () => { | |
const trigger = getByRole('button'); | ||
|
||
fireEvent.mouseDown(trigger); | ||
fireEvent.click(trigger); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one indicator that this change is problematic. What happens if there is no click registered on the trigger due to interactions with other elements? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no problem if the click occurs in other element, here it could even be in the |
||
|
||
expect(handleBlur.callCount).to.equal(0); | ||
expect(getByRole('listbox')).not.to.equal(null); | ||
|
@@ -246,7 +247,9 @@ describe('<Select />', () => { | |
<MenuItem value="2" /> | ||
</Select>, | ||
); | ||
fireEvent.mouseDown(getByRole('button')); | ||
const button = getByRole('button'); | ||
fireEvent.mouseDown(button); | ||
fireEvent.click(button); | ||
getAllByRole('option')[1].click(); | ||
|
||
expect(onChangeHandler.calledOnce).to.equal(true); | ||
|
@@ -265,7 +268,9 @@ describe('<Select />', () => { | |
</Select>, | ||
); | ||
|
||
fireEvent.mouseDown(getByRole('button')); | ||
const button = getByRole('button'); | ||
fireEvent.mouseDown(button); | ||
fireEvent.click(button); | ||
getAllByRole('option')[1].click(); | ||
|
||
expect(eventLog).to.deep.equal(['CHANGE_EVENT', 'CLOSE_EVENT']); | ||
|
@@ -724,7 +729,9 @@ describe('<Select />', () => { | |
} | ||
const { getByRole, queryByRole } = render(<ControlledWrapper />); | ||
|
||
fireEvent.mouseDown(getByRole('button')); | ||
const button = getByRole('button'); | ||
fireEvent.mouseDown(button); | ||
fireEvent.click(button); | ||
expect(getByRole('listbox')).not.to.equal(null); | ||
|
||
act(() => { | ||
|
@@ -921,7 +928,9 @@ describe('<Select />', () => { | |
}); | ||
const { getByRole, getAllByRole } = render(<ControlledSelectInput onChange={onChange} />); | ||
|
||
fireEvent.mouseDown(getByRole('button')); | ||
const button = getByRole('button'); | ||
fireEvent.mouseDown(button); | ||
fireEvent.click(button); | ||
const options = getAllByRole('option'); | ||
fireEvent.click(options[2]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as React from 'react'; | ||
import Select from '@material-ui/core/Select'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import ClickAwayListener from '@material-ui/core/ClickAwayListener'; | ||
|
||
export default function WithSelect() { | ||
const [counter, setCounter] = React.useState(0); | ||
|
||
return ( | ||
<React.Fragment> | ||
<div id="onClickAway">{counter}</div> | ||
<ClickAwayListener onClickAway={() => setCounter(counter + 1)}> | ||
<Select value=""> | ||
<MenuItem value={10}>One</MenuItem> | ||
<MenuItem value={20}>Two</MenuItem> | ||
<MenuItem value={30}>Three</MenuItem> | ||
</Select> | ||
</ClickAwayListener> | ||
</React.Fragment> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this click to every
fireEvent.mouseDown
so that the previous added event listener is removed.