focus-visible
focus-visible copied to clipboard
Optionally scope focus-ring to a specific DOM node
For projects that are just standalone libraries/components, it might be beneficial to be able to scope the focus-ring JS to just a specific DOM node rather than the entire body. This would allow these components to use focus-ring without inadvertently modifying other parts of the parent application.
If the team thinks that this is worth doing, I'd be happy to submit a PR.
I'd be interested in discussing how you'd like to implement this
I would imagine it would be similar to jQuery's noConflict method. Existing behavior would stay the same: focus-ring automatically binds listeners to document and adds the class to any applicable element. However, when some API method is called (e.g., FocusRing.scope(node)) then any document-level behavior is removed and replaced with event listeners bound to the corresponding node (+ checking that any element that is about to receive the focus-ring class be a descendent of node before actually getting the class).