Skip to content

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

TypeScript

feat(Selector): add selector-option-row theme target on the option row (#5179)

freddymeta1fdecb1ae6c3
diff --git a/.changeset/selector-option-row-theme-target.md b/.changeset/selector-option-row-theme-target.md
new file mode 100644
index 0000000000..3358257460
--- /dev/null
+++ b/.changeset/selector-option-row-theme-target.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Selector: add the `selector-option-row` theme target on the dropdown option row, carrying `size` plus `selected`/`disabled` state — so a theme can restyle row padding and density directly (mirroring `multi-selector-option`), instead of reaching the bare `role="option"` element with a structural selector.
+
+@freddymeta
diff --git a/apps/docsite/src/components/docs/ReferenceDocView.tsx b/apps/docsite/src/components/docs/ReferenceDocView.tsx
index c7bf76ed2b..e719feb805 100644
--- a/apps/docsite/src/components/docs/ReferenceDocView.tsx
+++ b/apps/docsite/src/components/docs/ReferenceDocView.tsx
@@ -176,7 +176,9 @@ export function ReferenceDocView({
[];
for (let j = blockIndex; j < section.content.length; j++) {
const run = section.content[j];
- if (!isGuidanceList(run)) {break;}
+ if (!isGuidanceList(run)) {
+ break;
+ }
for (const item of run.items ?? []) {
items.push({
guidance: run.style === 'do',
diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md
index 628121736f..15c8115f9f 100644
--- a/packages/core/CHANGELOG.md
+++ b/packages/core/CHANGELOG.md
@@ -10,6 +10,7 @@
Nothing changes unless you ask for it: `InternationalizationProvider` still defaults to English, and the catalogs are loaded through the existing `./locales/*.json` export. An app that already passes a `locale` now gets translated component strings where it previously fell back to English.
The catalogs come from Crowdin and are refreshed nightly (#5186), so a translation landing upstream reaches a release without anyone opening a PR by hand.
+
- DateRangeInput / Calendar: add `maxRangeSpan` and `minRangeSpan` to constrain the size of a selected range. Once a start date is picked, days outside the allowed window are disabled — e.g. `maxRangeSpan={7}` keeps the range within a 7-day window of the start (#5145).
- FormLayout: add `defaultOptionality` — set a form-wide default (`'optional'` or `'required'`) so only the exception carries a visible indicator. Under `'optional'` only `isRequired` fields show one; under `'required'` only `isOptional` fields do; a field that restates the default shows nothing. Under `'required'` the unmarked fields also expose `aria-required` so screen readers match what sighted users see — resolved on `aria-required` only, never the native `required` attribute. Unset keeps today's per-field behavior (#4791).
- Add `astryx-input-clear-button` theme target on the shared clear button wrapper. Themes can now control the clear button's height and hover independently of other ghost buttons — for example suppressing the hover fill or matching a different element size scale (#5093).
diff --git a/packages/core/src/BottomSheet/BottomSheet.test.tsx b/packages/core/src/BottomSheet/BottomSheet.test.tsx
index 9d64e4e750..dcbf14dc84 100644
--- a/packages/core/src/BottomSheet/BottomSheet.test.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.test.tsx
@@ -2272,11 +2272,18 @@ describe('BottomSheet', () => {
);
const sheet = getSheet();
const computed = window.getComputedStyle(sheet);
- expect(computed.getPropertyValue('--container-padding-inline-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-inline-end')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-end')).toBe('0px');
+ expect(
+ computed.getPropertyValue('--container-padding-inline-start'),
+ ).toBe('0px');
+ expect(computed.getPropertyValue('--container-padding-inline-end')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-start')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-end')).toBe(
+ '0px',
+ );
});
});
});
-
diff --git a/packages/core/src/Dialog/Dialog.test.tsx b/packages/core/src/Dialog/Dialog.test.tsx
index 8effe58e73..b4572ce6dc 100644
--- a/packages/core/src/Dialog/Dialog.test.tsx
+++ b/packages/core/src/Dialog/Dialog.test.tsx
@@ -471,10 +471,18 @@ describe('Dialog', () => {
);
const dialog = screen.getByRole('dialog');
const computed = window.getComputedStyle(dialog);
- expect(computed.getPropertyValue('--container-padding-inline-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-inline-end')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-end')).toBe('0px');
+ expect(
+ computed.getPropertyValue('--container-padding-inline-start'),
+ ).toBe('0px');
+ expect(computed.getPropertyValue('--container-padding-inline-end')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-start')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-end')).toBe(
+ '0px',
+ );
});
});
});
diff --git a/packages/core/src/Selector/Selector.doc.mjs b/packages/core/src/Selector/Selector.doc.mjs
index 31ef527ce4..b16bff127f 100644
--- a/packages/core/src/Selector/Selector.doc.mjs
+++ b/packages/core/src/Selector/Selector.doc.mjs
@@ -27,6 +27,11 @@ export const docs = {
states: ['disabled'],
},
{className: 'astryx-selector-option'},
+ {
+ className: 'astryx-selector-option-row',
+ visualProps: ['size'],
+ states: ['selected', 'disabled'],
+ },
{className: 'astryx-selector-search'},
{className: 'astryx-selector-section-heading'},
{className: 'astryx-selector-empty-state'},
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index 3d2916a9dd..d6040129f9 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -2997,6 +2997,124 @@ describe('Selector popup theme target', () => {
);
});
+describe('Selector option-row theme target', () => {
+ const ROW_OPTIONS = ['Apple', 'Banana', 'Orange'];
+
+ it('renders astryx-selector-option-row, with its size, on every dropdown row', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ 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-selector-option-row');
+ expect(option).toHaveClass('lg');
+ expect(option).toHaveAttribute('data-size', 'lg');
+ }
+ });
+
+ it('reflects the selected state on the row target', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ label="Fruit"
+ options={ROW_OPTIONS}
+ value="Banana"
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ const selected = screen.getByRole('option', {name: 'Banana', ...h});
+ expect(selected).toHaveClass('astryx-selector-option-row');
+ expect(selected).toHaveAttribute('data-selected', 'selected');
+ });
+
+ it('leaves the state attributes off an unselected, enabled row', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ label="Fruit"
+ options={ROW_OPTIONS}
+ value="Banana"
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ const plain = screen.getByRole('option', {name: 'Apple', ...h});
+ expect(plain).toHaveClass('astryx-selector-option-row');
+ // themeProps emits the data-* only when the state is truthy, so a theme's
+ // `.selected` / `.disabled` rules never touch a plain row.
+ expect(plain).not.toHaveAttribute('data-selected');
+ expect(plain).not.toHaveAttribute('data-disabled');
+ });
+
+ it('reflects the disabled state on the row target', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ label="Fruit"
+ options={[{value: 'Apple', disabled: true}, 'Banana']}
+ value=""
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ const disabled = screen.getByRole('option', {name: 'Apple', ...h});
+ expect(disabled).toHaveClass('astryx-selector-option-row');
+ expect(disabled).toHaveAttribute('data-disabled', 'disabled');
+ });
+
+ it('keeps the row target when renderOption replaces the content', async () => {
+ const user = userEvent.setup();
+ render(
+ <Selector
+ label="Fruit"
+ options={ROW_OPTIONS}
+ value=""
+ onChange={() => {}}
+ renderOption={option => (
+ <span data-testid="custom-row">{option.label ?? option.value}</span>
+ )}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ const option = screen.getAllByRole('option', h)[0];
+ // The row owns the padding/density, so custom content is inset the same as
+ // the default row — one row override reaches both.
+ expect(option).toHaveClass('astryx-selector-option-row');
+ expect(within(option).getByTestId('custom-row')).toHaveTextContent('Apple');
+ });
+
+ it('exposes the row target, its states and its size to defineTheme', () => {
+ // jsdom cannot resolve the @layer cascade, so the generated CSS is what
+ // proves a theme can reach the row (padding, state, per-size density).
+ const theme = defineTheme({
+ name: 'selector-option-row-target-test',
+ components: {
+ 'selector-option-row': {
+ base: {padding: 'var(--spacing-2)', borderRadius: '8px'},
+ selected: {backgroundColor: 'var(--color-background-muted)'},
+ disabled: {opacity: '0.5'},
+ 'size:md': {padding: 'var(--spacing-2)'},
+ },
+ },
+ });
+ const css = generateThemeTestCSS(theme);
+ expect(css).toContain('.astryx-selector-option-row {');
+ expect(css).toContain('.astryx-selector-option-row.selected');
+ expect(css).toContain('.astryx-selector-option-row.disabled');
+ expect(css).toContain('.astryx-selector-option-row.md');
+ });
+});
+
describe('Selector option descriptions and trigger value', () => {
const LOCK = <span data-testid="lock-glyph" />;
const GLOBE = <span data-testid="globe-glyph" />;
diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsx
index 13912ba6ac..6a713ce54a 100644
--- a/packages/core/src/Selector/Selector.tsx
+++ b/packages/core/src/Selector/Selector.tsx
@@ -1257,12 +1257,27 @@ export function Selector<T extends SelectorOptionType>(
aria-disabled={item.disabled}
onClick={() => onItemSelect(item)}
onMouseEnter={() => onItemMouseEnter(item, flatIndex)}
- {...stylex.props(
- styles.item,
- itemSizeStyles[size],
- isHighlighted && styles.itemHighlighted,
- isSelected && styles.itemSelected,
- item.disabled && styles.itemDisabled,
+ {...mergeProps(
+ // Stable theme target on the option row itself, mirroring
+ // `multi-selector-option`: it carries the row's size and runtime
+ // state so a theme can express "selected option at large" or
+ // restyle a given row density without structural selectors. The
+ // row's padding is split across a base and a per-size override (the
+ // default `md` trims the block axis), so `size` is what a theme
+ // needs to reach it. Named `-option-row` because `selector-option`
+ // is the public SelectorOption content primitive, not this row.
+ themeProps('selector-option-row', {
+ size,
+ selected: isSelected ? 'selected' : null,
+ disabled: item.disabled ? 'disabled' : null,
+ }),
+ stylex.props(
+ styles.item,
+ itemSizeStyles[size],
+ isHighlighted && styles.itemHighlighted,
+ isSelected && styles.itemSelected,
+ item.disabled && styles.itemDisabled,
+ ),
)}>
{content}
</div>
diff --git a/packages/lab/src/Drawer/Drawer.test.tsx b/packages/lab/src/Drawer/Drawer.test.tsx
index 6fb0933cc7..6dfb9d4046 100644
--- a/packages/lab/src/Drawer/Drawer.test.tsx
+++ b/packages/lab/src/Drawer/Drawer.test.tsx
@@ -585,11 +585,18 @@ describe('Drawer', () => {
);
const dialog = screen.getByRole('dialog');
const computed = window.getComputedStyle(dialog);
- expect(computed.getPropertyValue('--container-padding-inline-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-inline-end')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-start')).toBe('0px');
- expect(computed.getPropertyValue('--container-padding-block-end')).toBe('0px');
+ expect(
+ computed.getPropertyValue('--container-padding-inline-start'),
+ ).toBe('0px');
+ expect(computed.getPropertyValue('--container-padding-inline-end')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-start')).toBe(
+ '0px',
+ );
+ expect(computed.getPropertyValue('--container-padding-block-end')).toBe(
+ '0px',
+ );
});
});
});
-
diff --git a/packages/lab/src/ListInput/ListInput.tsx b/packages/lab/src/ListInput/ListInput.tsx
index ce7b2e4ab4..72522245aa 100644
--- a/packages/lab/src/ListInput/ListInput.tsx
+++ b/packages/lab/src/ListInput/ListInput.tsx
@@ -1640,10 +1640,9 @@ export function ListInput<T>({
})}
tooltip={
isDisabled || isLoading
- ? t(
- '@astryx.listInput.removeUnavailable',
- {itemName},
- )
+ ? t('@astryx.listInput.removeUnavailable', {
+ itemName,
+ })
: t('@astryx.listInput.removeItem', {
itemName,
position: index + 1,