fix: allow reassignment of focus and blur methods on `HTMLElement… #1265
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
What
Reinstates the ability to reassign
HTMLElement.prototype.focusandHTMLElement.prototype.blurthat was removed in #1252.Why
Some UI libraries (Chakra UI, for example) override the
focusand/orblurmethods on theHTMLElementprototype. #1252 introduced a patchedfocusimplementation that only included a getter, which means these libraries error when run with@testing-library/user-eventbecause there is no setter.How
This adds a setter to the patched
focusandblurmethods.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