Skip to content

Commit c098a17

Browse files
committed
fix: force update to keep disable state work
1 parent 2943745 commit c098a17

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/OptionList.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
162162
// ========================= Disabled =========================
163163
const disabledCacheRef = React.useRef<Map<string, boolean>>(new Map());
164164

165-
// Clear cache if `leftMaxCount` changed
165+
// Force update is needed since clearing cache alone doesn't trigger
166+
// a recalculation of node disabled states
167+
const [, setForceUpdate] = React.useState({});
168+
169+
// When leftMaxCount changes, we need to:
170+
// 1. Clear the disabled state cache
171+
// 2. Trigger a re-render to recalculate all node disabled states
172+
// This ensures parent nodes are properly disabled when max count is reached
166173
React.useEffect(() => {
167174
if (leftMaxCount) {
168175
disabledCacheRef.current.clear();
176+
setForceUpdate({});
169177
}
170178
}, [leftMaxCount]);
171179

0 commit comments

Comments
 (0)