-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[lexical-react] Feature: Add aria-errormessage and aria-invalid support to LexicalContentEditable #6745
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, I think this is fine as we discussed but these should be backward compatible, by adding these properties anyone's who's passing them aria-errormessage
or invalid now would get those as undefined
Good catch! Do you want me to fix the other attrs while I'm in there? Or just stick to |
IMO let's just do these new ones for now. Ideally, we'd get rid of these properties altogether and use the DOM provided ones. We can look into bundling this into a minor patch |
Description
Adds the ability to set
aria-errormessage
andaria-invalid
attributes on the Lexical contenteditable div. This allows us to signal that the text input is in an invalid state and to associate it with another element containing an error message.Impl
Runtime
LexicalContentEditableElement.tsx
already spreads all props that are passed to it, so passingaria-errormessage
oraria-invalid
already works at runtime, but it also explicitly supports camelCase version of aria attributes (e.g.ariaDescribedBy
) so we need to add support forariaErrorMessage
andariaInvalid
.Types
The TS type already implicitly included all HTML attrs via
React.AllHTMLAttributes<HTMLDivElement>
, but Flow doesn't have a nice type like that, so we allowlist certain attrs. So we update the Flow type to includearia-errormessage
andaria-invalid
.I also noticed that we missed
aria-describedby
, so I added that as well.And I also noticed that we misspelled
aria-labelledby
, but fixing that might technically be a breaking change since it could cause a Flow error. So I skipped that for now, but it will not work correctly until we fix the spelling issue, so that's something to consider for the future.Test plan
Added ariaErrorMessage and ariaInvalid attrs to the LexicalContentEditable in the Lexical Playground and confirmed that the props flowed through to the DOM.