Repository navigation
feat(ui-components): add states and full-width support to Button component - #45665
Conversation
|
👀 Review this PR in a CodeSee Review Map |
You are correct, it is technically sufficient for now under WCAG 2.1 but it won't be under WCAG 2.2 as SC 2.4.11 is being added which will create a new minimum standard for focus appearance, which many browsers will not meet, so basically we will need to make sure we have a good custom focus indicator that can be seen in all browsers. In PR #45137 I suggested we use WCAG 2.2 probably won't be officially released until this Fall but I don't think that should stop us from having a better focus indicator now. |
| 'active:before:w-full', | ||
| 'active:before:h-full', | ||
| 'active:before:absolute', | ||
| 'active:before:inset-0', | ||
| 'active:before:border-3', | ||
| 'active:before:border-transparent', | ||
| 'active:before:bg-gray-900', | ||
| 'active:before:opacity-20', |
There was a problem hiding this comment.
Basically when the button is in active state, we will show an overlay using a pseudo element. I set border-3 and border-transparent classes so that the overlay doesn't cover the border of the main element.
| ...(disabled | ||
| ? [] | ||
| : [ | ||
| 'hover:bg-default-background-danger-hover', | ||
| 'hover:text-default-foreground-danger-hover' | ||
| ]) |
There was a problem hiding this comment.
This would be &:hover:not([aria-disabled="true"]) if we were to write in CSS. Unfortunately Tailwind doesn't allow a not selector so I had to add a condition here.
| className={classes} | ||
| type={type} | ||
| onClick={handleClick} | ||
| aria-disabled={disabled} |
There was a problem hiding this comment.
aria-disabled is more preferred as it allows the user to focus on the element and understand that the button is disabled. While with the disabled attribute, the button is not focusable, and non-sighted users won't know about its existence nor its disabled state.
Refs:
| gray: { | ||
| 0: 'var(--gray00)', | ||
| 50: 'var(--gray05)', | ||
| 100: 'var(--gray10)', | ||
| 150: 'var(--gray15)', | ||
| 450: 'var(--gray45)', | ||
| 750: 'var(--gray75)', | ||
| 800: 'var(--gray80)', | ||
| 850: 'var(--gray85)', | ||
| 900: 'var(--gray90)' | ||
| }, |
There was a problem hiding this comment.
I only need gray90, but adding all of the variables in anyway, since we already did that for other colors.
| plugins: [ | ||
| plugin(({ addVariant }) => { | ||
| addVariant('aria-disabled', '[aria-disabled="true"]'); | ||
| }) | ||
| ] |
There was a problem hiding this comment.
Tailwind supports a lot of selectors by default (ref), but aria-disabled isn't one of them. I followed this guide to add our own modifier. This allows us to style the disabled state using aria-disabled:... classes.
And at this point, I have to say I'm very impressed with Tailwind. They support everything!!! And their documentation is very well-written.
|
@bbsmooth Thanks a lot for the guidance! I vaguely remember reading about this new requirement in the past, but I wasn't aware of the date it would be applied. (And it being a draft made me think it would be a while until the internet elders decide to roll it out lol.) I have updated the PR to use our own focus ring and I have also added screenshots to the PR description. Let me know what you think 🙂 |
|
Ouch! Thanks Ahmad, that's a nice catch! This is probably a good opportunity for new contributors to get familiar with our UI components. I'll create a issue for this 🙂 |


Checklist:
Update index.md)mainbranch of freeCodeCamp.Ref #45357
This PR adds the following support to the Button component:
disabledprop)blockprop)Note: The PR can be reviewed by commits.
Screenshots
Active state
I'm adding a screenshot of the normal state for comparison:
Focus state
Disabled state
Note: Inactive/disabled elements are allowed to not meet the contrast minimum (Ref: https://www.w3.org/TR/WCAG21/#contrast-minimum)
Full-width button