Skip to content

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

TypeScript

Slider: color marks inside the filled region with the fill color (#6455)

Kenton Quatman158512f79464
diff --git a/.changeset/slider-marks-fill-color.md b/.changeset/slider-marks-fill-color.md
new file mode 100644
index 0000000000..c96963876b
--- /dev/null
+++ b/.changeset/slider-marks-fill-color.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Slider marks inside the filled region use the fill color: marks at or behind the thumb in single mode, and marks between the thumbs in range mode, now paint with the accent fill color instead of the default mark color. Marks on the unfilled side are unchanged.
+
+@kentonquatman
diff --git a/packages/core/src/Slider/Slider.doc.mjs b/packages/core/src/Slider/Slider.doc.mjs
index c3a135a347..1f4d5b06a0 100644
--- a/packages/core/src/Slider/Slider.doc.mjs
+++ b/packages/core/src/Slider/Slider.doc.mjs
@@ -160,7 +160,8 @@ export const docs = {
{
name: 'marks',
type: 'Array<{ value: number; label?: string }>',
- description: 'Tick marks at specified positions with optional labels.',
+ 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.',
},
{
name: 'minStepsBetweenThumbs',
diff --git a/packages/core/src/Slider/Slider.test.tsx b/packages/core/src/Slider/Slider.test.tsx
index b1e7cf4365..679e8bd58c 100644
--- a/packages/core/src/Slider/Slider.test.tsx
+++ b/packages/core/src/Slider/Slider.test.tsx
@@ -13,7 +13,7 @@ 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} 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,6 +728,78 @@ describe('Slider', () => {
expect(handleChange).toHaveBeenCalledWith(100);
});
+ // --- Marks fill 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 {
+ return rulesDeclaredFor(el).some(rule => {
+ const selector = rule
+ .slice(0, rule.indexOf('{'))
+ .replaceAll(':not(#\\#)', '');
+ return !selector.includes(':') && rule.includes('var(--color-accent)');
+ });
+ }
+
+ it('colors marks at or behind the thumb with the fill color', () => {
+ render(
+ <Slider
+ label="Volume"
+ value={50}
+ min={0}
+ max={100}
+ marks={[
+ {value: 0},
+ {value: 25},
+ {value: 50},
+ {value: 75},
+ {value: 100},
+ ]}
+ />,
+ );
+ const marks = screen.getAllByTestId('slider-mark');
+ expect(marks).toHaveLength(5);
+ // Marks at 0, 25, and 50 sit at or behind the thumb: fill color.
+ expect(declaresFillColor(marks[0])).toBe(true);
+ expect(declaresFillColor(marks[1])).toBe(true);
+ expect(declaresFillColor(marks[2])).toBe(true);
+ // Marks at 75 and 100 sit ahead of the thumb: default mark color.
+ expect(declaresFillColor(marks[3])).toBe(false);
+ expect(declaresFillColor(marks[4])).toBe(false);
+ });
+
+ it('colors marks between the thumbs with the fill color in range mode', () => {
+ render(
+ <Slider
+ label="Price range"
+ value={[20, 80] as [number, number]}
+ min={0}
+ max={100}
+ marks={[
+ {value: 0},
+ {value: 20},
+ {value: 50},
+ {value: 80},
+ {value: 100},
+ ]}
+ />,
+ );
+ const marks = screen.getAllByTestId('slider-mark');
+ expect(marks).toHaveLength(5);
+ // The mark at 0 sits before the range: default mark color.
+ expect(declaresFillColor(marks[0])).toBe(false);
+ // Marks at 20, 50, and 80 sit between (or at) the thumbs: fill color.
+ expect(declaresFillColor(marks[1])).toBe(true);
+ expect(declaresFillColor(marks[2])).toBe(true);
+ expect(declaresFillColor(marks[3])).toBe(true);
+ // The mark at 100 sits after the range: default mark color.
+ expect(declaresFillColor(marks[4])).toBe(false);
+ });
+
// --- Boundary clamping ---
it('clamps value at max boundary', async () => {
diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsx
index 22a7ff83ac..12375545da 100644
--- a/packages/core/src/Slider/Slider.tsx
+++ b/packages/core/src/Slider/Slider.tsx
@@ -326,6 +326,12 @@ const styles = stylex.create({
backgroundColor: colorVars['--color-border-emphasized'],
borderRadius: radiusVars['--radius-full'],
},
+ // Marks over the filled region (at or behind the thumb in single mode,
+ // between the thumbs in range mode) take the fill color so they read as
+ // part of the filled track rather than the unfilled rail.
+ markFilled: {
+ backgroundColor: colorVars['--color-accent'],
+ },
markHorizontal: {
width: 2,
height: 8,
@@ -1103,6 +1109,12 @@ export function Slider({ref, ...props}: SliderProps) {
const markPos = isHorizontal
? {insetInlineStart: insetPosition(percent)}
: {bottom: insetPosition(percent)};
+ // Marks at or inside the filled region take the fill color:
+ // at or behind the thumb in single mode, between the thumbs
+ // in range mode.
+ const isFilled = isRange
+ ? mark.value >= values[0] && mark.value <= values[1]
+ : mark.value <= values[0];
return (
<div key={mark.value}>
<div
@@ -1114,6 +1126,7 @@ export function Slider({ref, ...props}: SliderProps) {
isHorizontal
? styles.markHorizontal
: styles.markVertical,
+ isFilled && styles.markFilled,
),
{style: markPos},
)}