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

[lexical-react] Feature: Add aria-errormessage and aria-invalid support to LexicalContentEditable #6745

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

ejhammond
Copy link
Contributor

@ejhammond ejhammond commented Oct 18, 2024

Description

Adds the ability to set aria-errormessage and aria-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 passing aria-errormessage or aria-invalid already works at runtime, but it also explicitly supports camelCase version of aria attributes (e.g. ariaDescribedBy) so we need to add support for ariaErrorMessage and ariaInvalid.

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 include aria-errormessage and aria-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.

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 8:27pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 8:27pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 18, 2024
Copy link

github-actions bot commented Oct 18, 2024

size-limit report 📦

Path Size
lexical - cjs 29.94 KB (0%)
lexical - esm 29.78 KB (0%)
@lexical/rich-text - cjs 38.51 KB (0%)
@lexical/rich-text - esm 31.58 KB (0%)
@lexical/plain-text - cjs 37.16 KB (0%)
@lexical/plain-text - esm 29 KB (0%)
@lexical/react - cjs 40.29 KB (0%)
@lexical/react - esm 33 KB (0%)

Copy link
Member

@zurfyx zurfyx left a 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

@ejhammond
Copy link
Contributor Author

Good catch! Do you want me to fix the other attrs while I'm in there? Or just stick to aria-errormessage/aria-invalid so that we're strictly backwards compatible? (Fixing the other attrs would technically not be backwards compatible since the kebab-case versions are all getting voided out today)

@zurfyx
Copy link
Member

zurfyx commented Oct 18, 2024

Good catch! Do you want me to fix the other attrs while I'm in there? Or just stick to aria-errormessage/aria-invalid so that we're strictly backwards compatible? (Fixing the other attrs would technically not be backwards compatible since the kebab-case versions are all getting voided out today)

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

@zurfyx zurfyx added this pull request to the merge queue Oct 20, 2024
Merged via the queue into facebook:main with commit b2d57a0 Oct 20, 2024
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants