-
Notifications
You must be signed in to change notification settings - Fork 47.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
fix: checkbox with preventDefault
on click should not trigger SyntheticEvent
#22735
Conversation
Comparing: e0aa5e2...461333c Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
preventDefault
on click should not trigger SyntheticEventpreventDefault
on click should not trigger SyntheticEvent
preventDefault
on click should not trigger SyntheticEventpreventDefault
on click should not trigger SyntheticEvent
hi @rickhanlonii, Thanks~ |
Anyone can take a look? Half month passed ... |
This doesn't seem to work in a Chrome Version 96.0.4664.45 (Official Build) (64-bit) when we call |
Here is a test that still fails in this PR which is based on https://codesandbox.io/s/react-18-checkbox-click-preventdefault-change-quirk-4mwl8?file=/src/index.js. Notice that it('should not fire change for checkbox input when preventDefault is called in onClick', () => {
const handleReactChange = jest.fn();
const handleNativeChange = jest.fn();
const node = ReactDOM.render(
<input
type="checkbox"
defaultChecked
onClick={event => {
event.preventDefault();
}}
onChange={handleReactChange}
/>,
container,
);
node.addEventListener('change', handleNativeChange);
node.click();
expect(handleNativeChange).toHaveBeenCalledTimes(0);
expect(handleReactChange).toHaveBeenCalledTimes(0);
}); |
@eps1lon, |
preventDefault
on click should not trigger SyntheticEventpreventDefault
on click should not trigger SyntheticEvent
Hmmm... |
preventDefault
on click should not trigger SyntheticEventpreventDefault
on click should not trigger SyntheticEvent
Fixed in Chrome 96 👍🏻 For safe measure, could you check various other browsers as well (e.g. Safari and IE 11 are notorous for inconsistent behavior). |
Update: Since CodeSandbox do not support IE11, I need additional work for test it. |
@eps1lon,
|
@eps1lon, wait your feed back : ) |
@eps1lon , anything more I can do? : ) |
@sebmarkbage could you pls help to take a look? |
Anyone can help on this? |
@eps1lon, could you help to take a look?~ Thanks |
@bvaughn, could you help to merge this? thx |
LGTM |
Hi @bvaughn, is any chance that this PR will be merged or something else that I can help?~ |
Hi @bvaughn, is there any chance to merge this PR? |
@sebmarkbage, could you help to take a look? |
@Huxpro Could you help to find someone can handle this? thx |
@gnoff plz take a look on this |
hi @kassens, |
@eps1lon, safe to merge? : ) |
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
Summary
React use SyntheticEvent to trigger change event on checkbox & radio by click event. But when called
preventDefault
on click event, it does not trigger native change event but will trigger on React. It's caused by thechecked
state will tmp set to opposite but reset when finished by browser:https://html.spec.whatwg.org/multipage/input.html#the-input-element
Add check to ignore change event when prevent is marked
resolve #9023
How did you test this change?
Update
ChangeEventPlugin-test.js
for preventDefault case. (Since this is prevent wrong event trigger, seems can do nothing for video record)related issue: