From be286624f633ec20704e5ed16055a26c1b0a146f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com> Date: Mon, 19 Jun 2023 15:30:34 +0800 Subject: [PATCH] fix: close button should be hidden when closable is false (#666) * fix: close button should be hidden when closable is false * fix: close button should be hidden when closable is false --- src/util.ts | 6 ++++-- tests/index.test.tsx | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util.ts b/src/util.ts index 3bc37b94..86269a87 100644 --- a/src/util.ts +++ b/src/util.ts @@ -37,8 +37,10 @@ export function getRemovable( !editable || // Tabs cannot be removed when disabled disabled || - // If closable is not explicitly set to true, the remove button should be hidden when closeIcon is null or false - (closable !== true && (closeIcon === false || closeIcon === null)) + // closable is false + closable === false || + // If closable is undefined, the remove button should be hidden when closeIcon is null or false + (closable === undefined && (closeIcon === false || closeIcon === null)) ) { return false; } diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 796f8941..c3ba7e3e 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -482,6 +482,11 @@ describe('Tabs.Basic', () => { closable: true, children: 'Light', }, + { + key: 'light5', + closable: false, + children: 'Light', + }, ] as any, }), ); @@ -492,6 +497,7 @@ describe('Tabs.Basic', () => { expect(container.querySelector('[data-node-key="light2"]').querySelector('.rc-tabs-tab-remove')).toBeFalsy(); expect(container.querySelector('[data-node-key="light3"]').querySelector('.rc-tabs-tab-remove')).toBeTruthy(); expect(container.querySelector('[data-node-key="light4"]').querySelector('.rc-tabs-tab-remove')).toBeTruthy(); + expect(container.querySelector('[data-node-key="light5"]').querySelector('.rc-tabs-tab-remove')).toBeFalsy(); }); });