-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Use Change/Input events for checkable inputs #10830
Conversation
@jquense Happy to do browser testing here. Is there anything special we should check for that might be missing from the DOM test fixtures? |
I think we should have everything covered fixture wise. I just need need to confirm it works on ie9 feel free to test as well if you want :) |
I've published the DOM fixtures with this change here: |
ReactTestUtils.SimulateNative.click(input); | ||
ReactTestUtils.SimulateNative.click(input); | ||
ReactTestUtils.SimulateNative.change(input); | ||
ReactTestUtils.SimulateNative.change(input); | ||
expect(called).toBe(1); | ||
}); |
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.
Does this drop support for clicking inputs to change them? Is this possibly breaking?
I've verified this using our (maybe official?) support matrix: Pass
Fail
These failures are also issues on master. Clicking a radio button fires change: Testing Notes: We need to add the Desktop Safari does not allow arrow keys for range inputs. Pretty lame for a11y, and confusing in the test case, but I'm not sure how to enable it. I don't think this is an issue on us. I'll followup with a PR that adds a note about Safari in this test. |
Thanks Nathan! I wonder if the failures are browser bugs with labels and inputs double firing? We don't dedupe input changes in some safari versions as well because it's not supported |
Following up:
I've pushed that up to: However: now there's in an issue in Safari <= 9 and Chrome <= 43 where the range input fires both a change event and input event. This is only viewable with the updates on master which fix the Arrow key presses fire a change event and input event in all versions of Safari and Chrome (that I've tested), but something in these old browsers is causing both events to produce a synthetic change event; duplicately firing on arrow key presses. I'm curious if some sort of legacy change event behavior for IE is also getting picked up by these old browsers, and if we can avoid that pathway to prevent the duplication. Could we get away with only subscribing to the |
@nhunzaker thanks for all the deets here. Is there a sense of whether anything in this PR regressed something or are we seeing some weird behavior that has always existed but we are just seeing? |
@jquense This started in React 15.6.0 (works in React 15.5.4), so it's not directly related to this PR. I'd be okay with syncing up later to figure out why this is happening, and how much we care about it. |
5fcaf86
to
607945d
Compare
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.
Rebased with master, and I've redeployed the fixtures:
http://react-radio-click-rebased.surge.sh/input-change-events
I'm concerned about this as a breaking change. Apps using SimulateNative.click
will need to switch over to SimulateNative.change
. How common is that?
Still, I am attracted to the idea of reducing the complexity of this code.
How does everyone else feel?
ReactTestUtils.SimulateNative.click(input); | ||
ReactTestUtils.SimulateNative.click(input); | ||
ReactTestUtils.SimulateNative.change(input); | ||
ReactTestUtils.SimulateNative.change(input); | ||
expect(called).toBe(1); | ||
}); |
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.
Am I correct to assume this is breaking change? Is this a change we are comfortable sending out in a minor release?
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.
that's a good question, technically i'd be relying on a private implementation detail, but i can see it breaking tests for folks as well. I defer to what the team thing on this
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 am comfortable with this, but it should go out in a minor. I'd hate for tests to fail on a patch.
Could you rebase this please? I'd be okay with doing it in a minor since
|
import SVGDOMPropertyConfig from './SVGDOMPropertyConfig'; | ||
|
||
DOMProperty.injection.injectDOMPropertyConfig(HTMLDOMPropertyConfig); | ||
DOMProperty.injection.injectDOMPropertyConfig(SVGDOMPropertyConfig); |
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.
Should this be added?
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 don't think so, seems like a rebase issue
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.
Looks good overall, just curious about that newly added injection file.
@nhunzaker long time coming but i've updated this :P |
ReactDOM: size: -0.0%, gzip: -0.0% Details of bundled changes.Comparing: 1609cf3...f0664d5 react-dom
Generated by 🚫 dangerJS |
@jquense doing a build and some testing, but this looks good from a surface level. I'll report back! |
This looks good! Tested in:
It's worth noting that older versions of Chrome and Safari exhibit a behavior where the changes double fire on range inputs when you use arrow keys: However this is already the case on master. This is good to go by me! |
Does this help us fix any bugs or is this purely to simplify? |
I read this as a simplification with a net benefit towards correctness. With this PR, React no longer needs to listen, at the cost of correctness, to click events in IE8. It's a small course-correction that falls more in line with the expected event behavior (or my interpretation of it anyway). Beyond that I'm not sure of any particular bug fixes this addresses. |
My guess is it'll "fix" #12643 as well but I'm still looking into why that behavior even happens. Beyond that tho it closes a leaky bit of the abstraction, that confuses folks occasionally |
This will also fix #9023. We currently have no way of knowing if @jquense You can cherry pick this commit to add a test. It's based on a rebased version of your PR. One thing I found out while rebasing is that some tests no longer pass after my cleanup in #13176. I think this is due to jsdom not firing the |
Can you bring this up to date please? |
updated! |
How likely is it to break anything? Would this only affect unit tests that dispatch events? |
The only breaking behavior i can think is of, is you are triggering native change events on checkbox and not expecting them to flow through components. But that would be really weird to do... IDK, it really shouldn't break anyone, this is an implementation detail, but any time we change the logic here, someone complains it doesn't work in an old version of selenium running on a toaster or something. We've made more aggressive changes in this space on minor bumps before and it's been ok :P |
What if you're triggering clicks and do expect them to flow through? |
Generally native clicks also trigger change events on inputs, so it shouldn't be a problem: http://jsfiddle.net/j3g16ydw/2/ |
Looks like CI fails? |
I think this is one of those things we'll need to put behind a flag. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
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! |
This is pulled from #10238 and only changes the checkable inputs, switching them to use change/input events vs click which was (AFAICT) a IE8 only thing. No real bytes saved but it plugs an otherwise leaky bit of the abstraction