Skip to content

Commit 1337e36

Browse files
authored
feat(Tabs): add the option to disable the Add button (#11872)
* feat(Tabs): add the option to disable the Add button The button in the Tabs component for adding new tabs can now get disabled if the isAddButtonDisabeled prop is set. * fix(Tabs): fix switched descriptions of addButtonAriaLabel and isAddButtonDisabled
1 parent 96fdb62 commit 1337e36

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

packages/react-core/src/components/Tabs/Tabs.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export interface TabsProps
6363
addButtonAriaLabel?: string;
6464
/** Uniquely identifies the tabs */
6565
id?: string;
66+
/** Flag indicating that the add button is disabled when onAdd is passed in */
67+
isAddButtonDisabled?: boolean;
6668
/** Enables the filled tab list layout */
6769
isFilled?: boolean;
6870
/** Enables subtab tab styling */
@@ -464,6 +466,7 @@ class Tabs extends Component<TabsProps, TabsState> {
464466
activeKey,
465467
defaultActiveKey,
466468
id,
469+
isAddButtonDisabled,
467470
isFilled,
468471
isSubtab,
469472
isVertical,
@@ -631,6 +634,7 @@ class Tabs extends Component<TabsProps, TabsState> {
631634
aria-label={addButtonAriaLabel || 'Add tab'}
632635
onClick={onAdd}
633636
icon={<PlusIcon />}
637+
isDisabled={isAddButtonDisabled}
634638
/>
635639
</span>
636640
)}

packages/react-core/src/components/Tabs/__tests__/Tabs.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,25 @@ test('should not render scroll buttons when isVertical is true', () => {
492492
expect(screen.queryByLabelText('Scroll left')).not.toBeInTheDocument();
493493
expect(screen.queryByLabelText('Scroll right')).not.toBeInTheDocument();
494494
});
495+
496+
test('should render a disabled add button', () => {
497+
render(
498+
<Tabs onAdd={jest.fn()} addButtonAriaLabel="add-label" isAddButtonDisabled={true}>
499+
<div>Tab content</div>
500+
</Tabs>
501+
);
502+
503+
const addButton = screen.getByLabelText('add-label');
504+
expect(addButton).toBeDisabled();
505+
});
506+
507+
test('should render an enabled add button', () => {
508+
render(
509+
<Tabs onAdd={jest.fn()} addButtonAriaLabel="add-label" isAddButtonDisabled={false}>
510+
<div>Tab content</div>
511+
</Tabs>
512+
);
513+
514+
const addButton = screen.getByLabelText('add-label');
515+
expect(addButton).not.toBeDisabled();
516+
});

0 commit comments

Comments
 (0)