Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/react/src/checkbox/root/CheckboxRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,20 @@ describe('<Checkbox.Root />', () => {
expect(button).not.toHaveAttribute('data-focused');
});

it('does not set [data-focused] when disabled', async () => {
await render(
<Field.Root>
<Checkbox.Root disabled data-testid="button" />
</Field.Root>,
);

const button = screen.getByTestId('button');

fireEvent.focus(button);

expect(button).not.toHaveAttribute('data-focused');
});

it('[data-invalid]', async () => {
await render(
<Field.Root invalid>
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/checkbox/root/CheckboxRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading