-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathTabs.tsx
More file actions
694 lines (648 loc) · 27.5 KB
/
Tabs.tsx
File metadata and controls
694 lines (648 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
import { Children, Component, createRef, isValidElement } from 'react';
import styles from '@patternfly/react-styles/css/components/Tabs/tabs';
import { css } from '@patternfly/react-styles';
import { PickOptional } from '../../helpers/typeUtils';
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon';
import {
isElementInView,
formatBreakpointMods,
getLanguageDirection,
getInlineStartProperty
} from '../../helpers/util';
import { TabContent } from './TabContent';
import { TabProps } from './Tab';
import { TabsContextProvider } from './TabsContext';
import { OverflowTab, HorizontalOverflowPopperProps } from './OverflowTab';
import { Button } from '../Button';
import { getOUIAProps, OUIAProps, canUseDOM } from '../../helpers';
import { SSRSafeIds } from '../../helpers/SSRSafeIds/SSRSafeIds';
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
import linkAccentLength from '@patternfly/react-tokens/dist/esm/c_tabs_link_accent_length';
import linkAccentStart from '@patternfly/react-tokens/dist/esm/c_tabs_link_accent_start';
export enum TabsComponent {
div = 'div',
nav = 'nav'
}
export interface HorizontalOverflowObject {
/** Flag which shows the count of overflowing tabs when enabled */
showTabCount?: boolean;
/** The text which displays when an overflowing tab isn't selected */
defaultTitleText?: string;
/** The aria label applied to the button which toggles the tab overflow menu */
toggleAriaLabel?: string;
/** Additional props to spread to the popper menu. */
popperProps?: HorizontalOverflowPopperProps;
}
type TabElement = React.ReactElement<TabProps, React.JSXElementConstructor<TabProps>>;
type TabsChild = TabElement | boolean | null | undefined;
export interface TabsProps
extends Omit<React.HTMLProps<HTMLElement | HTMLDivElement>, 'onSelect' | 'onToggle'>, OUIAProps {
/** Content rendered inside the tabs component. Only `Tab` components or expressions resulting in a falsy value are allowed here. */
children: TabsChild | TabsChild[];
/** Additional classes added to the tabs */
className?: string;
/** Tabs background color variant */
variant?: 'default' | 'secondary';
/** The index of the active tab */
activeKey?: number | string;
/** The index of the default active tab. Set this for uncontrolled Tabs */
defaultActiveKey?: number | string;
/** Callback to handle tab selection */
onSelect?: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: TabProps['eventKey']) => void;
/** Callback to handle tab closing and adds a basic close button to all tabs. This is overridden by the tab actions property. */
onClose?: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: TabProps['eventKey']) => void;
/** Callback for the add button. Passing this property inserts the add button */
onAdd?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
/** Aria-label for the add button */
addButtonAriaLabel?: string;
/** A readable string to create an accessible name for the tablist element. This can be used to differentiate multiple tablists on a page, and should be used for subtabs. */
tabListAriaLabel?: string;
/** Id of an element that provides an accessible name for the tablist. Use this when a visible label already exists on the page. */
tabListAriaLabelledBy?: string;
/** Uniquely identifies the tabs */
id?: string;
/** Flag indicating that the add button is disabled when onAdd is passed in */
isAddButtonDisabled?: boolean;
/** Enables the filled tab list layout */
isFilled?: boolean;
/** Enables subtab tab styling */
isSubtab?: boolean;
/** @beta Enables horizontal nav tab styling */
isNav?: boolean;
/** Enables box styling to the tab component */
isBox?: boolean;
/** Enables vertical tab styling */
isVertical?: boolean;
/** Disables border bottom tab styling on tabs. Defaults to false. To remove the bottom border, set this prop to true. */
hasNoBorderBottom?: boolean;
/** @deprecated Please use backScrollAriaLabel. Aria-label for the left scroll button */
leftScrollAriaLabel?: string;
/** @deprecated Please use forwardScrollAriaLabel. Aria-label for the right scroll button */
rightScrollAriaLabel?: string;
/** Aria-label for the back scroll button */
backScrollAriaLabel?: string;
/** Aria-label for the forward scroll button */
forwardScrollAriaLabel?: string;
/** Determines what tag is used around the tabs. Use "nav" to define the tabs inside a navigation region */
component?: 'div' | 'nav';
/** Provides an accessible label for the tabs. Labels should be unique for each set of tabs that are present on a page. When component is set to nav, this prop should be defined to differentiate the tabs from other navigation regions on the page. */
'aria-label'?: string;
/** Waits until the first "enter" transition to mount tab children (add them to the DOM) */
mountOnEnter?: boolean;
/** Unmounts tab children (removes them from the DOM) when they are no longer visible */
unmountOnExit?: boolean;
/** Flag indicates that the tabs should use page insets. */
usePageInsets?: boolean;
/** Insets at various breakpoints. */
inset?: {
default?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
sm?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
md?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
lg?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
xl?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
'2xl'?: 'insetNone' | 'insetSm' | 'insetMd' | 'insetLg' | 'insetXl' | 'inset2xl';
};
/** Enable expandable vertical tabs at various breakpoints. (isVertical should be set to true for this to work) */
expandable?: {
default?: 'expandable' | 'nonExpandable';
sm?: 'expandable' | 'nonExpandable';
md?: 'expandable' | 'nonExpandable';
lg?: 'expandable' | 'nonExpandable';
xl?: 'expandable' | 'nonExpandable';
'2xl'?: 'expandable' | 'nonExpandable';
};
/** Flag to indicate if the vertical tabs are expanded */
isExpanded?: boolean;
/** Flag indicating the default expanded state for uncontrolled expand/collapse of */
defaultIsExpanded?: boolean;
/** Text that appears in the expandable toggle */
toggleText?: string;
/** Aria-label for the expandable toggle */
toggleAriaLabel?: string;
/** Callback function to toggle the expandable tabs. */
onToggle?: (event: React.MouseEvent, isExpanded: boolean) => void;
/** Flag which places overflowing tabs into a menu triggered by the last tab. Additionally an object can be passed with custom settings for the overflow tab. */
isOverflowHorizontal?: boolean | HorizontalOverflowObject;
/** Value to overwrite the randomly generated data-ouia-component-id.*/
ouiaId?: number | string;
/** Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. */
ouiaSafe?: boolean;
}
const variantStyle = {
default: '',
secondary: styles.modifiers.secondary
};
interface TabsState {
/** Used to signal if the scroll buttons should be used */
enableScrollButtons: boolean;
/** Used to control if the scroll buttons should be shown to the user via the pf-m-scrollable class */
showScrollButtons: boolean;
/** Used to control if the scroll buttons should be rendered. Rendering must occur before the scroll buttons are
* shown and rendering must be stopped after they stop being shown to preserve CSS transitions.
*/
renderScrollButtons: boolean;
disableBackScrollButton: boolean;
disableForwardScrollButton: boolean;
shownKeys: (string | number)[];
uncontrolledActiveKey: number | string;
uncontrolledIsExpandedLocal: boolean;
overflowingTabCount: number;
isInitializingAccent: boolean;
currentLinkAccentLength: string;
currentLinkAccentStart: string;
}
class Tabs extends Component<TabsProps, TabsState> {
static displayName = 'Tabs';
tabList = createRef<HTMLUListElement>();
leftScrollButtonRef = createRef<HTMLButtonElement>();
private direction = 'ltr';
constructor(props: TabsProps) {
super(props);
this.state = {
enableScrollButtons: false,
showScrollButtons: false,
renderScrollButtons: false,
disableBackScrollButton: true,
disableForwardScrollButton: true,
shownKeys: this.props.defaultActiveKey !== undefined ? [this.props.defaultActiveKey] : [this.props.activeKey], // only for mountOnEnter case
uncontrolledActiveKey: this.props.defaultActiveKey,
uncontrolledIsExpandedLocal: this.props.defaultIsExpanded,
overflowingTabCount: 0,
isInitializingAccent: true,
currentLinkAccentLength: linkAccentLength.value,
currentLinkAccentStart: linkAccentStart.value
};
if (this.props.isVertical && this.props.expandable !== undefined) {
if (!this.props.toggleAriaLabel && !this.props.toggleText) {
// eslint-disable-next-line no-console
console.error(
'Tabs:',
'toggleAriaLabel or the toggleText prop is required to make the toggle button accessible'
);
}
}
}
scrollTimeout: NodeJS.Timeout = null;
static defaultProps: PickOptional<TabsProps> = {
activeKey: 0,
onSelect: () => undefined as any,
isFilled: false,
isSubtab: false,
isNav: false,
isVertical: false,
isBox: false,
hasNoBorderBottom: false,
leftScrollAriaLabel: 'Scroll left',
backScrollAriaLabel: 'Scroll back',
rightScrollAriaLabel: 'Scroll right',
forwardScrollAriaLabel: 'Scroll forward',
mountOnEnter: false,
unmountOnExit: false,
ouiaSafe: true,
variant: 'default',
onToggle: (_event: React.MouseEvent, _isExpanded: boolean): void => undefined
};
handleTabClick(
event: React.MouseEvent<HTMLElement, MouseEvent>,
eventKey: number | string,
tabContentRef: React.RefObject<any>
) {
const { shownKeys } = this.state;
const { onSelect, defaultActiveKey } = this.props;
// if defaultActiveKey Tabs are uncontrolled, set new active key internally
if (defaultActiveKey !== undefined) {
this.setState({
uncontrolledActiveKey: eventKey
});
} else {
onSelect(event, eventKey);
}
// process any tab content sections outside of the component
if (tabContentRef) {
Children.toArray(this.props.children)
.filter((child): child is TabElement => isValidElement(child))
.filter(({ props }) => props.tabContentRef && props.tabContentRef.current)
.forEach((child) => (child.props.tabContentRef.current.hidden = true));
// most recently selected tabContent
if (tabContentRef.current) {
tabContentRef.current.hidden = false;
}
}
if (this.props.mountOnEnter) {
this.setState({
shownKeys: shownKeys.concat(eventKey)
});
}
}
countOverflowingElements = (container: HTMLUListElement) => {
const elements = Array.from(container.children);
return elements.filter((element) => !isElementInView(container, element as HTMLElement, false)).length;
};
handleScrollButtons = () => {
const { isOverflowHorizontal: isOverflowHorizontal } = this.props;
// add debounce to the scroll event
clearTimeout(this.scrollTimeout);
this.scrollTimeout = setTimeout(() => {
const container = this.tabList.current;
let disableBackScrollButton = true;
let disableForwardScrollButton = true;
let enableScrollButtons = false;
let overflowingTabCount = 0;
if (container && !this.props.isVertical && !isOverflowHorizontal) {
// get first element and check if it is in view
const overflowOnLeft = !isElementInView(container, container.firstChild as HTMLElement, false);
// get last element and check if it is in view
const overflowOnRight = !isElementInView(container, container.lastChild as HTMLElement, false);
enableScrollButtons = overflowOnLeft || overflowOnRight;
disableBackScrollButton = !overflowOnLeft;
disableForwardScrollButton = !overflowOnRight;
}
if (isOverflowHorizontal) {
overflowingTabCount = this.countOverflowingElements(container);
}
this.setState({
enableScrollButtons,
disableBackScrollButton,
disableForwardScrollButton,
overflowingTabCount
});
}, 100);
};
scrollBack = () => {
// find first Element that is fully in view on the left, then scroll to the element before it
if (this.tabList.current) {
const container = this.tabList.current;
const childrenArr = Array.from(container.children);
let firstElementInView: any;
let lastElementOutOfView: any;
let i;
for (i = 0; i < childrenArr.length && !firstElementInView; i++) {
if (isElementInView(container, childrenArr[i] as HTMLElement, false)) {
firstElementInView = childrenArr[i];
lastElementOutOfView = childrenArr[i - 1];
}
}
if (lastElementOutOfView) {
if (this.direction === 'ltr') {
// LTR scrolls left to go back
container.scrollLeft -= lastElementOutOfView.scrollWidth;
} else {
// RTL scrolls right to go back
container.scrollLeft += lastElementOutOfView.scrollWidth;
}
}
}
};
scrollForward = () => {
// find last Element that is fully in view on the right, then scroll to the element after it
if (this.tabList.current) {
const container = this.tabList.current as any;
const childrenArr = Array.from(container.children);
let lastElementInView: any;
let firstElementOutOfView: any;
for (let i = childrenArr.length - 1; i >= 0 && !lastElementInView; i--) {
if (isElementInView(container, childrenArr[i] as HTMLElement, false)) {
lastElementInView = childrenArr[i];
firstElementOutOfView = childrenArr[i + 1];
}
}
if (firstElementOutOfView) {
if (this.direction === 'ltr') {
// LTR scrolls right to go forward
container.scrollLeft += firstElementOutOfView.scrollWidth;
} else {
// RTL scrolls left to go forward
container.scrollLeft -= firstElementOutOfView.scrollWidth;
}
}
}
};
hideScrollButtons = () => {
const { enableScrollButtons, renderScrollButtons, showScrollButtons } = this.state;
if (!enableScrollButtons && !showScrollButtons && renderScrollButtons) {
this.setState({ renderScrollButtons: false });
}
};
setAccentStyles = (shouldInitializeStyle?: boolean) => {
const currentItem = this.tabList.current.querySelector('li.pf-m-current') as HTMLElement;
if (!currentItem) {
return;
}
const { isVertical } = this.props;
const { offsetWidth, offsetHeight, offsetTop } = currentItem;
const lengthValue = isVertical ? offsetHeight : offsetWidth;
const startValue = isVertical ? offsetTop : getInlineStartProperty(currentItem, this.tabList.current);
this.setState({
currentLinkAccentLength: `${lengthValue}px`,
currentLinkAccentStart: `${startValue}px`,
...(shouldInitializeStyle && { isInitializingAccent: true })
});
setTimeout(() => {
this.setState({ isInitializingAccent: false });
}, 0);
};
handleResize = () => {
this.handleScrollButtons();
this.setAccentStyles();
};
componentDidMount() {
if (!this.props.isVertical) {
if (canUseDOM) {
window.addEventListener('resize', this.handleResize, false);
}
this.direction = getLanguageDirection(this.tabList.current);
// call the handle resize function to check if scroll buttons should be shown
this.handleScrollButtons();
}
this.setAccentStyles(true);
}
componentWillUnmount() {
if (!this.props.isVertical) {
if (canUseDOM) {
window.removeEventListener('resize', this.handleResize, false);
}
}
clearTimeout(this.scrollTimeout);
this.leftScrollButtonRef.current?.removeEventListener('transitionend', this.hideScrollButtons);
}
componentDidUpdate(prevProps: TabsProps, prevState: TabsState) {
this.direction = getLanguageDirection(this.tabList.current);
const { activeKey, mountOnEnter, isOverflowHorizontal, children, defaultActiveKey } = this.props;
const { shownKeys, overflowingTabCount, enableScrollButtons, uncontrolledActiveKey } = this.state;
const isOnCloseUpdate = !!prevProps.onClose !== !!this.props.onClose;
if (
(defaultActiveKey !== undefined && prevState.uncontrolledActiveKey !== uncontrolledActiveKey) ||
(defaultActiveKey === undefined && prevProps.activeKey !== activeKey) ||
isOnCloseUpdate
) {
this.setAccentStyles(isOnCloseUpdate);
}
if (prevProps.activeKey !== activeKey && mountOnEnter && shownKeys.indexOf(activeKey) < 0) {
this.setState({
shownKeys: shownKeys.concat(activeKey)
});
}
if (
prevProps.children &&
children &&
Children.toArray(prevProps.children).length !== Children.toArray(children).length
) {
this.handleScrollButtons();
this.setAccentStyles(true);
}
const currentOverflowingTabCount = this.countOverflowingElements(this.tabList.current);
if (isOverflowHorizontal && currentOverflowingTabCount) {
this.setState({ overflowingTabCount: currentOverflowingTabCount + overflowingTabCount });
}
if (!prevState.enableScrollButtons && enableScrollButtons) {
this.setState({ renderScrollButtons: true });
setTimeout(() => {
// Remove any existing listener before adding a new one to prevent accumulation
this.leftScrollButtonRef.current?.removeEventListener('transitionend', this.hideScrollButtons);
this.leftScrollButtonRef.current?.addEventListener('transitionend', this.hideScrollButtons);
this.setState({ showScrollButtons: true });
}, 100);
} else if (prevState.enableScrollButtons && !enableScrollButtons) {
this.setState({ showScrollButtons: false });
}
if (prevState.uncontrolledIsExpandedLocal !== this.state.uncontrolledIsExpandedLocal) {
this.setAccentStyles(true);
}
}
static getDerivedStateFromProps(nextProps: TabsProps, prevState: TabsState) {
if (prevState.uncontrolledActiveKey === undefined) {
return null;
}
const childrenHasTabWithActiveEventKey = Children.toArray(nextProps.children)
.filter((child): child is TabElement => isValidElement(child))
.some(({ props }) => props.eventKey === prevState.uncontrolledActiveKey);
// if uncontrolledActiveKey is an existing eventKey of any Tab of nextProps.children --> don't update uncontrolledActiveKey
if (childrenHasTabWithActiveEventKey) {
return null;
}
// otherwise update state derived from nextProps.defaultActiveKey
return {
uncontrolledActiveKey: nextProps.defaultActiveKey,
shownKeys: nextProps.defaultActiveKey !== undefined ? [nextProps.defaultActiveKey] : [nextProps.activeKey] // only for mountOnEnter case
};
}
render() {
const {
className,
children,
activeKey,
defaultActiveKey,
id,
isAddButtonDisabled,
isFilled,
isSubtab,
isNav,
isVertical,
isBox,
hasNoBorderBottom,
leftScrollAriaLabel,
rightScrollAriaLabel,
backScrollAriaLabel,
forwardScrollAriaLabel,
'aria-label': ariaLabel,
component,
ouiaId,
ouiaSafe,
mountOnEnter,
unmountOnExit,
usePageInsets,
inset,
variant,
expandable,
isExpanded,
defaultIsExpanded,
toggleText,
toggleAriaLabel,
addButtonAriaLabel,
tabListAriaLabel,
tabListAriaLabelledBy,
onToggle,
onClose,
onAdd,
isOverflowHorizontal: isOverflowHorizontal,
...props
} = this.props;
const {
showScrollButtons,
renderScrollButtons,
disableBackScrollButton,
disableForwardScrollButton,
shownKeys,
uncontrolledActiveKey,
uncontrolledIsExpandedLocal,
overflowingTabCount,
isInitializingAccent,
currentLinkAccentLength,
currentLinkAccentStart
} = this.state;
const filteredChildren = Children.toArray(children)
.filter((child): child is TabElement => isValidElement(child))
.filter(({ props }) => !props.isHidden);
const filteredChildrenWithoutOverflow = filteredChildren.slice(0, filteredChildren.length - overflowingTabCount);
const filteredChildrenOverflowing = filteredChildren.slice(filteredChildren.length - overflowingTabCount);
const overflowingTabProps = filteredChildrenOverflowing.map((child: React.ReactElement<TabProps>) => child.props);
const defaultComponent = isNav && !component ? 'nav' : 'div';
const Component: any = component !== undefined ? component : defaultComponent;
const localActiveKey = defaultActiveKey !== undefined ? uncontrolledActiveKey : activeKey;
const isExpandedLocal = defaultIsExpanded !== undefined ? uncontrolledIsExpandedLocal : isExpanded;
/* Uncontrolled expandable tabs */
const toggleTabs = (event: React.MouseEvent, newValue: boolean) => {
if (isExpanded === undefined) {
this.setState({ uncontrolledIsExpandedLocal: newValue });
} else {
onToggle(event, newValue);
}
};
const hasOverflowTab = isOverflowHorizontal && overflowingTabCount > 0;
const overflowObjectProps = typeof isOverflowHorizontal === 'object' ? { ...isOverflowHorizontal } : {};
return (
<SSRSafeIds prefix="pf-random-id-" ouiaComponentType={Tabs.displayName}>
{(generatedId, generatedOuiaId) => {
const uniqueId = id || generatedId;
return (
<TabsContextProvider
value={{
variant,
mountOnEnter,
unmountOnExit,
localActiveKey,
uniqueId,
setAccentStyles: this.setAccentStyles,
handleTabClick: (...args) => this.handleTabClick(...args),
handleTabClose: onClose
}}
>
<Component
aria-label={ariaLabel}
className={css(
styles.tabs,
styles.modifiers.animateCurrent,
isFilled && styles.modifiers.fill,
isSubtab && styles.modifiers.subtab,
isNav && styles.modifiers.nav,
isVertical && styles.modifiers.vertical,
isVertical && expandable && formatBreakpointMods(expandable, styles),
isVertical && expandable && isExpandedLocal && styles.modifiers.expanded,
isBox && styles.modifiers.box,
showScrollButtons && styles.modifiers.scrollable,
usePageInsets && styles.modifiers.pageInsets,
hasNoBorderBottom && styles.modifiers.noBorderBottom,
formatBreakpointMods(inset, styles),
variantStyle[variant],
hasOverflowTab && styles.modifiers.overflow,
isInitializingAccent && styles.modifiers.initializingAccent,
className
)}
{...getOUIAProps(Tabs.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId, ouiaSafe)}
id={id && id}
{...props}
style={{
[linkAccentLength.name]: currentLinkAccentLength,
[linkAccentStart.name]: currentLinkAccentStart,
...props.style
}}
>
{expandable && isVertical && (
<GenerateId>
{(randomId) => (
<div className={css(styles.tabsToggle)}>
<div className={'pf-v6-c-tabs__toggle-button'}>
<Button
onClick={(event) => toggleTabs(event, !isExpandedLocal)}
variant="plain"
aria-label={toggleAriaLabel}
aria-expanded={isExpandedLocal}
id={`${randomId}-button`}
aria-labelledby={`${randomId}-text ${randomId}-button`}
icon={
<span className={css(styles.tabsToggleIcon)}>
<AngleRightIcon />
</span>
}
>
{toggleText && <span id={`${randomId}-text`}>{toggleText}</span>}
</Button>
</div>
</div>
)}
</GenerateId>
)}
{renderScrollButtons && (
<div className={css(styles.tabsScrollButton)}>
<Button
aria-label={backScrollAriaLabel || leftScrollAriaLabel}
onClick={this.scrollBack}
isDisabled={disableBackScrollButton}
aria-hidden={disableBackScrollButton}
ref={this.leftScrollButtonRef}
variant="plain"
icon={<AngleLeftIcon />}
/>
</div>
)}
<ul
aria-label={tabListAriaLabel}
aria-labelledby={tabListAriaLabelledBy}
className={css(styles.tabsList)}
ref={this.tabList}
onScroll={this.handleScrollButtons}
role="tablist"
>
{isOverflowHorizontal ? filteredChildrenWithoutOverflow : filteredChildren}
{hasOverflowTab && <OverflowTab overflowingTabs={overflowingTabProps} {...overflowObjectProps} />}
</ul>
{renderScrollButtons && (
<div className={css(styles.tabsScrollButton)}>
<Button
aria-label={forwardScrollAriaLabel || rightScrollAriaLabel}
onClick={this.scrollForward}
isDisabled={disableForwardScrollButton}
aria-hidden={disableForwardScrollButton}
variant="plain"
icon={<AngleRightIcon />}
/>
</div>
)}
{onAdd !== undefined && (
<span className={css(styles.tabsAdd)}>
<Button
variant="plain"
aria-label={addButtonAriaLabel || 'Add tab'}
onClick={onAdd}
icon={<PlusIcon />}
isDisabled={isAddButtonDisabled}
/>
</span>
)}
</Component>
{filteredChildren
.filter(
(child) =>
child.props.children &&
!(unmountOnExit && child.props.eventKey !== localActiveKey) &&
!(mountOnEnter && shownKeys.indexOf(child.props.eventKey) === -1)
)
.map((child) => (
<TabContent
key={child.props.eventKey}
activeKey={localActiveKey}
child={child}
id={child.props.id || uniqueId}
ouiaId={child.props.ouiaId}
/>
))}
</TabsContextProvider>
);
}}
</SSRSafeIds>
);
}
}
export { Tabs };