You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know this is a bit of a XY Problem but I want to make a component that doesn't force me to wrap evrything in a Provider that provides ALL Field context, because I know I'm going to forget to add some context at some point and go down a debugging rabbithole 😂
What I really want is something like this discussion is describing:
I have a case where I want to create a composable API for form fields in a component library.
Mainly I want to be able to have one or more fields share one description and error message.
Ignore the naming of stuff here, it's WIP 😅
.
The API I'm trying to achieve:
<FormControlhint="This is a hint"validationErrors={["This is an error"]}><TextFieldlabel="Postal Code"/><Selectlabel="Country"options={[{label: "USA",value: "usa"},{label: "Canada",value: "canada"},{label: "Mexico",value: "mexico"},]}/></FormControl>
Current State
I've basically got it working by making the following component, with a util function enhanceChildren that adds aria-describedBy, aria-errormessage and aria-invalid to the field-component children of the FormControl.
Only problem I'm having atm to match the regular implementation of the Field-pattern is that the RACValidationErrors won't render. The component looks like this:
exportfunctionRACValidationError(props: ValidationErrorProps){return(<FieldError>// <-- React-aria-components FieldError<ValidationError{...props}/>// <--- Essentially just styling but extracted for use outside of React Aria.</FieldError>);}
The FieldError here ☝️ returns null because the FormFieldContexts validation object has isInvalid equal to false.
I'm assuming this is because It's not child of a XYZFieldProvider.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Before you read
I know this is a bit of a XY Problem but I want to make a component that doesn't force me to wrap evrything in a
Providerthat provides ALLFieldcontext, because I know I'm going to forget to add some context at some point and go down a debugging rabbithole 😂What I really want is something like this discussion is describing:
But I see that it has not been discussed any further, so I tried to make it work without it.
The Problem
I have a case where I want to create a composable API for form fields in a component library.
Mainly I want to be able to have one or more fields share one description and error message.
Ignore the naming of stuff here, it's WIP 😅
.
The API I'm trying to achieve:
Current State
I've basically got it working by making the following component, with a util function
enhanceChildrenthat addsaria-describedBy,aria-errormessageandaria-invalidto the field-component children of theFormControl.Only problem I'm having atm to match the regular implementation of the Field-pattern is that the
RACValidationErrorswon't render. The component looks like this:The
FieldErrorhere ☝️ returnsnullbecause theFormFieldContextsvalidationobject hasisInvalidequal tofalse.I'm assuming this is because It's not child of a XYZFieldProvider.
Anyone got any tips?
Beta Was this translation helpful? Give feedback.
All reactions