Skip to content

feat(switch): enhance component's colors for a11y and usability #11951

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

aPreciado88
Copy link
Contributor

Related Issue: #10483

Summary

  • Increase contrast and visual presence of idle state.
  • Simplify track and handle to one color and remove strokes.
  • Simplify hover & focus state: remove hover and focus ring on the handle.

@github-actions github-actions bot added the enhancement Issues tied to a new feature or request. label Apr 14, 2025
…ciado88/10483-switch-enhance-component-colors-for-a11y-and-usability
@aPreciado88 aPreciado88 added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Apr 14, 2025
@aPreciado88
Copy link
Contributor Author

@ashetland @SkyeSeitz Can you please take a look?

@SkyeSeitz
Copy link

@ashetland @SkyeSeitz Can you please take a look?

Updates look great! ✨

@@ -4,11 +4,12 @@
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-switch-background-color: Specifies the component's background color.
* @prop --calcite-switch-border-color: Specifies the component's border color.
* @prop --calcite-switch-background-color-hover: Specifies the component's background color when hovered or pressed.
* @prop --calcite-switch-border-color: [Deprecated] Specifies the component's border color.
Copy link
Member

Choose a reason for hiding this comment

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

Should we specify any deprecation reasoning or what they should use instead?

Copy link
Member

Choose a reason for hiding this comment

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

We don't have other similar references across our CSS doc, but since the border is no longer applicable, maybe we could go with:

Suggested change
* @prop --calcite-switch-border-color: [Deprecated] Specifies the component's border color.
* @prop --calcite-switch-border-color: [Deprecated] No longer necessary. Specifies the component's border color.

cc @DitwanP

border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand));
border-color: var(--calcite-switch-handle-border-color);
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 0);
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to set box-shadow here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this, thanks for catching it!

border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand-hover));
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand-hover));
border-color: var(--calcite-switch-handle-border-color);
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 0);
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to set box-shadow here?

@aPreciado88 aPreciado88 added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Apr 15, 2025
@aPreciado88 aPreciado88 requested a review from driskull April 15, 2025 21:43
transition-all
duration-150
ease-in-out;
inset-block-start: -1px;
inset-inline: -1px theme("inset.auto");
inset-block-start: 2px;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a platform design token that can be used here? Maybe a border width one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated this to use --calcite-border-width-md

inset-block-start: -1px;
inset-inline: -1px theme("inset.auto");
inset-block-start: 2px;
inset-inline: 2px theme("inset.auto");
Copy link
Member

Choose a reason for hiding this comment

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

can the theme() be replaced with a css var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find a css var with auto as a value, but I replaced theme("inset.auto") with just "auto".

background-color: var(--calcite-switch-background-color, var(--calcite-color-brand));
}
.handle {
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
inset-inline: theme("inset.auto") -1px;
inset-inline: theme("inset.auto") 2px;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a platform design token that can be used here? Maybe a border width one? can the theme() be replaced with a css var?

Copy link
Member

Choose a reason for hiding this comment

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

I think theme("inset.auto") can just be replaced with auto

Copy link
Member

Choose a reason for hiding this comment

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

I think the inset-inline could be calc(var(--calcite-spacing-base) * -1)

background-color: var(--calcite-switch-background-color, var(--calcite-color-brand));
}
.handle {
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
inset-inline: theme("inset.auto") -1px;
inset-inline: theme("inset.auto") 2px;
Copy link
Member

Choose a reason for hiding this comment

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

I think theme("inset.auto") can just be replaced with auto

background-color: var(--calcite-switch-background-color, var(--calcite-color-brand));
}
.handle {
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
inset-inline: theme("inset.auto") -1px;
inset-inline: theme("inset.auto") 2px;
Copy link
Member

Choose a reason for hiding this comment

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

I think the inset-inline could be calc(var(--calcite-spacing-base) * -1)

transition-all
duration-150
ease-in-out;
inset-block-start: -1px;
inset-inline: -1px theme("inset.auto");
inset-block-start: var(--calcite-border-width-md);
Copy link
Member

Choose a reason for hiding this comment

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

@aPreciado88 this should be a negative value right? Also, I think a spacing value is better since its not a border.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need a positive value now, since we removed the border. I'm updating this to inset-block-start: var(--calcite-spacing-base);

background-color: var(--calcite-switch-background-color, var(--calcite-color-brand));
}
.handle {
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
inset-inline: theme("inset.auto") -1px;
inset-inline: auto var(--calcite-border-width-md);
Copy link
Member

Choose a reason for hiding this comment

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

@aPreciado88 this should be a negative value right? Also, I think a spacing value is better since its not a border.

Copy link
Contributor Author

@aPreciado88 aPreciado88 Apr 15, 2025

Choose a reason for hiding this comment

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

We also need a positive value here, since the border is now gone. I'm updating this to inset-inline: auto var(--calcite-spacing-base);

…ciado88/10483-switch-enhance-component-colors-for-a11y-and-usability
@@ -151,9 +151,10 @@ describe("calcite-switch", () => {
shadowSelector: `.${CSS.track}`,
targetProp: "backgroundColor",
},
"--calcite-switch-border-color": {
"--calcite-switch-background-color-hover": {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add this var to the switch custom theme story tokens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this, thanks for catching it!

@aPreciado88 aPreciado88 requested a review from driskull April 15, 2025 23:11
@aPreciado88 aPreciado88 added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Apr 15, 2025
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

👍

inset-block-start: -1px;
inset-inline: -1px theme("inset.auto");
inset-block-start: var(--calcite-spacing-base);
inset-inline: var(--calcite-border-width-md) auto;
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this should be using a border var and not a spacing one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I missed this. Updating it now!

@aPreciado88 aPreciado88 added pr ready for visual snapshots Adding this label will run visual snapshot testing. skip visual snapshots Pull requests that do not need visual regression testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Apr 15, 2025
@aPreciado88 aPreciado88 merged commit 52886ef into dev Apr 15, 2025
17 checks passed
@aPreciado88 aPreciado88 deleted the aPreciado88/10483-switch-enhance-component-colors-for-a11y-and-usability branch April 15, 2025 23:58
benelan added a commit that referenced this pull request Apr 17, 2025
…gis-deps

* origin/dev: (31 commits)
  chore: add workflow manager to team issue templates (#11971)
  chore: release next
  feat(accordion-item): enhance component's interactivity states (#11935)
  chore: release next
  build(deps): update dependency lerna to v8.2.2 (#11948)
  feat(switch): enhance component's colors for a11y and usability (#11951)
  chore: release next
  ci: remove redundant test mode environment variable (#11958)
  fix(input-date-picker): allow clearing invalid date value (#11937)
  build: update browserslist db (#11946)
  feat(notice): add token for close icon and title text color (#11938)
  fix(list, block-group): fix drag handle events when lists or blocks are nested (#11816)
  chore: release next
  build(deps): update dependency vite to v5.4.18 (#11949)
  ci: default to stable tests when experimental mode is not set (#11957)
  fix(input-number): cancel arrow down event (#11956)
  refactor: tidy up (#11945)
  docs(checkbox): update icon color prop context (#11950)
  build(deps): bump node minor version (#11927)
  chore: release next
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues tied to a new feature or request. skip visual snapshots Pull requests that do not need visual regression testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants