From 72e0bdbd112c86af53d4fa4118fb1376503c7340 Mon Sep 17 00:00:00 2001 From: Janry Date: Wed, 19 Jan 2022 20:52:58 +0800 Subject: [PATCH] fix(antd): fix ArrayTabs auto switch activeKey (#2774) --- packages/antd/src/array-tabs/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/antd/src/array-tabs/index.tsx b/packages/antd/src/array-tabs/index.tsx index 5675c96d01b..3f6e95a25e4 100644 --- a/packages/antd/src/array-tabs/index.tsx +++ b/packages/antd/src/array-tabs/index.tsx @@ -25,20 +25,16 @@ export const ArrayTabs: React.FC = observer((props) => { } setActiveKey(`tab-${id}`) } else if (type == 'remove') { - const index = targetKey.match(/-(\d+)/)?.[1] - field.remove(Number(index)) - if (activeKey === targetKey) { + const index = Number(targetKey.match(/-(\d+)/)?.[1]) + if (index - 1 > -1) { setActiveKey(`tab-${index - 1}`) } + field.remove(index) } } const badgedTab = (index: number) => { const tab = `${field.title || 'Untitled'} ${index + 1}` - const path = field.address.concat(index) - const errors = field.form.queryFeedbacks({ - type: 'error', - address: `${path}.**`, - }) + const errors = field.errors if (errors.length) { return ( @@ -64,7 +60,12 @@ export const ArrayTabs: React.FC = observer((props) => { : schema.items const key = `tab-${index}` return ( - + )