diff --git a/packages/component-library-react/package.json b/packages/component-library-react/package.json index 65938b8e7de..848bf1b4166 100644 --- a/packages/component-library-react/package.json +++ b/packages/component-library-react/package.json @@ -74,7 +74,7 @@ "@utrecht/button-link-css": "workspace:*", "@utrecht/button-react": "workspace:*", "@utrecht/calendar-react": "workspace:*", - "@utrecht/checkbox-css": "workspace:*", + "@utrecht/checkbox-react": "workspace:*", "@utrecht/code-block-css": "workspace:*", "@utrecht/code-css": "workspace:*", "@utrecht/color-sample-css": "workspace:*", @@ -90,10 +90,11 @@ "@utrecht/emphasis-css": "workspace:*", "@utrecht/figure-css": "workspace:*", "@utrecht/focus-ring-css": "workspace:*", + "@utrecht/form-field-checkbox-react": "workspace:*", "@utrecht/form-field-react": "workspace:*", - "@utrecht/form-field-description-css": "workspace:*", - "@utrecht/form-field-error-message-css": "workspace:*", - "@utrecht/form-fieldset-css": "workspace:*", + "@utrecht/form-field-description-react": "workspace:*", + "@utrecht/form-field-error-message-react": "workspace:*", + "@utrecht/fieldset-react": "workspace:*", "@utrecht/form-label-react": "workspace:*", "@utrecht/form-toggle-css": "workspace:*", "@utrecht/heading-1-css": "workspace:*", @@ -134,7 +135,7 @@ "@utrecht/paragraph-css": "workspace:*", "@utrecht/pre-heading-css": "workspace:*", "@utrecht/preserve-data-css": "workspace:*", - "@utrecht/radio-button-css": "workspace:*", + "@utrecht/radio-button-react": "workspace:*", "@utrecht/rich-text-css": "workspace:*", "@utrecht/search-bar-css": "workspace:*", "@utrecht/select-css": "workspace:*", diff --git a/packages/component-library-react/src/Checkbox.test.tsx b/packages/component-library-react/src/Checkbox.test.tsx deleted file mode 100644 index 995025d077e..00000000000 --- a/packages/component-library-react/src/Checkbox.test.tsx +++ /dev/null @@ -1,375 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import { createRef } from 'react'; -import { Checkbox } from './Checkbox'; -import '@testing-library/jest-dom'; - -describe('Checkbox', () => { - it('renders a checkbox role element', () => { - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).toBeInTheDocument(); - }); - - it('renders an HTML input type=checkbox element', () => { - const { container } = render(); - - const checkbox = container.querySelector('input[type="checkbox"]:only-child'); - - expect(checkbox).toBeInTheDocument(); - }); - - it('displays as CSS inline-block element', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toBeVisible(); - expect(checkbox).toHaveStyle({ display: 'inline-block' }); - }); - - it('renders a design system BEM class name', () => { - const { container } = render(); - - const link = container.querySelector(':only-child'); - - expect(link).toHaveClass('utrecht-checkbox'); - }); - - it('can have a additional class name', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveClass('large'); - - expect(checkbox).toHaveClass('utrecht-checkbox'); - }); - describe('checked variant', () => { - it('is not checked by default', () => { - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).not.toBeChecked(); - }); - - it('omits non-essential checked attributes when not checked', () => { - const handleChange = () => {}; - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toHaveAttribute('aria-checked'); - - expect(checkbox).not.toHaveAttribute('checked'); - }); - - it('can have a checked state', () => { - const handleChange = () => {}; - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).toBeChecked(); - }); - - it('can have a defaultChecked state (in React)', () => { - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).toBeChecked(); - }); - - it('can have a checked state in CSS', () => { - const handleChange = () => {}; - const { container } = render(); - - const checkbox = container.querySelector(':checked'); - - expect(checkbox).toBeInTheDocument(); - }); - }); - - describe('invalid variant', () => { - it('renders a design system BEM modifier class name', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveClass('utrecht-checkbox--invalid'); - }); - - it('is not invalid by default', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toBeInvalid(); - }); - - it('omits non-essential invalid attributes when not invalid', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toHaveAttribute('aria-invalid'); - }); - - it('can have an invalid state', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toBeInvalid(); - }); - - it('can have a invalid state in CSS', () => { - const handleChange = () => {}; - const { container } = render(); - - const checkbox = container.querySelector(':invalid'); - - expect(checkbox).toBeInTheDocument(); - }); - }); - - describe('disabled variant', () => { - it('renders a design system BEM modifier class name', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveClass('utrecht-checkbox--disabled'); - }); - - it('is not disabled by default', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toBeDisabled(); - }); - - it('omits non-essential disabled attributes when not disabled', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toHaveAttribute('aria-disabled'); - - expect(checkbox).not.toHaveAttribute('disabled'); - }); - - it('can have a disabled state', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toBeDisabled(); - }); - - it('can have a disabled state in CSS', () => { - const { container } = render(); - - const checkbox = container.querySelector(':disabled'); - - expect(checkbox).toBeInTheDocument(); - }); - }); - - describe('required variant', () => { - it('renders a design system BEM modifier class name', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveClass('utrecht-checkbox--required'); - }); - - it('is not required by default', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toBeRequired(); - }); - - it('omits non-essential required attributes when not required', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toHaveAttribute('aria-required'); - - expect(checkbox).not.toHaveAttribute('required'); - }); - - it('can have a required state', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toBeRequired(); - }); - }); - - describe('inputRequired variant', () => { - it('renders a design system BEM modifier class name: utrecht-checkbox--required', () => { - const { container } = render(); - - const checkbox = container.querySelector('.utrecht-checkbox'); - - expect(checkbox).toHaveClass('utrecht-checkbox--required'); - }); - - it('is not required by default', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toBeRequired(); - }); - - it('omits non-essential required attributes when not required', () => { - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).not.toHaveAttribute('aria-required'); - expect(checkbox).not.toHaveAttribute('required'); - }); - - it('can have a required state', () => { - render(); - - const checkbox = screen.getByRole('checkbox'); - - expect(checkbox).toBeRequired(); - }); - - it('can have a required state in CSS', () => { - const { container } = render(); - - const checkbox = container.querySelector(':required'); - - expect(checkbox).toBeInTheDocument(); - }); - }); - - describe('indeterminate variant', () => { - it('renders a design system BEM modifier class name', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveClass('utrecht-checkbox--indeterminate'); - }); - - it('is not indeterminate by default', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).not.toHaveAttribute('aria-checked', 'mixed'); - }); - - it('can have a indeterminate state in the attribute `aria-checked` (for server side rendering)', () => { - const { container } = render(); - - const checkbox = container.querySelector(':only-child'); - - expect(checkbox).toHaveAttribute('aria-checked', 'mixed'); - }); - - it('can have a indeterminate state in the DOM property `indeterminate` (for client side rendering)', () => { - const { container } = render(); - - type FixedHTMLInput = HTMLInputElement & { indeterminate: boolean }; - - const checkbox = container.querySelector(':only-child') as FixedHTMLInput; - - expect(checkbox.indeterminate).toBe(true); - }); - - it('can have a indeterminate state in CSS', () => { - const { container } = render(); - - const checkbox = container.querySelector(':indeterminate'); - - expect(checkbox).toBeInTheDocument(); - }); - }); - - it('can be hidden', () => { - const { container } = render(