Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation support for React Aria Components #5313

Merged
merged 5 commits into from
Oct 30, 2023
Merged

Conversation

devongovett
Copy link
Member

Depends on #5288

This adds support for the validation behaviors described in #5288 to React Aria Components. It includes two new components:

  • <FieldError> renders form validation errors. It accepts render props to allow customization of the error messages.
  • <Form> is a small wrapper around an HTML <form> that also supports the validationErrors prop for server errors, which is provided via the FormValidationContext. We could also potentially add more functionality here in the future (e.g. auto focusing the first invalid field).

In addition, in RAC validationBehavior="native" is the default rather than validationBehavior="aria". I think this is a better default, but we cannot change the behavior in RSP for backward compatibility reasons.

@rspbot
Copy link

rspbot commented Oct 27, 2023

Base automatically changed from validation to main October 27, 2023 01:39
@LFDanLu
Copy link
Member

LFDanLu commented Oct 27, 2023

mind rebasing this, looks like it has all the changes from #5288 as well

@rspbot
Copy link

rspbot commented Oct 27, 2023

snowystinger
snowystinger previously approved these changes Oct 27, 2023
validationErrors?: ValidationErrors | null
}

function Form(props: FormProps, ref: ForwardedRef<HTMLFormElement>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description says small wrapper and can add in the future, so I assume suggestions like providing data attributes and renderprops for focusWithin or a FormContext for passing in props would fall into that category of enhancements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good questions. I'm not sure what the use case for focus within on a form would be. I thought our recommendation was to use Group in those cases. I guess we could support FormContext for consistency but not really sure what people would use it for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I realized you could just use a Group, though don't know if it'd be a nice convenience feature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do very explicitly say

All React Aria Components export a corresponding context that can be used to send props to them from a parent element

in our docs, just noticed

@rspbot
Copy link

rspbot commented Oct 30, 2023

LFDanLu
LFDanLu previously approved these changes Oct 30, 2023
@LFDanLu
Copy link
Member

LFDanLu commented Oct 30, 2023

ah, didn't see the 2nd merge, looks like the tests need to be updated to have the new Item changes from the other PR. Will reapprove after that is updated

@rspbot
Copy link

rspbot commented Oct 30, 2023

@rspbot
Copy link

rspbot commented Oct 30, 2023

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@devongovett devongovett merged commit d4e467b into main Oct 30, 2023
@devongovett devongovett deleted the rac-validation branch October 30, 2023 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants