-
Notifications
You must be signed in to change notification settings - Fork 252
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: allow reassignment of focus
and blur
methods on `HTMLElement…
#1265
fix: allow reassignment of focus
and blur
methods on `HTMLElement…
#1265
Conversation
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. |
I ran into the same issue when trying to upgrade |
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.
Thanks for contributing to this library.
Replacing the accessor descriptor with a data descriptor removes the extra logic.
IMHO this also makes the test redundant.
Supporting the reassignment would also require us to expose proper setup and teardown, as the linked teardown function in Chakra-UI would break our implementation if their setup function runs before our setup.
But this is out of scope here – I will tackle this in a separate PR.
Thanks for the comments, @ph-fritsche. I made the requested changes and removed the test. |
@ph-fritsche can this fix get released soon? |
#1270 should fix that but I didn't have time to check yet |
What
Reinstates the ability to reassign
HTMLElement.prototype.focus
andHTMLElement.prototype.blur
that was removed in #1252.Why
Some UI libraries (Chakra UI, for example) override the
focus
and/orblur
methods on theHTMLElement
prototype. #1252 introduced a patchedfocus
implementation that only included a getter, which means these libraries error when run with@testing-library/user-event
because there is no setter.How
This adds a setter to the patched
focus
andblur
methods.Checklist
I'm not super confident that this is the correct or preferred way to resolve the issue, but it works for my use cases.
This line from
@zag-js/radio-group
(a dependency of@chakra-ui/react
) was the operative code in my case: https://github.com/chakra-ui/zag/blob/c1ffbfe1eb09028c837b305942f34bb77b9ac4fc/packages/utilities/focus-visible/src/index.ts#L143