Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute checked has faulty types #3160

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .yarn/versions/1b559ed8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
releases:
"@radix-ui/react-checkbox": patch
"@radix-ui/react-radio-group": patch
"@radix-ui/react-switch": patch

declined:
- primitives
14 changes: 10 additions & 4 deletions packages/react/checkbox/src/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const Styled = () => (
);

export const Controlled = () => {
const [checked, setChecked] = React.useState<boolean | 'indeterminate'>(true);
const [checked, setChecked] = React.useState<boolean | 'indeterminate' | undefined>(true);

return (
<>
Expand All @@ -75,7 +75,9 @@ export const Controlled = () => {
};

export const Indeterminate = () => {
const [checked, setChecked] = React.useState<boolean | 'indeterminate'>('indeterminate');
const [checked, setChecked] = React.useState<boolean | 'indeterminate' | undefined>(
'indeterminate'
);

return (
<>
Expand All @@ -101,7 +103,9 @@ export const Indeterminate = () => {

export const WithinForm = () => {
const [data, setData] = React.useState({ optional: false, required: false, stopprop: false });
const [checked, setChecked] = React.useState<boolean | 'indeterminate'>('indeterminate');
const [checked, setChecked] = React.useState<boolean | 'indeterminate' | undefined>(
'indeterminate'
);

return (
<form
Expand Down Expand Up @@ -173,7 +177,9 @@ export const WithinForm = () => {
};

export const Animated = () => {
const [checked, setChecked] = React.useState<boolean | 'indeterminate'>('indeterminate');
const [checked, setChecked] = React.useState<boolean | 'indeterminate' | undefined>(
'indeterminate'
);

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CHECKBOX_NAME = 'Checkbox';
type ScopedProps<P> = P & { __scopeCheckbox?: Scope };
const [createCheckboxContext, createCheckboxScope] = createContextScope(CHECKBOX_NAME);

type CheckedState = boolean | 'indeterminate';
type CheckedState = boolean | 'indeterminate' | undefined;

type CheckboxContextValue = {
state: CheckedState;
Expand Down Expand Up @@ -105,7 +105,7 @@ const Checkbox = React.forwardRef<CheckboxElement, CheckboxProps>(
bubbles={!hasConsumerStoppedPropagationRef.current}
name={name}
value={value}
checked={checked}
checked={checked ? true : undefined}
required={required}
disabled={disabled}
// We transform because the input is absolutely positioned but we have
Expand Down
6 changes: 3 additions & 3 deletions packages/react/radio-group/src/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const [RadioProvider, useRadioContext] = createRadioContext<RadioContextValue>(R
type RadioElement = React.ElementRef<typeof Primitive.button>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface RadioProps extends PrimitiveButtonProps {
checked?: boolean;
checked?: boolean | undefined;
required?: boolean;
onCheck?(): void;
}
Expand Down Expand Up @@ -77,7 +77,7 @@ const Radio = React.forwardRef<RadioElement, RadioProps>(
bubbles={!hasConsumerStoppedPropagationRef.current}
name={name}
value={value}
checked={checked}
checked={checked ? true : undefined}
required={required}
disabled={disabled}
// We transform because the input is absolutely positioned but we have
Expand Down Expand Up @@ -132,7 +132,7 @@ RadioIndicator.displayName = INDICATOR_NAME;

type InputProps = React.ComponentPropsWithoutRef<'input'>;
interface BubbleInputProps extends Omit<InputProps, 'checked'> {
checked: boolean;
checked: boolean | undefined;
control: HTMLElement | null;
bubbles: boolean;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react/switch/src/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const [SwitchProvider, useSwitchContext] = createSwitchContext<SwitchContextValu
type SwitchElement = React.ElementRef<typeof Primitive.button>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface SwitchProps extends PrimitiveButtonProps {
checked?: boolean;
checked?: boolean | undefined;
defaultChecked?: boolean;
required?: boolean;
onCheckedChange?(checked: boolean): void;
Expand Down Expand Up @@ -84,7 +84,7 @@ const Switch = React.forwardRef<SwitchElement, SwitchProps>(
bubbles={!hasConsumerStoppedPropagationRef.current}
name={name}
value={value}
checked={checked}
checked={checked ? true : undefined}
required={required}
disabled={disabled}
// We transform because the input is absolutely positioned but we have
Expand Down Expand Up @@ -131,7 +131,7 @@ SwitchThumb.displayName = THUMB_NAME;

type InputProps = React.ComponentPropsWithoutRef<'input'>;
interface BubbleInputProps extends Omit<InputProps, 'checked'> {
checked: boolean;
checked: boolean | undefined;
control: HTMLElement | null;
bubbles: boolean;
}
Expand Down