Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: Clarify enabled switch colors (#6631)

Oleg Isonenc755578dbe76
diff --git a/packages/design-system/src/components/form-control-contrast.browser.test.ts b/packages/design-system/src/components/form-control-contrast.browser.test.ts
index e169d60737..7c75f1cbfe 100644
--- a/packages/design-system/src/components/form-control-contrast.browser.test.ts
+++ b/packages/design-system/src/components/form-control-contrast.browser.test.ts
@@ -33,6 +33,15 @@ const readColor = (color: string) => {
return Array.from(context.getImageData(0, 0, 1, 1).data);
};
+const readTokenColor = (name: string) => {
+ const sample = document.createElement("span");
+ sample.style.color = `var(${name})`;
+ document.body.append(sample);
+ const color = readColor(getComputedStyle(sample).color);
+ sample.remove();
+ return color;
+};
+
test("compact form controls use their intended resting treatment", () => {
const container = document.createElement("div");
document.body.append(container);
@@ -55,6 +64,22 @@ test("compact form controls use their intended resting treatment", () => {
{ "data-switch": true },
createElement(Switch, { "aria-label": "Switch" })
),
+ createElement(
+ "div",
+ { "data-disabled-switch": true },
+ createElement(Switch, {
+ "aria-label": "Disabled switch",
+ disabled: true,
+ })
+ ),
+ createElement(
+ "div",
+ { "data-checked-switch": true },
+ createElement(Switch, {
+ "aria-label": "Checked switch",
+ checked: true,
+ })
+ ),
createElement(
"div",
{ "data-neutral-control": true },
@@ -86,6 +111,23 @@ test("compact form controls use their intended resting treatment", () => {
expect(
readColor(getComputedStyle(switchControl, "::before").backgroundColor),
`${mode} switch resting track`
+ ).toEqual(readTokenColor("--foreground-disabled"));
+ const disabledSwitch = container.querySelector(
+ "[data-disabled-switch] > button"
+ );
+ const checkedSwitch = container.querySelector(
+ "[data-checked-switch] > button"
+ );
+ if (disabledSwitch === null || checkedSwitch === null) {
+ throw new Error("Expected disabled and checked switches");
+ }
+ expect(
+ readColor(getComputedStyle(disabledSwitch, "::before").backgroundColor),
+ `${mode} disabled switch track`
).toEqual(readColor(getComputedStyle(neutralControl).backgroundColor));
+ expect(
+ readColor(getComputedStyle(checkedSwitch, "::before").backgroundColor),
+ `${mode} checked switch track`
+ ).toEqual(readTokenColor("--background-accent"));
}
});
diff --git a/packages/design-system/src/components/switch.tsx b/packages/design-system/src/components/switch.tsx
index ae50d130cc..b4579120f6 100644
--- a/packages/design-system/src/components/switch.tsx
+++ b/packages/design-system/src/components/switch.tsx
@@ -29,7 +29,7 @@ const switchStyle = css({
position: "absolute",
inset: padding,
borderRadius: theme.borderRadius.pill,
- backgroundColor: neutralControlBackground,
+ backgroundColor: cssVar("--foreground-disabled"),
},
"&[data-state=checked]:not([data-disabled]):before, &[aria-checked=true]:not([data-disabled]):before":
@@ -38,7 +38,7 @@ const switchStyle = css({
},
"&[data-disabled]:before": {
- backgroundColor: cssVar("--foreground-disabled"),
+ backgroundColor: neutralControlBackground,
},
"&:focus": {