adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.21k stars 1.07k forks source link

`HiddenContext` not exported, can't build my own Popover within a Select field #6453

Closed thexpand closed 4 days ago

thexpand commented 1 month ago

Provide your feedback here.

I want to build a select field using the Select component. However, I have my own popover component that I want to use instead of the one from React Aria, but can't because I can't use HiddenContext, as it's not exported but it's required by Select for everything to work properly.

🔦 Context

I want to build a similar logic like this in my own Popover component: https://github.com/adobe/react-spectrum/blob/2bda4c971dd557be7ecc44614569a8281e6cb6dd/packages/react-aria-components/src/Popover.tsx#L87-L100

Can we just have this context exported, so that we can use it in our own (user land) components if needed?

💻 Code Sample

No response

Version

react-aria-components@1.2.1

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify

No response

What operating system are you using?

macOS

snowystinger commented 1 month ago

I don't see any reason not to do this.

thexpand commented 1 month ago

@snowystinger I created a PR (#6459) for this. This is my first one for react-spectrum, so let me know if something looks awry.

ArrayKnight commented 2 weeks ago

I'd like to request that Hidden and createHideableComponent also be exported as part of this effort, for the simplicity of implementation and completeness of feature suite

snowystinger commented 2 weeks ago

createHideableComponent should be added soon https://github.com/adobe/react-spectrum/pull/6640 We still looking into ways to handle the Hidden component https://github.com/adobe/react-spectrum/pull/6459#issuecomment-2146376427

devongovett commented 2 weeks ago

It should be noted that createHideableComponent is only an optimization and is not required for a functional implementation.

This will also be marked unstable in the upcoming release so it could change at any time.

devongovett commented 4 days ago

closing due to #6640

ArrayKnight commented 1 day ago

@devongovett It looks like the HiddenContext was not exported in the new @react-aria/collections or through react-aria-components. This means that the HiddenContext can't be reused as a provider

I'd like to reopen this issue until HiddenContext is fully exported

ArrayKnight commented 1 day ago

Also, it feels a little weird that the whole hidden suite got rolled into collections considering it's used by components like Button that have no connection with collection at all

devongovett commented 1 day ago

What are you trying to do with this? The provider is built into createHidableComponent, and you can consume it via useIsHidden. The only use case we have for this is in collections, but again it's just an optimization, not necessary for correctness.

ArrayKnight commented 1 day ago

If I want to build a component that implements the HiddenContext.Provider and controls whether a descendant is hidden or not. As you have it now, it's only possible to consume the HiddenContext which is implemented by RAC/Collections. I'd like to be able to create my own components that control that state.

It'd also be helpful to have your Hidden component exported

I swear that you had a RAC with <Provider values={[[HiddenContext, ...]]}> implemented somewhere, but now I can't find it. Maybe it got refactored?

devongovett commented 1 day ago

Yeah that all got moved into the new CollectionBuilder component that we're using everywhere now so you don't need to worry about setting the hidden context or configuring SSR manually anymore. See here for example (will update the docs eventually). https://github.com/adobe/react-spectrum/blob/4fc70174ac35a5ebf06379f5cafaf943519a1eac/packages/react-aria-components/src/Select.tsx#L87-L91

ArrayKnight commented 14 hours ago

But if I'm building something that isn't a collection and I want to use HiddenContext or Hidden?

devongovett commented 10 hours ago

Like what? It wasn't really intended as a general purpose thing, it's just an implementation detail. Can't you use your own context if you are doing something other than a collection?