-
Notifications
You must be signed in to change notification settings - Fork 12
Card: updates labeling and internal testId support #2859
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
Conversation
🦋 Changeset detectedLatest commit: 731cada The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
|
Size Change: +54 B (+0.05%) Total Size: 109 kB
ℹ️ View Unchanged
|
npm Snapshot: Published🎉 Good news!! We've packaged up the latest commit from this PR (6d4735f) and published all packages with changesets to npm. You can install the packages in ./dev/tools/deploy_wonder_blocks.js --tag="PR2859"Packages can also be installed manually by running: pnpm add @khanacademy/wonder-blocks-<package-name>@PR2859 |
A new build was pushed to Chromatic! 🚀https://5e1bf4b385e3fb0020b7073c-qgtrabsocj.chromatic.com/ Chromatic results:
|
|
I think this one is finally ready to go -- it is supporting a PR in the frontend repo through a snapshot release: https://github.com/Khan/frontend/pull/5283 |
| // 1. labels.cardAriaLabel (preferred for translatable strings) | ||
| // 2. aria-labelledby (if provided, don't set aria-label) | ||
| // 3. aria-label (fallback) |
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.
thought: Based on this description, it looks like cardAriaLabel and aria-label have the same function, so one of these would be redundant, as aria-label would technically be translatable as well.
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.
Yes -- and aria-label is likely translated on the way in, anyway. Originally the API for this component was to only use labels.cardAriaLabel and apply that internally to aria-label. But I wanted to make it more flexible based on existing usage where aria-label was passed down through multiple layers of abstraction as a prop.
The "only one label type" and specific tag restrictions made the Card super hard to use in practice, so I loosened those types to make it more reasonable.
Maybe I'll just remove this comment entirely.
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.
For ease of use, I think it would be easier to have only one way consumers can set the aria-label.
Since aria-label and labels.cardAriaLabel are for the same element, could we use only one of them? I prefer the aria-label prop over the labels.cardAriaLabel prop since it is consistent with the other WB components! (I might be misunderstanding the context around needing both, so let me know!)
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 originally had aria-label in the Card Implementation Spec but labels were suggested instead so I went with that... The labels structure also includes dismissButtonAriaLabel, which is convenient.
I decided to allow aria-label in the integration phase in frontend, based on how the Card component was wrapped to create deeper abstractions. We could go with all aria-label, but the dismissButtonAriaLabel will be an odd one out in the labels object or have another one-off prop.
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'm opting to keep labels only and getting rid of aria-label, since there are two properties on the object! (whenever this Git outage is resolved)
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.
Ah right, it's been a while since I took a look at the Card Implementation Spec! I think keeping it on labels works too, so there's only 1 way to add the aria-label! Thanks Marcy!
beaesguerra
left a comment
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.
Thanks for the improvements! Left some comments/questions on things I'd like to get your thoughts on!
| "aria-labelledby"?: string; | ||
| "aria-label"?: string; | ||
| "aria-busy"?: AriaAttributes["aria-busy"]; | ||
| "aria-roledescription"?: AriaAttributes["aria-roledescription"]; |
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.
Should the Card component props extend the AriaProps? This is normally what we do in components so it supports all the aria attributes!
Also, if we want to include support for setting the role, AriaProps includes the type for role, while AriaAttributes doesn't!
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 personally don't think it's a good practice to support all ARIA attributes everywhere because it can allow non-compliant markup. We need a way to restrict some of them to valid use cases, so opting in for common usage through direct props makes sense to me. We can always enable support for something specific if and when it comes up!
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.
That's fair! I think this makes sense to start doing going forwards. cc: @jandrade also in case you have thoughts on this!
Another nice thing about this is when we explicitly add the specific aria props, it'll get included in the prop docs automatically! (props extended from the AriaProps weren't automatically included the props docs)
| labels, | ||
| tag, | ||
| testId, | ||
| testId = "card", |
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.
Could we leave testId uninitialized and only set the test id if it is provided? That way there aren't unnecessary data attributes in the DOM, and teams will have to explicitly pass in a test id if they want to use it! This is the behaviour I've observed in other components!
We can also only set the close button test id if the main testId prop is provided! What do you think?
| // 1. labels.cardAriaLabel (preferred for translatable strings) | ||
| // 2. aria-labelledby (if provided, don't set aria-label) | ||
| // 3. aria-label (fallback) |
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.
For ease of use, I think it would be easier to have only one way consumers can set the aria-label.
Since aria-label and labels.cardAriaLabel are for the same element, could we use only one of them? I prefer the aria-label prop over the labels.cardAriaLabel prop since it is consistent with the other WB components! (I might be misunderstanding the context around needing both, so let me know!)
387b0b5 to
e63bfae
Compare
… adds testId to dismiss button
e63bfae to
82d49c0
Compare
| : ariaLabelledBy | ||
| ? undefined | ||
| : undefined; |
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.
Could the ariaLabelledBy ? undefined : undefined be simplified to undefined? 😄
| aria-label={ariaLabelValue} | ||
| aria-labelledby={ariaLabelledBy} |
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.
Based on the prop docs:
aria-labelledby- For ID references (will take precedence overaria-labelif both are provided).
There's a case where both the aria-label and aria-labelledby attributes can be set! Does aria-label need to be undefined if aria-labelledby is set?
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 was trying to simplify the typing since it got so complicated with wrapper components... I updated this to be mutually exclusive again, here's hoping it didn't reintroduce nightmare typing for consumers! (discriminated unions are so cryptic!) 🙏
| <DismissButton | ||
| aria-label={labels?.dismissButtonAriaLabel || "Close"} | ||
| onClick={(e) => onDismiss?.(e)} | ||
| testId={`${testId}-dismiss-button`} |
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.
| testId={`${testId}-dismiss-button`} | |
| testId={testId && `${testId}-dismiss-button`} |
We can check for testId first to avoid having a undefined-dismiss-button test id all the time on the close button!
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.
Added a fix for this!
beaesguerra
left a comment
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.
Looks good to me! 🚀
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2859 +/- ##
============================
============================
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary:
When integrating Cards into the frontend repo, I ran into a few complications that I wanted to fix:
Issue: FEI-6310
Related
frontendPR: https://github.com/Khan/frontend/pull/5283Test plan: