user-event icon indicating copy to clipboard operation
user-event copied to clipboard

Remove label-click-implies-input-click as this behavior is handled by DOM libs

Open Lanny opened this issue 10 months ago • 2 comments

There's this common UA behavior where clicking on a label which controls an input behaves the same way as a click on the input. As far as I can tell this isn't part of any standard, but it's pretty much universal among browsers in practice. There is some code here in user-event to simulate this behavior, however jsdom and happy-dom both implement this.

In the case of happy-dom this causes a bug producing double-clicks on elements when their controlling label is clicked: https://github.com/capricorn86/happy-dom/issues/1410 . This doesn't affect jsdom because the way it handles preventDefault is different, but that's purely an implementation detail that we shouldn't be relying on here.

This MR removes the logic to attempt to click controlled inputs when their controlling labels are clicked and leaves it to the DOM lib. In so doing, to prevent interfering with the dom lib's handling of this behavior, this PR also removes the logic to half-way preventing default when user-event has some additional behavior to apply on top of dispatching an event (e.g. in the case of click or clipboard events). It seems to have only really been needed for the label-click scenario. If we find this is necessary, we can let the individual behavior handlers make their own determination about preventing default or not.

Checklist:

  • [ ] Documentation
  • [x] Tests
  • [x] Ready to be merged

Lanny avatar Apr 17 '24 21:04 Lanny

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Apr 17 '24 21:04 codesandbox-ci[bot]

@nickmccurdy if you could take a look at this when you get a chance, I'd appreciate it!

Lanny avatar May 03 '24 16:05 Lanny