An open source design system that's fully customizable and agent ready
TypeScript
feat(multi-selector): themeable dropdown option target with states and size (#4628)
athzdab968f1d220
diff --git a/.changeset/multiselector-row-slots.md b/.changeset/multiselector-row-slots.mdnew file mode 100644index 0000000000..3d1d39be8a--- /dev/null+++ b/.changeset/multiselector-row-slots.md@@ -0,0 +1,12 @@+---+'@astryxdesign/core': patch+---++[feat] MultiSelector: dropdown option rows are themeable through a single+`multi-selector-option` target, carrying the row's `size` and its `select-all`,+`selected` and `disabled` states — so a theme can express "selected option at+large" or restyle just the Select All row. Row typography moved from the label+span onto the row, so one override reaches both the fallback label and+`renderOption` content; custom option content now inherits the row's font and+disabled color.+@athzdiff --git a/packages/core/src/MultiSelector/MultiSelector.doc.mjs b/packages/core/src/MultiSelector/MultiSelector.doc.mjsindex 682ff18478..bfb111b651 100644--- a/packages/core/src/MultiSelector/MultiSelector.doc.mjs+++ b/packages/core/src/MultiSelector/MultiSelector.doc.mjs@@ -31,6 +31,11 @@ export const docs = {className: 'astryx-multi-selector-indicator-icon',states: ['state'],},+ {+ className: 'astryx-multi-selector-option',+ visualProps: ['size'],+ states: ['select-all', 'selected', 'disabled'],+ },],},components: [diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsxindex 94a3b5fde3..5fa61627a7 100644--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx@@ -1959,3 +1959,120 @@ describe('MultiSelector disabled state theme target', () => {});});+describe('MultiSelector dropdown option theme target', () => {+ const ROW_OPTIONS = ['Apple', 'Banana', 'Orange'];++ it('renders astryx-multi-selector-option, with its size, on every dropdown row', async () => {+ const user = userEvent.setup();+ render(+ <MultiSelector+ label="Fruit"+ options={ROW_OPTIONS}+ value={[]}+ onChange={() => {}}+ size="lg"+ />,+ );+ await user.click(screen.getByRole('combobox'));+ const options = screen.getAllByRole('option', h);+ expect(options).toHaveLength(3);+ for (const option of options) {+ expect(option).toHaveClass('astryx-multi-selector-option');+ expect(option).toHaveClass('lg');+ expect(option).toHaveAttribute('data-size', 'lg');+ }+ });++ it('carries the selected and disabled states a theme keys on', async () => {+ const user = userEvent.setup();+ render(+ <MultiSelector+ label="Fruit"+ options={[+ {value: 'apple', label: 'Apple'},+ {value: 'banana', label: 'Banana'},+ {value: 'orange', label: 'Orange', disabled: true},+ ]}+ value={['apple']}+ onChange={() => {}}+ />,+ );+ await user.click(screen.getByRole('combobox'));+ const [selected, plain, disabled] = screen.getAllByRole('option', h);++ expect(selected).toHaveClass('selected');+ expect(selected).toHaveAttribute('data-selected', 'selected');+ expect(plain).not.toHaveClass('selected');+ expect(plain).not.toHaveAttribute('data-selected');++ expect(disabled).toHaveClass('disabled');+ expect(disabled).toHaveAttribute('data-disabled', 'disabled');+ expect(plain).not.toHaveAttribute('data-disabled');+ });++ it('marks the Select All row with the select-all state, not a separate target', async () => {+ const user = userEvent.setup();+ render(+ <MultiSelector+ label="Fruit"+ options={ROW_OPTIONS}+ value={[]}+ onChange={() => {}}+ hasSelectAll+ />,+ );+ await user.click(screen.getByRole('combobox'));++ const [selectAllRow, ...regularRows] = screen.getAllByRole('option', h);+ expect(selectAllRow).toHaveTextContent('Select all');+ expect(selectAllRow).toHaveClass('astryx-multi-selector-option');+ expect(selectAllRow).toHaveClass('select-all');+ expect(selectAllRow).toHaveAttribute('data-select-all', 'select-all');++ for (const row of regularRows) {+ expect(row).toHaveClass('astryx-multi-selector-option');+ expect(row).not.toHaveClass('select-all');+ expect(row).not.toHaveAttribute('data-select-all');+ }+ });++ it('keeps the row targetable when renderOption replaces the label', async () => {+ const user = userEvent.setup();+ render(+ <MultiSelector+ label="Fruit"+ options={[{value: 'apple', label: 'Apple'}]}+ value={[]}+ onChange={() => {}}+ renderOption={option => (+ <span data-testid="custom-row">{option.label}</span>+ )}+ />,+ );+ await user.click(screen.getByRole('combobox'));+ const option = screen.getAllByRole('option', h)[0];+ // The row owns the typography, so custom content inherits the same+ // treatment the fallback label gets — and one row override reaches both.+ expect(option).toHaveClass('astryx-multi-selector-option');+ expect(within(option).getByTestId('custom-row')).toHaveTextContent('Apple');+ });++ it('exposes the row target, its states and its size to defineTheme', () => {+ const theme = defineTheme({+ name: 'multi-selector-option-target-test',+ components: {+ 'multi-selector-option': {+ base: {borderRadius: '8px', fontWeight: '600'},+ selected: {backgroundColor: 'var(--color-background-muted)'},+ 'select-all': {fontWeight: '700'},+ 'size:lg': {borderRadius: '12px'},+ },+ },+ });+ const css = generateThemeTestCSS(theme);+ expect(css).toContain('.astryx-multi-selector-option {');+ expect(css).toContain('.astryx-multi-selector-option.selected');+ expect(css).toContain('.astryx-multi-selector-option.select-all');+ expect(css).toContain('.astryx-multi-selector-option.lg');+ });+});diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsxindex 8e485bade1..557a0bce15 100644--- a/packages/core/src/MultiSelector/MultiSelector.tsx+++ b/packages/core/src/MultiSelector/MultiSelector.tsx@@ -309,6 +309,14 @@ const styles = stylex.create({width: '100%',borderRadius: radiusVars['--radius-element'],cursor: 'pointer',+ // Row typography lives here, not on the label span, so a theme override on+ // the row target reaches both the fallback label and renderOption output+ // (a declaration on the span would win over the inherited row value).+ // Matches Selector, whose option row owns its typography the same way.+ fontFamily: typographyVars['--font-family-body'],+ fontSize: typeScaleVars['--text-label-size'],+ fontWeight: fontWeightVars['--font-weight-medium'],+ color: colorVars['--color-text-primary'],backgroundColor: 'transparent',border: 'none',outline: 'none',@@ -318,6 +326,7 @@ const styles = stylex.create({},itemDisabled: {opacity: 0.5,+ color: colorVars['--color-text-disabled'],cursor: 'not-allowed',},@@ -328,20 +337,15 @@ const styles = stylex.create({flexShrink: 0,},- // Label text for items (rendered outside checkbox for correct click behavior)+ // Label text for items (rendered outside checkbox for correct click+ // behavior). Typography is inherited from the row; this only handles+ // truncation.itemLabel: {- fontFamily: typographyVars['--font-family-body'],- fontSize: typeScaleVars['--text-label-size'],- fontWeight: fontWeightVars['--font-weight-medium'],- color: colorVars['--color-text-primary'],minWidth: 0,overflow: 'hidden',textOverflow: 'ellipsis',whiteSpace: 'nowrap',},- itemLabelDisabled: {- color: colorVars['--color-text-disabled'],- },// Empty stateemptyState: {@@ -1266,12 +1270,24 @@ export function MultiSelector<T extends MultiSelectorOptionType>({}}}onMouseEnter={() => onItemMouseEnter(item, flatIndex)}- {...stylex.props(- styles.item,- isSelectAll ? selectAllSizeStyles[size] : itemSizeStyles[size],- isSelectAll && styles.selectAllWrapper,- isHighlighted && styles.itemHighlighted,- item.disabled && styles.itemDisabled,+ {...mergeProps(+ // One target for every dropdown row, carrying the row's size and+ // runtime state so a theme can express "selected option at large"+ // or restyle just the Select All row (`.select-all`) without+ // reaching for structural selectors.+ themeProps('multi-selector-option', {+ size,+ 'select-all': isSelectAll ? 'select-all' : null,+ selected: isSelected ? 'selected' : null,+ disabled: item.disabled ? 'disabled' : null,+ }),+ stylex.props(+ styles.item,+ isSelectAll ? selectAllSizeStyles[size] : itemSizeStyles[size],+ isSelectAll && styles.selectAllWrapper,+ isHighlighted && styles.itemHighlighted,+ item.disabled && styles.itemDisabled,+ ),)}><div inert {...stylex.props(styles.checkboxDecorative)}><CheckboxInput@@ -1286,11 +1302,7 @@ export function MultiSelector<T extends MultiSelectorOptionType>({{renderOption && !isSelectAll ? (renderOption(item)) : (- <span- {...stylex.props(- styles.itemLabel,- item.disabled && styles.itemLabelDisabled,- )}>+ <span {...stylex.props(styles.itemLabel)}>{item.label ?? item.value}</span>)}@@ -1550,50 +1562,50 @@ export function MultiSelector<T extends MultiSelectorOptionType>({the two affordances stop sharing a node.*/}{showStatusIcon ? (- showStatusTooltip ? (- <button- ref={statusTooltip.ref}- type="button"- aria-label={t(STATUS_BUTTON_LABEL_KEY[status.type])}- aria-describedby={statusTooltip.describedBy}- onClick={e => e.stopPropagation()}- {...stylex.props(styles.statusButton)}>- <Icon- icon={STATUS_ICON_MAP[status.type]}- size="sm"- color={STATUS_ICON_COLOR_MAP[status.type]}- xstyle={styles.triggerIcon}- />- </button>- ) : (+ showStatusTooltip ? (+ <button+ ref={statusTooltip.ref}+ type="button"+ aria-label={t(STATUS_BUTTON_LABEL_KEY[status.type])}+ aria-describedby={statusTooltip.describedBy}+ onClick={e => e.stopPropagation()}+ {...stylex.props(styles.statusButton)}><Iconicon={STATUS_ICON_MAP[status.type]}size="sm"color={STATUS_ICON_COLOR_MAP[status.type]}xstyle={styles.triggerIcon}/>- )+ </button>) : (<Icon- icon="chevronDown"+ icon={STATUS_ICON_MAP[status.type]}size="sm"- color="secondary"- // The rotation rides on the glyph, alongside the box and color- // the wrapper used to provide, so one element carries the mark,- // its open/closed transform, and the theme target.- xstyle={[- styles.triggerIcon,- styles.triggerIconRotation,- popover.isOpen && styles.triggerIconOpen,- ]}- // Stable theme target on the chevron glyph itself, so a theme can- // restyle just this icon (color, size, hover) — and its- // open/closed state — via `defineTheme`. Same-element rules in- // @layer astryx-theme win over the icon's own base color/size,- // which a button-level target could not reach.- {...themeProps('multi-selector-indicator-icon', {- state: popover.isOpen ? 'expanded' : 'collapsed',- })}+ color={STATUS_ICON_COLOR_MAP[status.type]}+ xstyle={styles.triggerIcon}+ />+ )+ ) : (+ <Icon+ icon="chevronDown"+ size="sm"+ color="secondary"+ // The rotation rides on the glyph, alongside the box and color+ // the wrapper used to provide, so one element carries the mark,+ // its open/closed transform, and the theme target.+ xstyle={[+ styles.triggerIcon,+ styles.triggerIconRotation,+ popover.isOpen && styles.triggerIconOpen,+ ]}+ // Stable theme target on the chevron glyph itself, so a theme can+ // restyle just this icon (color, size, hover) — and its+ // open/closed state — via `defineTheme`. Same-element rules in+ // @layer astryx-theme win over the icon's own base color/size,+ // which a button-level target could not reach.+ {...themeProps('multi-selector-indicator-icon', {+ state: popover.isOpen ? 'expanded' : 'collapsed',+ })}/>)}</div>