Skip to content

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

TypeScript

fix(core): a disabled RadioListItem no longer runs a caller's onClick (#9120)

Parinith18b5260b6712
diff --git a/.changeset/radio-list-item-disabled-onclick.md b/.changeset/radio-list-item-disabled-onclick.md
new file mode 100644
index 0000000000..21cad60214
--- /dev/null
+++ b/.changeset/radio-list-item-disabled-onclick.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A disabled `RadioListItem` no longer runs a caller's `onClick` (`spec:AST-085` FR2). Before, a radio in a group disabled with a `disabledMessage` stays focusable through `aria-disabled` rather than native `disabled`, so the browser did not silence it and the handler still ran on a click on the radio, on Space, and on an arrow key onto it. It still refused to select. An enabled radio is unchanged: its `onClick` still runs.
+
+@parinith-web
diff --git a/packages/core/src/RadioList/RadioList.test.tsx b/packages/core/src/RadioList/RadioList.test.tsx
index 1fdabb7f2e..b4d85ec31d 100644
--- a/packages/core/src/RadioList/RadioList.test.tsx
+++ b/packages/core/src/RadioList/RadioList.test.tsx
@@ -499,6 +499,62 @@ describe('RadioList', () => {
fireEvent.click(pro);
expect(onChange).not.toHaveBeenCalled();
});
+
+ it('does not run a caller onClick while focusable-disabled', () => {
+ const onClick = vi.fn();
+ render(
+ <RadioList
+ label="Plan"
+ value="free"
+ onChange={() => {}}
+ isDisabled
+ disabledMessage="Upgrade your account to change plans">
+ <RadioListItem label="Free" value="free" onClick={onClick} />
+ <RadioListItem label="Pro" value="pro" onClick={onClick} />
+ </RadioList>,
+ );
+ fireEvent.click(screen.getByRole('radio', {name: 'Pro', hidden: true}));
+ fireEvent.click(screen.getByRole('radio', {name: 'Free', hidden: true}));
+ expect(onClick).not.toHaveBeenCalled();
+ });
+
+ it('does not run a caller onClick from the keyboard while focusable-disabled', async () => {
+ const user = userEvent.setup();
+ const onClick = vi.fn();
+ render(
+ <RadioList
+ label="Plan"
+ value="free"
+ onChange={() => {}}
+ isDisabled
+ disabledMessage="Upgrade your account to change plans">
+ <RadioListItem label="Free" value="free" onClick={onClick} />
+ <RadioListItem label="Pro" value="pro" onClick={onClick} />
+ </RadioList>,
+ );
+ await user.tab();
+ expect(
+ screen.getByRole('radio', {name: 'Free', hidden: true}),
+ ).toHaveFocus();
+ // Space activates the focused radio.
+ await user.keyboard(' ');
+ expect(onClick).not.toHaveBeenCalled();
+ // An arrow key moves onto the next radio, and the browser clicks it.
+ await user.keyboard('{ArrowDown}');
+ expect(onClick).not.toHaveBeenCalled();
+ });
+
+ it('still runs a caller onClick on an enabled radio', () => {
+ const onClick = vi.fn();
+ render(
+ <RadioList label="Plan" value="free" onChange={() => {}}>
+ <RadioListItem label="Free" value="free" />
+ <RadioListItem label="Pro" value="pro" onClick={onClick} />
+ </RadioList>,
+ );
+ fireEvent.click(screen.getByRole('radio', {name: 'Pro'}));
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
});
describe('form participation', () => {
it('submits the selected value under htmlName', () => {
diff --git a/packages/core/src/RadioList/RadioListItem.tsx b/packages/core/src/RadioList/RadioListItem.tsx
index 6c881b3d31..f64573055e 100644
--- a/packages/core/src/RadioList/RadioListItem.tsx
+++ b/packages/core/src/RadioList/RadioListItem.tsx
@@ -340,8 +340,11 @@ export function RadioListItem({
}}
// A consumer onClick rides on the radio input itself, so it fires for
// both direct control clicks and row-surface clicks the row delegates
- // to the input — the same routing CheckboxListItem uses.
- onClick={onClick}
+ // to the input — the same routing CheckboxListItem uses. A disabled
+ // radio that stays focusable (`aria-disabled`, not native `disabled`)
+ // is not silenced by the browser, so drop the handler here
+ // (`spec:AST-085` FR2), as CheckboxInput does.
+ onClick={isDisabled ? undefined : onClick}
// The radio names itself from the visible label element, which works
// for a rich label as well as a plain string. `aria-label` replaces
// that name rather than adding to it, so the two are mutually