-
Notifications
You must be signed in to change notification settings - Fork 37
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
Fix "An input component must either have a 'aria-label' attribute..." error when a <label> is present #1230
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 871a9a3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for sg-orbit ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for sg-storybook ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -335,6 +331,14 @@ export function InnerNumberInput(props: InnerNumberInputProps) { | |||
value: inputValueRef.current | |||
}); | |||
|
|||
useEffect(() => { |
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.
I believe this is textbook what React is now recommending NOT to do with useEffect
: https://react.dev/reference/react/useEffect#caveats
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.
Which part specifically are you concerned about?
Logging something in the console is the textbook definition of a side-effect in functional programming.
To check for the presence of a label, we need to access the ref
to obtrain the HTMLInputElement. Using a useEffect or a callbackRef are the main ways to do it.
I am not sure I understand the use case correctly. Does the following code would print a warning?
When there's a
From what I can see by the following test, the issue might be that the Input and the Label are not wrapped within a |
✅ I confirm that using I'll add it to the test scenarios. I didn't know the To me, it still feel like a bug because using a label with <>
<Label htmlFor="test">Label</Label>
<TextInput id="test" />
</> I understand that labels are this is not as easily verifyable as using I think it's a valid trade-off. We can also argue against this change if we prefer people to use the |
Thank for the reply @tjosepo. Yes, the intent is to always use the |
Alright! I'll update my PR and go for it. |
Issue: #1229
Summary
Removes the warning "An input component must either have a 'aria-label' attribute..." when a
<label>
is present.What I did
I moved the validation logic inside a
useEffect
and add a check forisNilOrEmpty(input.labels)
.I had to modify
isNilOrEmpty
to support arrays (and NodeList). Instead of checkingvalue === ""
, it checksvalue.length === 0
(this works for strings, arrays and NodeLists).How to test
Unit tests were added.