Skip to content

Commit

Permalink
fix(checkbox): checked set state is not last
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW committed May 25, 2024
1 parent 2c50854 commit afb854b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/checkbox/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
import React, { ReactElement, useCallback, useEffect, useMemo, useState } from 'react';
import classNames from 'classnames';
import isNumber from 'lodash/isNumber';
import useConfig from '../hooks/useConfig';
Expand Down Expand Up @@ -64,12 +64,13 @@ const CheckboxGroup = <T extends CheckboxGroupValue = CheckboxGroupValue>(props:
const [internalValue, setInternalValue] = useControlled(props, 'value', onChange);
const [localMax, setLocalMax] = useState(max);

const checkedSet = useMemo(() => {
const getCheckedSet = useCallback(() => {
if (!Array.isArray(internalValue)) {
return new Set<ItemType>([]);
}
return new Set<ItemType>([].concat(internalValue));
}, [internalValue]);
const checkedSet = useMemo(() => getCheckedSet(), [getCheckedSet]);

// 用于决定全选状态的属性
const indeterminate = useMemo(() => {
Expand Down Expand Up @@ -118,6 +119,7 @@ const CheckboxGroup = <T extends CheckboxGroupValue = CheckboxGroupValue>(props:
checkProps.onChange(checked, { e });
}

const checkedSet = getCheckedSet();
// 全选时的逻辑处理
if (checkProps.checkAll) {
checkedSet.clear();
Expand Down

0 comments on commit afb854b

Please sign in to comment.