Skip to content

Commit

Permalink
chore(form): removed deprecated implementation in useIndeterminateChe…
Browse files Browse the repository at this point in the history
…cked

BREAKING CHANGE: The second argument for `useIndeterminateChecked` is now an object of options
  • Loading branch information
mlaursen committed Aug 12, 2021
1 parent f5b652c commit 6b7871f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default function IndeterminateCheckboxes(): ReactElement {
rootProps,
// checkedValues,
// setCheckedValues,
} = useIndeterminateChecked(condiments, ["Sprouts"]);
} = useIndeterminateChecked(condiments, {
defaultCheckedValues: ["Sprouts"],
});

return (
<Fieldset legend="Sandwich Condiments" unstyled={false}>
Expand Down
7 changes: 3 additions & 4 deletions packages/form/src/__tests__/useIndeterminateChecked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,10 @@ describe("useIndeterminateChecked", () => {
const onChange = jest.fn();
const defaultCheckedValues = ["b"] as const;
function Test() {
const { rootProps, getProps } = useIndeterminateChecked(
values,
const { rootProps, getProps } = useIndeterminateChecked(values, {
onChange,
defaultCheckedValues,
onChange
);
});
return (
<>
<Checkbox id="checkbox-1" label="Toggle All" {...rootProps} />
Expand Down
32 changes: 5 additions & 27 deletions packages/form/src/useIndeterminateChecked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ export interface CombinedIndeterminateCheckedHookReturnValue<V extends string>
getProps(value: V): ProvidedCombinedIndeterminateControlledProps<V>;
}

/**
* @deprecated \@since 2.8.5 Use the implementation that accepts options as the
* second argument.
*/
export function useIndeterminateChecked<V extends string>(
values: readonly V[],
defaultCheckedValues: Initializer<V>,
onChange?: OnChange<V>
): OnChangeReturnValue<V>;
export function useIndeterminateChecked<V extends string>(
values: readonly V[],
options?: IndeterminateCheckedHookOptions<V> & { menu?: false }
Expand Down Expand Up @@ -339,25 +330,12 @@ export function useIndeterminateChecked<V extends string>(
*/
export function useIndeterminateChecked<V extends string>(
values: readonly V[],
defaultOrOptions?: IndeterminateCheckedHookOptions<V> | Initializer<V>,
optionalOnChange?: OnChange<V>
{
menu = false,
onChange: propOnChange,
defaultCheckedValues = [],
}: IndeterminateCheckedHookOptions<V> = {}
): CombinedIndeterminateCheckedHookReturnValue<V> {
let menu = false;
let propOnChange: OnChange<V> | undefined = optionalOnChange;
let defaultCheckedValues: Initializer<V>;
if (
typeof defaultOrOptions === "undefined" ||
!("length" in defaultOrOptions)
) {
({
menu = false,
onChange: propOnChange,
defaultCheckedValues = [],
} = defaultOrOptions ?? {});
} else {
defaultCheckedValues = defaultOrOptions;
}

const [checkedValues, setCheckedValues] =
useState<readonly V[]>(defaultCheckedValues);
const checked = checkedValues.length > 0;
Expand Down

0 comments on commit 6b7871f

Please sign in to comment.