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

chore: Expandable component style refactor #3128

Open
wants to merge 14 commits into
base: prerelease/major
Choose a base branch
from

Conversation

williamjstanton
Copy link
Collaborator

@williamjstanton williamjstanton commented Feb 8, 2025

Summary

Fixes: #2954

Expandable style re-factor is needed with the new cs prop. We will need to update this component to use the new system level tokens via CSS variables.

Release Category

Tokens

Release Note

  • The ExpandableTarget component is now rendering the BaseButton component, and may have some small impact on the visual styling of the keyboard focus ring.
  • The ExpandableIcon stencil is extending the SystemIcon stencil, and may have had an impact on the chevron icon color.
  • Fixed an accessibility bug in the Avatar component where an aria-label string was rendered on a generic HTML element that did not have an explicit or implicit role

Checklist

For the Reviewer

  • PR title is short and descriptive
  • PR summary describes the change (Fixes/Resolves linked correctly)
  • PR Release Notes describes additional information useful to call out in a release message or removed if not applicable
  • Breaking Changes provides useful information to upgrade to this code or removed if not applicable

Where Should the Reviewer Start?

modules/labs-react/expandable/lib/Expandable.tsx
(all subcomponents)
Line 274: modules/react/avatar/lib/Avatar.tsx

Areas for Feedback? (optional)

  • Code
  • Documentation
  • Testing
  • Codemods

Testing Manually

Screenshots or GIFs (if applicable)

expandable-focus expandable-hover

Thank You Gif (optional)

William Stanton added 12 commits January 22, 2025 18:25
Explicit ARIA role is unnecessary when roles are implied from Element. If Element is button, then set aria-label string to altText, else aria-label is undefined. Consumers can pass ARIA role and aria-label through props if using Avatar in an informative way.
Replaced <Box> with <Element> to remove 'as' prop and simplify code.
Copy link

cypress bot commented Feb 8, 2025

Workday/canvas-kit    Run #8283

Run Properties:  status check passed Passed #8283  •  git commit 6a1992e08a ℹ️: Merge 77df7478641ca1beb54764969dddb2d1c1ab36ff into 20a9a33c6a1b54b37959d5523881...
Project Workday/canvas-kit
Branch Review william-issue-2954-expandable-style-refactor
Run status status check passed Passed #8283
Run duration 03m 03s
Commit git commit 6a1992e08a ℹ️: Merge 77df7478641ca1beb54764969dddb2d1c1ab36ff into 20a9a33c6a1b54b37959d5523881...
Committer William Stanton
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 21
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 929
View all changes introduced in this branch ↗︎
UI Coverage  21.32%
  Untested elements 1522  
  Tested elements 410  
Accessibility  99.17%
  Failed rules  6 critical   5 serious   0 moderate   2 minor
  Failed elements 162  

@williamjstanton williamjstanton changed the base branch from master to prerelease/major February 10, 2025 20:09
@mannycarrera4 mannycarrera4 added the ready for review Code is ready for review label Feb 13, 2025
marginRight: system.space.x2,
flexShrink: 0,
export const expandableAvatarStencil = createStencil({
base: {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this renders an avatar, maybe we extend the avatarStencil as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did try this, and then noticed that the <img> didn't work in the Avatar examples. I didn't spend a lot of time digging in and trying to understand why.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found a bug, we have to switch the order of the stencil if we move false above true it works as intended: https://github.com/Workday/canvas-kit/blob/master/modules/react/avatar/lib/Avatar.tsx#L221

My guess is true gets called first and never gets to false

});

// When the component is created, it needs to be a button element to match AvatarProps.
// Once Avatar becomes a `createComponent` we can default the element type to a `div`
// and the types should be properly extracted
// Setting altText prop to a default empty string for decorative purposes
Copy link
Contributor

Choose a reason for hiding this comment

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

should we set aria-hidden as well?

Copy link
Collaborator Author

@williamjstanton williamjstanton Feb 14, 2025

Choose a reason for hiding this comment

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

No, I don't believe aria-hidden is necessary. Setting the alt attribute on
elements to an empty string is the best practice, and very effective
for hiding images. In the case of an <svg>, we already use ARIA role
"presentation" which strips the implied 'img' role in an <svg> element.
This gives us the same outcome (hiding the graphic), if we can assume there
isn't any <text> rendered in the <svg>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, i just asked because we had an instance where a user can add a url, and cypress complains that you can't have an image with empty alt text, so we had to add aria-hidden

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"... can add a url" - what do you mean? Does this turn the image into a linked image... ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if you pass a url to say an image that's hosted, it renders an img element which requires an alt attribute.

@mannycarrera4
Copy link
Contributor

Looks like the gap / padding seems off

Your PR

image

Master

image

Comment on lines +33 to +64
compound: [
{
modifiers: {position: 'end', isExpanded: 'false'},
styles: {
marginLeft: 'auto',
transform: 'rotate(180deg)',
paddingRight: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'end', isExpanded: 'true'},
styles: {
marginLeft: 'auto',
paddingLeft: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'start', isExpanded: 'false'},
styles: {
marginRight: system.space.x2,
transform: 'rotate(90deg)',
},
},
{
modifiers: {position: 'start', isExpanded: 'true'},
styles: {
marginRight: system.space.x2,
transform: 'rotate(180deg)',
},
},
],
});
Copy link
Contributor

@josh-bagwell josh-bagwell Feb 25, 2025

Choose a reason for hiding this comment

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

This is for RTL support with using inline for padding and margin.

Suggested change
compound: [
{
modifiers: {position: 'end', isExpanded: 'false'},
styles: {
marginLeft: 'auto',
transform: 'rotate(180deg)',
paddingRight: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'end', isExpanded: 'true'},
styles: {
marginLeft: 'auto',
paddingLeft: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'start', isExpanded: 'false'},
styles: {
marginRight: system.space.x2,
transform: 'rotate(90deg)',
},
},
{
modifiers: {position: 'start', isExpanded: 'true'},
styles: {
marginRight: system.space.x2,
transform: 'rotate(180deg)',
},
},
],
});
compound: [
{
modifiers: {position: 'end', isExpanded: 'false'},
styles: {
marginInlineStart: 'auto',
transform: 'rotate(180deg)',
paddingInlineEnd: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'end', isExpanded: 'true'},
styles: {
marginInlineStart: 'auto',
paddingInlineStart: system.space.x3, // do I need these padding changes?
},
},
{
modifiers: {position: 'start', isExpanded: 'false'},
styles: {
marginInlineEnd: system.space.x2,
transform: 'rotate(90deg)',
},
},
{
modifiers: {position: 'start', isExpanded: 'true'},
styles: {
marginInlineEnd: system.space.x2,
transform: 'rotate(180deg)',
},
},
],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expandable Styles Refactor
3 participants