Skip to content

Commit 7f69a71

Browse files
committed
fix(form): useIndeterminateChecked correctly uses readonly prefix
1 parent 6ed2b65 commit 7f69a71

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/form/src/useIndeterminateChecked.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Dispatch, SetStateAction, useState } from "react";
77
export interface ProvidedIndeterminateCheckboxProps {
88
"aria-checked"?: "mixed";
99
checked: boolean;
10-
onChange: () => void;
10+
onChange(): void;
1111
indeterminate: boolean;
1212
}
1313

@@ -20,7 +20,7 @@ export interface ProvidedIndeterminateControlledCheckboxProps<
2020
> {
2121
value: T;
2222
checked: boolean;
23-
onChange: () => void;
23+
onChange(): void;
2424
}
2525

2626
/**
@@ -34,8 +34,8 @@ export type GetIndeterminateControlledCheckboxProps<T extends string> = (
3434
export interface IndeterminateCheckedReturnValue<T extends string> {
3535
getProps: GetIndeterminateControlledCheckboxProps<T>;
3636
rootProps: ProvidedIndeterminateCheckboxProps;
37-
checkedValues: T[];
38-
setCheckedValues: Dispatch<SetStateAction<T[]>>;
37+
checkedValues: readonly T[];
38+
setCheckedValues: Dispatch<SetStateAction<readonly T[]>>;
3939
}
4040

4141
/**
@@ -48,8 +48,8 @@ export interface IndeterminateCheckedReturnValue<T extends string> {
4848
* #### Simple value list with labels lookup:
4949
*
5050
* ```tsx
51-
* const values = ["a", "b", "c", "d"];
52-
* const LABELS = { a: "Label 1", b: "Label 2", c: "Label 3", d: "Label 4" };
51+
* const values = ["a", "b", "c", "d"] as const;
52+
* const LABELS = { a: "Label 1", b: "Label 2", c: "Label 3", d: "Label 4" } as const;
5353
* const { getProps, rootProps } = useIndeterminateChecked(values);
5454
*
5555
* return (
@@ -127,15 +127,16 @@ export interface IndeterminateCheckedReturnValue<T extends string> {
127127
* the list of values can be changed from external sources as well.
128128
*/
129129
export function useIndeterminateChecked<T extends string>(
130-
values: T[],
131-
defaultCheckedValues: T[] | (() => T[]) = [],
132-
onChange?: (checkedValues: T[]) => void
130+
values: readonly T[],
131+
defaultCheckedValues: readonly T[] | (() => readonly T[]) = [],
132+
onChange?: (checkedValues: readonly T[]) => void
133133
): IndeterminateCheckedReturnValue<T> {
134-
const [checkedValues, setCheckedValues] = useState<T[]>(defaultCheckedValues);
134+
const [checkedValues, setCheckedValues] =
135+
useState<readonly T[]>(defaultCheckedValues);
135136
const checked = checkedValues.length > 0;
136137
const indeterminate = checked && checkedValues.length < values.length;
137138

138-
const updateCheckedValues = (values: T[]): void => {
139+
const updateCheckedValues = (values: readonly T[]): void => {
139140
if (onChange) {
140141
onChange(values);
141142
}

0 commit comments

Comments
 (0)