Skip to content

Commit a878811

Browse files
aPreciado88benelan
authored andcommitted
feat(switch): enhance component's colors for a11y and usability (#11951)
**Related Issue:** [#10483](#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.
1 parent 243b567 commit a878811

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

packages/calcite-components/src/components/switch/switch.e2e.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ describe("calcite-switch", () => {
151151
shadowSelector: `.${CSS.track}`,
152152
targetProp: "backgroundColor",
153153
},
154-
"--calcite-switch-border-color": {
154+
"--calcite-switch-background-color-hover": {
155155
shadowSelector: `.${CSS.track}`,
156-
targetProp: "borderColor",
156+
targetProp: "backgroundColor",
157+
state: "hover",
157158
},
158159
"--calcite-switch-corner-radius": {
159160
shadowSelector: `.${CSS.track}`,
@@ -163,6 +164,15 @@ describe("calcite-switch", () => {
163164
shadowSelector: `.${CSS.handle}`,
164165
targetProp: "backgroundColor",
165166
},
167+
});
168+
});
169+
170+
describe("deprecated", () => {
171+
themed(html`calcite-switch`, {
172+
"--calcite-switch-border-color": {
173+
shadowSelector: `.${CSS.track}`,
174+
targetProp: "borderColor",
175+
},
166176
"--calcite-switch-handle-border-color": {
167177
shadowSelector: `.${CSS.handle}`,
168178
targetProp: "borderColor",

packages/calcite-components/src/components/switch/switch.scss

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* These properties can be overridden using the component's tag as selector.
55
*
66
* @prop --calcite-switch-background-color: Specifies the component's background color.
7-
* @prop --calcite-switch-border-color: Specifies the component's border color.
7+
* @prop --calcite-switch-background-color-hover: Specifies the component's background color when hovered or pressed.
8+
* @prop --calcite-switch-border-color: [Deprecated] No longer necessary. Specifies the component's border color.
89
* @prop --calcite-switch-corner-radius: Specifies the component's corner radius.
910
* @prop --calcite-switch-handle-background-color: Specifies the handle's background color.
10-
* @prop --calcite-switch-handle-border-color: Specifies the handle's border color.
11-
* @prop --calcite-switch-handle-shadow: Specifies the handle's shadow.
11+
* @prop --calcite-switch-handle-border-color: [Deprecated] No longer necessary. Specifies the handle's border color.
12+
* @prop --calcite-switch-handle-shadow: [Deprecated] No longer necessary. Specifies the handle's shadow.
1213
*/
1314

1415
// sizes
@@ -69,59 +70,48 @@
6970
relative
7071
box-border
7172
inline-block
72-
border
73-
border-solid
7473
align-top
7574
focus-base;
7675

7776
border-radius: var(--calcite-switch-corner-radius, 9999px);
78-
border-color: var(--calcite-switch-border-color, var(--calcite-color-border-2));
79-
background-color: var(--calcite-switch-background-color, var(--calcite-color-foreground-2));
77+
border-color: var(--calcite-switch-border-color);
78+
background-color: var(--calcite-switch-background-color, var(--calcite-color-border-input));
8079
}
8180

8281
.container:focus .track {
8382
@apply focus-outset;
8483
}
8584

85+
.container:hover .track {
86+
background-color: var(--calcite-switch-background-color-hover, var(--calcite-color-text-3));
87+
}
88+
8689
.handle {
8790
@apply pointer-events-none
8891
absolute
8992
block
90-
border-2
91-
border-solid
9293
transition-all
9394
duration-150
9495
ease-in-out;
95-
inset-block-start: -1px;
96-
inset-inline: -1px theme("inset.auto");
96+
inset-block-start: var(--calcite-spacing-base);
97+
inset-inline: var(--calcite-spacing-base) auto;
9798
background-color: var(--calcite-switch-handle-background-color, var(--calcite-color-foreground-1));
98-
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-border-input));
99+
border-color: var(--calcite-switch-handle-border-color);
99100
border-radius: var(--calcite-switch-corner-radius, 9999px);
100101
box-shadow: var(--calcite-switch-handle-shadow);
101102
}
102103

103-
:host(:hover:not([disabled])),
104-
:host(:focus:not([disabled])) {
105-
.handle {
106-
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
107-
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand));
108-
}
109-
}
110-
111104
:host([checked]) {
112105
.track {
113-
border-color: var(--calcite-switch-border-color, var(--calcite-color-brand-hover));
114106
background-color: var(--calcite-switch-background-color, var(--calcite-color-brand));
115107
}
116108
.handle {
117-
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand));
118-
inset-inline: theme("inset.auto") -1px;
109+
inset-inline: auto var(--calcite-spacing-base);
119110
}
120111

121112
&:host(:hover:not([disabled])) {
122-
.handle {
123-
border-color: var(--calcite-switch-handle-border-color, var(--calcite-color-brand-hover));
124-
box-shadow: var(--calcite-switch-handle-shadow, inset 0 0 0 1px var(--calcite-color-brand-hover));
113+
.track {
114+
background-color: var(--calcite-switch-background-color-hover, var(--calcite-color-brand-hover));
125115
}
126116
}
127117
}

packages/calcite-components/src/custom-theme/switch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { html } from "../../support/formatting";
22

33
export const switchTokens = {
44
calciteSwitchBackgroundColor: "",
5+
calciteSwitchBackgroundColorHover: "",
56
calciteSwitchBorderColor: "",
67
calciteSwitchHandleBorderColor: "",
78
calciteSwitchHandleBackgroundColor: "",

0 commit comments

Comments
 (0)