Skip to content

Commit

Permalink
fix(antd): fix ArrayCollapse collapsed and expanded errors (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lind-pro authored May 26, 2021
1 parent 2ad4322 commit 12275cf
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/antd/src/array-collapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
)
}

const [activeKeys, setActiveKeys] = useState<Array<string | number>>(
Array.from({ length: props?.defaultOpenPanelCount || 1 }).map((_, i) => i)
const [activeKeys, setActiveKeys] = useState<Array<string>>(
Array.from({ length: props?.defaultOpenPanelCount || 1 }).map((_, i) =>
String(i)
)
)

const renderItems = () => {
Expand Down Expand Up @@ -177,7 +179,13 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
)
}
return (
<ArrayBase onAdd={(index) => setActiveKeys(activeKeys.concat(index))}>
<ArrayBase
onAdd={(index) => {
if (!activeKeys.includes(String(index))) {
setActiveKeys(activeKeys.concat(String(index)))
}
}}
>
{renderEmpty()}
{renderItems()}
{renderAddition()}
Expand Down

0 comments on commit 12275cf

Please sign in to comment.