Skip to content

Commit 747447c

Browse files
authored
[checkbox] Ignore data-focused Field attribute when disabled (#4998)
1 parent a48dc6d commit 747447c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/react/src/checkbox/root/CheckboxRoot.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,20 @@ describe('<Checkbox.Root />', () => {
11741174
expect(button).not.toHaveAttribute('data-focused');
11751175
});
11761176

1177+
it('does not set [data-focused] when disabled', async () => {
1178+
await render(
1179+
<Field.Root>
1180+
<Checkbox.Root disabled data-testid="button" />
1181+
</Field.Root>,
1182+
);
1183+
1184+
const button = screen.getByTestId('button');
1185+
1186+
fireEvent.focus(button);
1187+
1188+
expect(button).not.toHaveAttribute('data-focused');
1189+
});
1190+
11771191
it('[data-invalid]', async () => {
11781192
await render(
11791193
<Field.Root invalid>

packages/react/src/checkbox/root/CheckboxRoot.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ export const CheckboxRoot = React.forwardRef(function CheckboxRoot(
317317
'aria-labelledby': ariaLabelledBy,
318318
[PARENT_CHECKBOX as string]: parent ? '' : undefined,
319319
onFocus() {
320-
setFocused(true);
320+
if (!disabled) {
321+
setFocused(true);
322+
}
321323
},
322324
onBlur() {
323325
const inputEl = inputRef.current;

0 commit comments

Comments
 (0)