From 3891e5e91fd81e1378e40d6384c056d1831acf14 Mon Sep 17 00:00:00 2001 From: atomiks Date: Wed, 10 Jun 2026 05:44:39 +1000 Subject: [PATCH] [checkbox] Ignore focus while disabled --- .../react/src/checkbox/root/CheckboxRoot.test.tsx | 14 ++++++++++++++ packages/react/src/checkbox/root/CheckboxRoot.tsx | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx index b9ef89a5d1b..08361f9b21e 100644 --- a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx +++ b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx @@ -1174,6 +1174,20 @@ describe('', () => { expect(button).not.toHaveAttribute('data-focused'); }); + it('does not set [data-focused] when disabled', async () => { + await render( + + + , + ); + + const button = screen.getByTestId('button'); + + fireEvent.focus(button); + + expect(button).not.toHaveAttribute('data-focused'); + }); + it('[data-invalid]', async () => { await render( diff --git a/packages/react/src/checkbox/root/CheckboxRoot.tsx b/packages/react/src/checkbox/root/CheckboxRoot.tsx index cdac2a0da5c..92d9a3ba28a 100644 --- a/packages/react/src/checkbox/root/CheckboxRoot.tsx +++ b/packages/react/src/checkbox/root/CheckboxRoot.tsx @@ -317,7 +317,9 @@ export const CheckboxRoot = React.forwardRef(function CheckboxRoot( 'aria-labelledby': ariaLabelledBy, [PARENT_CHECKBOX as string]: parent ? '' : undefined, onFocus() { - setFocused(true); + if (!disabled) { + setFocused(true); + } }, onBlur() { const inputEl = inputRef.current;