Skip to content

fix: force update to keep disable state work #612

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

Merged
merged 3 commits into from
Dec 25, 2024
Merged
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
14 changes: 7 additions & 7 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
}, [searchValue]);

// ========================= Disabled =========================
const disabledCacheRef = React.useRef<Map<string, boolean>>(new Map());
// Cache disabled states in React state to ensure re-render when cache updates
const [disabledCache, setDisabledCache] = React.useState<Map<string, boolean>>(() => new Map());

// Clear cache if `leftMaxCount` changed
React.useEffect(() => {
if (leftMaxCount) {
disabledCacheRef.current.clear();
setDisabledCache(new Map());
}
}, [leftMaxCount]);

function getDisabledWithCache(node: DataNode) {
const value = node[fieldNames.value];
if (!disabledCacheRef.current.has(value)) {
if (!disabledCache.has(value)) {
const entity = valueEntities.get(value);
const isLeaf = (entity.children || []).length === 0;

Expand All @@ -184,12 +184,12 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
);

const checkableChildrenCount = checkableChildren.length;
disabledCacheRef.current.set(value, checkableChildrenCount > leftMaxCount);
disabledCache.set(value, checkableChildrenCount > leftMaxCount);
} else {
disabledCacheRef.current.set(value, false);
disabledCache.set(value, false);
}
}
return disabledCacheRef.current.get(value);
return disabledCache.get(value);
}

const nodeDisabled = useEvent((node: DataNode) => {
Expand Down
Loading