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
5 changes: 5 additions & 0 deletions .changeset/tired-clowns-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vapor-ui/core': patch
---

propagate `invalid` state to indicator element
44 changes: 44 additions & 0 deletions packages/core/src/components/checkbox/checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ describe('Checkbox', () => {

expect(checkbox).not.toHaveAttribute('aria-invalid');
});

it('should propagate the invalid state to the indicator', async () => {
const rendered = render(
<Checkbox.Root id="checkbox" aria-label={LABEL_TEXT} invalid>
<Checkbox.IndicatorPrimitive data-testid="indicator" />
</Checkbox.Root>,
);
const indicator = rendered.getByTestId('indicator');

expect(indicator).toHaveAttribute('data-invalid');
});
});

describe('prop: indeterminate', () => {
Expand Down Expand Up @@ -217,6 +228,17 @@ describe('Checkbox', () => {

expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
});

it('should propagate the indeterminate state to the indicator', async () => {
const rendered = render(
<Checkbox.Root id="checkbox" aria-label={LABEL_TEXT} indeterminate>
<Checkbox.IndicatorPrimitive data-testid="indicator" />
</Checkbox.Root>,
);
const indicator = rendered.getByTestId('indicator');

expect(indicator).toHaveAttribute('data-indeterminate');
});
});

describe('prop: disabled', () => {
Expand Down Expand Up @@ -245,6 +267,17 @@ describe('Checkbox', () => {
expect(onCheckedChange).not.toHaveBeenCalled();
expect(checkbox).not.toBeChecked();
});

it('should propagate the disabled state to the indicator', async () => {
const rendered = render(
<Checkbox.Root id="checkbox" aria-label={LABEL_TEXT} disabled>
<Checkbox.IndicatorPrimitive data-testid="indicator" />
</Checkbox.Root>,
);
const indicator = rendered.getByTestId('indicator');

expect(indicator).toHaveAttribute('data-disabled');
});
});

describe('prop: readOnly', () => {
Expand Down Expand Up @@ -292,6 +325,17 @@ describe('Checkbox', () => {
await userEvent.tab();
expect(nextButton).toHaveFocus();
});

it('should propagate the readOnly state to the indicator', async () => {
const rendered = render(
<Checkbox.Root id="checkbox" aria-label={LABEL_TEXT} readOnly>
<Checkbox.IndicatorPrimitive data-testid="indicator" />
</Checkbox.Root>,
);
const indicator = rendered.getByTestId('indicator');

expect(indicator).toHaveAttribute('data-readonly');
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const CheckboxRoot = forwardRef<HTMLElement, CheckboxRoot.Props>((props,
},
});

return <CheckboxProvider value={{ size, indeterminate }}>{root}</CheckboxProvider>;
return <CheckboxProvider value={variantProps}>{root}</CheckboxProvider>;
});
CheckboxRoot.displayName = 'Checkbox.Root';

Expand Down
Loading