Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Slider): use track token for unfilled marks (#6461)

Kenton Quatmanc9fb1ad0fa83
diff --git a/.changeset/slider-uses-the-track-token-for-unfilled-tick-ma-5nd1.md b/.changeset/slider-uses-the-track-token-for-unfilled-tick-ma-5nd1.md
new file mode 100644
index 0000000000..0ef0a94420
--- /dev/null
+++ b/.changeset/slider-uses-the-track-token-for-unfilled-tick-ma-5nd1.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Slider uses the track token for unfilled tick marks so marks and rails stay aligned across themes
+@kentonquatman
diff --git a/packages/core/src/Slider/Slider.doc.mjs b/packages/core/src/Slider/Slider.doc.mjs
index 1f4d5b06a0..563a69774b 100644
--- a/packages/core/src/Slider/Slider.doc.mjs
+++ b/packages/core/src/Slider/Slider.doc.mjs
@@ -161,7 +161,7 @@ export const docs = {
name: 'marks',
type: 'Array<{ value: number; label?: string }>',
description:
- 'Tick marks at specified positions with optional labels. Marks inside the filled region (at or behind the thumb, or between the thumbs in range mode) use the fill color.',
+ 'Tick marks at specified positions with optional labels. Unfilled marks use the track color; marks inside the filled region (at or behind the thumb, or between the thumbs in range mode) use the fill color.',
},
{
name: 'minStepsBetweenThumbs',
@@ -366,7 +366,8 @@ export const docsZh = {
{
name: 'marks',
type: 'Array<{ value: number; label?: string }>',
- description: '在指定位置的刻度标记,带可选标签。',
+ description:
+ '在指定位置的刻度标记,带可选标签。未填充区域的标记使用轨道颜色;填充区域内的标记使用强调色。',
},
{
name: 'minStepsBetweenThumbs',
@@ -532,7 +533,8 @@ export const docsDense = {
orientation: 'Slider orientation.',
formatValue: 'Custom value formatting fn for display + aria-valuetext.',
valueDisplay: 'How current value is displayed.',
- marks: 'Tick marks at specified positions w/ optional labels.',
+ marks:
+ 'Tick marks at specified positions w/ optional labels. Unfilled marks use the track color; filled marks use the accent color.',
minStepsBetweenThumbs:
'Min steps between thumbs in range mode; prevents overlap.',
isDisabled: 'Whether slider is disabled.',
diff --git a/packages/core/src/Slider/Slider.test.tsx b/packages/core/src/Slider/Slider.test.tsx
index 679e8bd58c..268baba432 100644
--- a/packages/core/src/Slider/Slider.test.tsx
+++ b/packages/core/src/Slider/Slider.test.tsx
@@ -13,7 +13,10 @@ import {useState} from 'react';
import {describe, it, expect, vi, beforeEach} from 'vitest';
import {render, screen, act, fireEvent, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
-import {declaresPressedOverlay, rulesDeclaredFor} from '../__tests__/pressState';
+import {
+ declaresPressedOverlay,
+ rulesDeclaredFor,
+} from '../__tests__/pressState';
import * as stylex from '@stylexjs/stylex';
import {Slider} from './Slider';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
@@ -728,23 +731,41 @@ describe('Slider', () => {
expect(handleChange).toHaveBeenCalledWith(100);
});
- // --- Marks fill color ---
+ // --- Marks color ---
- /**
- * Whether the element has an unconditional rule painting the accent (fill)
- * color. Mirrors declaresPressedOverlay: the base mark paints
- * --color-border-emphasized, and marks inside the filled region additionally
- * paint --color-accent.
- */
- function declaresFillColor(el: Element): boolean {
+ /** Whether the element has an unconditional rule painting a token. */
+ function declaresColorToken(el: Element, token: string): boolean {
return rulesDeclaredFor(el).some(rule => {
const selector = rule
.slice(0, rule.indexOf('{'))
.replaceAll(':not(#\\#)', '');
- return !selector.includes(':') && rule.includes('var(--color-accent)');
+ return !selector.includes(':') && rule.includes(`var(${token})`);
});
}
+ it('uses the track color for unfilled marks and the accent for filled marks', () => {
+ render(
+ <Slider
+ label="Volume"
+ value={50}
+ min={0}
+ max={100}
+ marks={[{value: 25}, {value: 75}]}
+ />,
+ );
+ const marks = screen.getAllByTestId('slider-mark');
+
+ expect(marks).toHaveLength(2);
+ expect(declaresColorToken(marks[0], '--color-track')).toBe(false);
+ expect(declaresColorToken(marks[0], '--color-accent')).toBe(true);
+ expect(declaresColorToken(marks[1], '--color-track')).toBe(true);
+ expect(declaresColorToken(marks[1], '--color-accent')).toBe(false);
+ });
+
+ function declaresFillColor(el: Element): boolean {
+ return declaresColorToken(el, '--color-accent');
+ }
+
it('colors marks at or behind the thumb with the fill color', () => {
render(
<Slider
diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsx
index 12375545da..16812b521f 100644
--- a/packages/core/src/Slider/Slider.tsx
+++ b/packages/core/src/Slider/Slider.tsx
@@ -5,7 +5,7 @@
/**
* @file Slider.tsx
* @input Uses React, useId, useRef, useCallback, Field, Tooltip, useTooltip, VisuallyHidden
- * @output Exports Slider and its props; modifier-only key presses do not restore the thumb focus ring
+ * @output Exports Slider and its props; unfilled marks share the track token; modifier-only key presses do not restore the thumb focus ring
* @position Core implementation; consumed by index.ts, tested by Slider.test.tsx
*
* SYNC: When modified, update these files to stay in sync:
@@ -323,7 +323,7 @@ const styles = stylex.create({
},
mark: {
position: 'absolute',
- backgroundColor: colorVars['--color-border-emphasized'],
+ backgroundColor: colorVars['--color-track'],
borderRadius: radiusVars['--radius-full'],
},
// Marks over the filled region (at or behind the thumb in single mode,