An open source design system that's fully customizable and agent ready
TypeScript
feat(selector): expose selector-check theme target on the selected marker (#4627)
athz7521845f6fc7
diff --git a/.changeset/selector-check-target.md b/.changeset/selector-check-target.mdnew file mode 100644index 0000000000..b7643ce03f--- /dev/null+++ b/.changeset/selector-check-target.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[feat] Selector: expose a `selector-check` theme target on the selected-row checkmark so themes can restyle or hide it (e.g. to compose their own selected indicator via `renderOption`) instead of relying on a structural sibling selector. Purely additive — default appearance is unchanged.+@athzdiff --git a/packages/core/src/Selector/Selector.doc.mjs b/packages/core/src/Selector/Selector.doc.mjsindex 4a35914d41..669c859bd4 100644--- a/packages/core/src/Selector/Selector.doc.mjs+++ b/packages/core/src/Selector/Selector.doc.mjs@@ -28,6 +28,7 @@ export const docs = {{className: 'astryx-selector-option'},{className: 'astryx-selector-clear-icon'},{className: 'astryx-selector-indicator-icon', states: ['state']},+ {className: 'astryx-selector-check'},],},description: 'Dropdown selector for choosing from a list of options.',diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsxindex 42059b60a1..fb76216f52 100644--- a/packages/core/src/Selector/Selector.test.tsx+++ b/packages/core/src/Selector/Selector.test.tsx@@ -1640,3 +1640,80 @@ describe('Selector search affordances', () => {expect(trigger).toHaveAttribute('aria-expanded', 'true');});});++describe('Selector selected-marker theme target (selector-check)', () => {+ const openOptions = (): HTMLElement[] => screen.getAllByRole('option', h);++ it('renders the astryx-selector-check target on the selected row only', () => {+ render(+ <Selector+ label="Fruit"+ options={OPTIONS}+ value="Banana"+ onChange={() => {}}+ isDefaultOpen+ />,+ );+ const options = openOptions();+ const selected = options.find(+ o => o.getAttribute('aria-selected') === 'true',+ )!;+ const check = selected.querySelector('.astryx-selector-check');+ expect(check).toBeInTheDocument();+ // The target lands on the checkmark glyph itself, so a theme can restyle or+ // hide it (e.g. to compose its own selected indicator via renderOption).+ expect(check).toHaveClass('astryx-icon');++ const unselected = options.filter(+ o => o.getAttribute('aria-selected') !== 'true',+ );+ for (const row of unselected) {+ expect(row.querySelector('.astryx-selector-check')).not.toBeInTheDocument();+ }+ });++ it('renders the default checkmark byte-identically aside from the target class', () => {+ // The added target class is purely additive — it changes nothing about the+ // glyph's own color/size until a theme targets it.+ render(+ <Selector+ label="Fruit"+ options={OPTIONS}+ value="Banana"+ onChange={() => {}}+ isDefaultOpen+ />,+ );+ const selected = screen+ .getAllByRole('option', h)+ .find(o => o.getAttribute('aria-selected') === 'true')!;+ const check = selected.querySelector(+ '.astryx-selector-check',+ ) as HTMLElement;++ const {container: refContainer} = render(+ <Icon icon="check" size="sm" color="accent" />,+ );+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;+ const styleClasses = (el: HTMLElement) =>+ el.className+ .split(' ')+ .filter(c => c !== 'astryx-selector-check')+ .sort();+ expect(styleClasses(check)).toEqual(styleClasses(refIcon));+ });++ it('exposes selector-check so a theme can hide or restyle the marker', () => {+ const theme = defineTheme({+ name: 'selector-check-test',+ components: {+ 'selector-check': {+ base: {display: 'none'},+ },+ },+ });+ const css = generateThemeTestCSS(theme);+ expect(css).toContain('.astryx-selector-check {');+ expect(css).toContain('display: none');+ });+});diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsxindex dee927d5f5..ce73eb54a7 100644--- a/packages/core/src/Selector/Selector.tsx+++ b/packages/core/src/Selector/Selector.tsx@@ -1049,7 +1049,17 @@ export function Selector<T extends SelectorOptionType>(<DefaultOption option={item} />)}</span>- {isSelected && <Icon icon="check" size="sm" color="accent" />}+ {isSelected && (+ <Icon+ icon="check"+ size="sm"+ color="accent"+ // Stable theme target on the selected-row marker, so a theme can+ // restyle or hide it (e.g. to compose its own selected indicator+ // via renderOption) without a structural sibling selector.+ {...themeProps('selector-check')}+ />+ )}</div>);},