react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

Expose FocusableProvider in `react-aria`

Open filipw01 opened this issue 3 years ago โ€ข 4 comments

๐Ÿ™‹ Feature Request

Expose FocusableProvider from react-aria

๐Ÿค” Expected Behavior

Have the ability to inject custom dom attributes into focusable elements

๐Ÿ˜ฏ Current Behavior

public useFocusable uses context to inject dom attributes, but the provider is not exposed to the public

๐Ÿ’ Possible Solution

Export FocusableProvider the same way useFocusable is

๐Ÿ”ฆ Context

I'm working on a Tooltip component and I noticed spectrum uses FocusableProvider to implement a nice API where props are automatically injected. I want to do the same. Right now I'm using @react-aria/focus to do that, but I think that should be part of react-aria package itself

๐Ÿ’ป Examples

Example usage in react-spectrum

๐Ÿงข Your Company/Team

Chili Piper

filipw01 avatar Jan 19 '23 15:01 filipw01

We are fine exposing this provider, we'll need docs + additional guardrails to prevent abuse of it so people don't use it to pass any arbitrary attribute to an element.

LFDanLu avatar Jan 25 '23 21:01 LFDanLu

What guardrails do you have in mind? I can work on it if you elaborate and point me in the right direction with docs

filipw01 avatar Jan 26 '23 08:01 filipw01

The guardrails would be something along these lines I imagine:

  • FocusableProvider currently accepts all DOMAttributes and passes it down the context. This feels a bit too wide especially since the component consuming the context may only accept a certain attributes. Perhaps something docs should cover?
  • useFocusable could use some checks to make sure a element is actually focusable/interactive

LFDanLu avatar Jan 31 '23 21:01 LFDanLu

Hi, I'd like to pick this up if it is still available. I read the previous attempts in #10637 and #10692, including the clarification that the existing provider validation means an additional check in useFocusableContext is unnecessary. I'd keep the change focused on the public export, documentation of the supported attributes and intended usage, and relevant behaviour coverage. Are either of the previous contributors planning to resume, or would a fresh PR be welcome?

Orcus01 avatar Nov 05 '26 17:11 Orcus01