How to render Label and Text components outside React Aria Components? #7726
endaquigley
started this conversation in
General
Replies: 2 comments 5 replies
-
You can use
Can you say more about why description and error need to be outside as well? |
Beta Was this translation helpful? Give feedback.
4 replies
-
Just wondering, have you guys ever discussed exposing a compound component to get around issues like this: <RadioGroup {...otherProps} asCompoundComponent>
<Label>{label}</Label>
<Text slot="description">{description}</Text>
<RadioGroup.Component />
</RadioGroup> which would render: <div>
<div id=":r1:" class="react-aria-Label">Favorite avatar</div>
<div id=":r2:" class="react-aria-Text">Please select an avatar</div>
<div role="radiogroup" class="react-aria-RadioGroup" aria-labelledby=":r1:" aria-describedby=":r2:">
<label class="react-aria-Radio">
<input type="radio" aria-describedby=":r2:" value="wizard" />
Wizard
</label>
<label class="react-aria-Radio">
<input type="radio" aria-describedby=":r2:" value="dragon" />
Dragon
</label>
</div>
</div> Not sure how big of a change that would be... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a project at the moment using React Aria Components and I need to render a
Label
and multipleText
components (e.g. "description" and "errorMessage") outside of the React Aria context. The reason I need to render theLabel
outside theRadioGroup
is because we display an info icon button beside ourLabel
, which isn't a valid RadioGroup child.However, I’m not sure about the best approach to integrate these components outside their usual context while still maintaining accessibility features. I tried using
useRadioGroupState
anduseRadioGroup
but the props keep getting reset:The only way I've got this to work is by adding a
LabelContext
,TextContext
,RadioGroupContext
andRadioContext
, manually creating IDs and hooking up the components myself:Doesn't feel right though... I feel like I'm missing a basic concept 🙃
Any help would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions