Skip to content

Commit 8fdd83e

Browse files
feat(Tabs): consumed Penta updates (#10044)
* feat(Tabs): consumed Penta updates * Updated unit tests * Updated integration tests
1 parent 86a75d2 commit 8fdd83e

21 files changed

Lines changed: 348 additions & 349 deletions

File tree

packages/react-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"tslib": "^2.5.0"
5555
},
5656
"devDependencies": {
57-
"@patternfly/patternfly": "6.0.0-alpha.66",
57+
"@patternfly/patternfly": "6.0.0-alpha.69",
5858
"@rollup/plugin-commonjs": "^25.0.0",
5959
"@rollup/plugin-node-resolve": "^15.0.2",
6060
"@rollup/plugin-replace": "^5.0.2",

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export interface TabContentProps extends Omit<React.HTMLProps<HTMLElement>, 'ref
2727
ouiaSafe?: boolean;
2828
}
2929

30-
// TODO: Update with issue #9909
31-
// const variantStyle = {
32-
// default: ''
33-
// };
30+
const variantStyle = {
31+
default: '',
32+
secondary: styles.modifiers.secondary
33+
};
3434

3535
const TabContentBase: React.FunctionComponent<TabContentProps> = ({
3636
id,
@@ -56,27 +56,30 @@ const TabContentBase: React.FunctionComponent<TabContentProps> = ({
5656

5757
return (
5858
<TabsContextConsumer>
59-
{({ variant }: TabsContextProps) => (
60-
<section
61-
ref={innerRef}
62-
hidden={children ? null : child.props.eventKey !== activeKey}
63-
// TODO: Update "variant" with issue #9909
64-
className={
65-
children
66-
? css(styles.tabContent, className, variant)
67-
: css(styles.tabContent, child.props.className, variant)
68-
}
69-
id={children ? id : `pf-tab-section-${child.props.eventKey}-${id}`}
70-
aria-label={ariaLabel}
71-
aria-labelledby={labelledBy}
72-
role="tabpanel"
73-
tabIndex={0}
74-
{...getOUIAProps('TabContent', ouiaId, ouiaSafe)}
75-
{...props}
76-
>
77-
{children || child.props.children}
78-
</section>
79-
)}
59+
{({ variant }: TabsContextProps) => {
60+
const variantClass = variantStyle[variant];
61+
62+
return (
63+
<section
64+
ref={innerRef}
65+
hidden={children ? null : child.props.eventKey !== activeKey}
66+
className={
67+
children
68+
? css(styles.tabContent, className, variantClass)
69+
: css(styles.tabContent, child.props.className, variantClass)
70+
}
71+
id={children ? id : `pf-tab-section-${child.props.eventKey}-${id}`}
72+
aria-label={ariaLabel}
73+
aria-labelledby={labelledBy}
74+
role="tabpanel"
75+
tabIndex={0}
76+
{...getOUIAProps('TabContent', ouiaId, ouiaSafe)}
77+
{...props}
78+
>
79+
{children || child.props.children}
80+
</section>
81+
);
82+
}}
8083
</TabsContextConsumer>
8184
);
8285
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const TabTitleIcon: React.FunctionComponent<TabTitleIconProps> = ({
1414
className = '',
1515
...props
1616
}: TabTitleIconProps) => (
17-
<span className={css(styles.tabsItemIcon, className)} {...props}>
17+
<span className={css(`${styles.tabs}__item-icon`, className)} {...props}>
1818
{children}
1919
</span>
2020
);

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import styles from '@patternfly/react-styles/css/components/Tabs/tabs';
3-
import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
43
import { css } from '@patternfly/react-styles';
54
import { PickOptional } from '../../helpers/typeUtils';
65
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
@@ -38,7 +37,7 @@ export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivEle
3837
/** Additional classes added to the tabs */
3938
className?: string;
4039
/** Tabs background color variant */
41-
variant?: 'default';
40+
variant?: 'default' | 'secondary';
4241
/** The index of the active tab */
4342
activeKey?: number | string;
4443
/** The index of the default active tab. Set this for uncontrolled Tabs */
@@ -55,8 +54,8 @@ export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivEle
5554
id?: string;
5655
/** Enables the filled tab list layout */
5756
isFilled?: boolean;
58-
/** Enables secondary tab styling */
59-
isSecondary?: boolean;
57+
/** Enables subtab tab styling */
58+
isSubtab?: boolean;
6059
/** Enables box styling to the tab component */
6160
isBox?: boolean;
6261
/** Enables vertical tab styling */
@@ -119,7 +118,7 @@ export interface TabsProps extends Omit<React.HTMLProps<HTMLElement | HTMLDivEle
119118

120119
const variantStyle = {
121120
default: '',
122-
light300: styles.modifiers.colorSchemeLight_300
121+
secondary: styles.modifiers.secondary
123122
};
124123

125124
interface TabsState {
@@ -177,7 +176,7 @@ class Tabs extends React.Component<TabsProps, TabsState> {
177176
activeKey: 0,
178177
onSelect: () => undefined as any,
179178
isFilled: false,
180-
isSecondary: false,
179+
isSubtab: false,
181180
isVertical: false,
182181
isBox: false,
183182
hasNoBorderBottom: false,
@@ -247,7 +246,6 @@ class Tabs extends React.Component<TabsProps, TabsState> {
247246
if (container && !this.props.isVertical && !isOverflowHorizontal) {
248247
// get first element and check if it is in view
249248
const overflowOnLeft = !isElementInView(container, container.firstChild as HTMLElement, false);
250-
251249
// get last element and check if it is in view
252250
const overflowOnRight = !isElementInView(container, container.lastChild as HTMLElement, false);
253251

@@ -392,7 +390,7 @@ class Tabs extends React.Component<TabsProps, TabsState> {
392390
defaultActiveKey,
393391
id,
394392
isFilled,
395-
isSecondary,
393+
isSubtab,
396394
isVertical,
397395
isBox,
398396
hasNoBorderBottom,
@@ -473,7 +471,7 @@ class Tabs extends React.Component<TabsProps, TabsState> {
473471
className={css(
474472
styles.tabs,
475473
isFilled && styles.modifiers.fill,
476-
isSecondary && styles.modifiers.secondary,
474+
isSubtab && styles.modifiers.subtab,
477475
isVertical && styles.modifiers.vertical,
478476
isVertical && expandable && formatBreakpointMods(expandable, styles),
479477
isVertical && expandable && isExpandedLocal && styles.modifiers.expanded,
@@ -518,33 +516,35 @@ class Tabs extends React.Component<TabsProps, TabsState> {
518516
</GenerateId>
519517
)}
520518
{renderScrollButtons && (
521-
<button
522-
type="button"
523-
className={css(styles.tabsScrollButton, isSecondary && buttonStyles.modifiers.secondary)}
524-
aria-label={backScrollAriaLabel || leftScrollAriaLabel}
525-
onClick={this.scrollBack}
526-
disabled={disableBackScrollButton}
527-
aria-hidden={disableBackScrollButton}
528-
ref={this.leftScrollButtonRef}
529-
>
530-
<AngleLeftIcon />
531-
</button>
519+
<div className={css(styles.tabsScrollButton)}>
520+
<Button
521+
aria-label={backScrollAriaLabel || leftScrollAriaLabel}
522+
onClick={this.scrollBack}
523+
isDisabled={disableBackScrollButton}
524+
aria-hidden={disableBackScrollButton}
525+
ref={this.leftScrollButtonRef}
526+
variant="plain"
527+
>
528+
<AngleLeftIcon />
529+
</Button>
530+
</div>
532531
)}
533532
<ul className={css(styles.tabsList)} ref={this.tabList} onScroll={this.handleScrollButtons} role="tablist">
534533
{isOverflowHorizontal ? filteredChildrenWithoutOverflow : filteredChildren}
535534
{hasOverflowTab && <OverflowTab overflowingTabs={overflowingTabProps} {...overflowObjectProps} />}
536535
</ul>
537536
{renderScrollButtons && (
538-
<button
539-
type="button"
540-
className={css(styles.tabsScrollButton, isSecondary && buttonStyles.modifiers.secondary)}
541-
aria-label={forwardScrollAriaLabel || rightScrollAriaLabel}
542-
onClick={this.scrollForward}
543-
disabled={disableForwardScrollButton}
544-
aria-hidden={disableForwardScrollButton}
545-
>
546-
<AngleRightIcon />
547-
</button>
537+
<div className={css(styles.tabsScrollButton)}>
538+
<Button
539+
aria-label={forwardScrollAriaLabel || rightScrollAriaLabel}
540+
onClick={this.scrollForward}
541+
isDisabled={disableForwardScrollButton}
542+
aria-hidden={disableForwardScrollButton}
543+
variant="plain"
544+
>
545+
<AngleRightIcon />
546+
</Button>
547+
</div>
548548
)}
549549
{onAdd !== undefined && (
550550
<span className={css(styles.tabsAdd)}>

packages/react-core/src/components/Tabs/TabsContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22

33
export interface TabsContextProps {
4-
variant: 'default' | 'light300';
4+
variant: 'default' | 'secondary';
55
mountOnEnter: boolean;
66
unmountOnExit: boolean;
77
localActiveKey: string | number;

packages/react-core/src/components/Tabs/__tests__/Generated/__snapshots__/TabContent.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ exports[`TabContent should match snapshot (auto-generated) 1`] = `
44
<DocumentFragment>
55
<section
66
aria-label="string"
7-
class="pf-v5-c-tab-content string default"
7+
class="pf-v5-c-tab-content string"
88
data-ouia-component-type="PF5/TabContent"
99
data-ouia-safe="true"
1010
id="string"

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,19 @@ test('should render filled tabs', () => {
251251
expect(asFragment()).toMatchSnapshot();
252252
});
253253

254-
test('should render secondary tabs', () => {
254+
test('should render subtabs', () => {
255255
const { asFragment } = render(
256256
<Tabs id="primarieTabs">
257257
<Tab eventKey={0} title={<TabTitleText>"Tab item 1"</TabTitleText>}>
258-
<Tabs isSecondary id="secondaryTabs">
259-
<Tab id="secondary tab1" eventKey={10} title={<TabTitleText>"Secondary Tab item 1"</TabTitleText>}>
260-
Secondary Tab 1 section
258+
<Tabs isSubtab id="subtabs">
259+
<Tab id="subtab1" eventKey={10} title={<TabTitleText>"Subtab item 1"</TabTitleText>}>
260+
Subtab 1 section
261261
</Tab>
262-
<Tab id="secondary tab2" eventKey={11} title={<TabTitleText>"Secondary Tab item 2"</TabTitleText>}>
263-
Secondary Tab 2 section
262+
<Tab id="subtab2" eventKey={11} title={<TabTitleText>"Subtab item 2"</TabTitleText>}>
263+
Subtab 2 section
264264
</Tab>
265-
<Tab id="secondary tab3" eventKey={12} title={<TabTitleText>"Secondary Tab item 3"</TabTitleText>}>
266-
Secondary Tab 3 section
265+
<Tab id="subtab3" eventKey={12} title={<TabTitleText>"Subtab item 3"</TabTitleText>}>
266+
Subtab 3 section
267267
</Tab>
268268
</Tabs>
269269
</Tab>
@@ -338,9 +338,9 @@ test('should render tabs with separate content', () => {
338338
expect(asFragment()).toMatchSnapshot();
339339
});
340340

341-
test('should render box tabs of light variant', () => {
341+
test('should render box tabs of secondary variant', () => {
342342
const { asFragment } = render(
343-
<Tabs id="boxLightVariantTabs" isBox variant="light300">
343+
<Tabs id="boxSecondaryVariantTabs" isBox variant="secondary">
344344
<Tab id="tab1" eventKey={0} title={<TabTitleText>"Tab item 1"</TabTitleText>}>
345345
Tab 1 section
346346
</Tab>
@@ -372,9 +372,9 @@ test('should render tabs with no bottom border', () => {
372372
expect(asFragment()).toMatchSnapshot();
373373
});
374374

375-
test('should render secondary tabs with no bottom border when passed hasNoBorderBottom', () => {
375+
test('should render subtabs with no bottom border when passed hasNoBorderBottom', () => {
376376
render(
377-
<Tabs isSecondary hasNoBorderBottom id="noBottomBorderTabs" aria-label="Secondary bottom border">
377+
<Tabs isSubtab hasNoBorderBottom id="noBottomBorderTabs" aria-label="Subtab bottom border">
378378
<Tab id="tab1" eventKey={0} title={<TabTitleText>"Tab item 1"</TabTitleText>}>
379379
Tab 1 section
380380
</Tab>
@@ -387,14 +387,14 @@ test('should render secondary tabs with no bottom border when passed hasNoBorder
387387
</Tabs>
388388
);
389389

390-
const tabsContainer = screen.queryByLabelText('Secondary bottom border');
390+
const tabsContainer = screen.queryByLabelText('Subtab bottom border');
391391

392392
expect(tabsContainer).toHaveClass('pf-m-no-border-bottom');
393393
});
394394

395-
test('should render secondary tabs with border bottom', () => {
395+
test('should render subtabs with border bottom', () => {
396396
render(
397-
<Tabs isSecondary id="bottomBorderTabs" aria-label="Secondary bottom border">
397+
<Tabs isSubtab id="bottomBorderTabs" aria-label="Subtab bottom border">
398398
<Tab id="tab1" eventKey={0} title={<TabTitleText>"Tab item 1"</TabTitleText>}>
399399
Tab 1 section
400400
</Tab>
@@ -407,7 +407,7 @@ test('should render secondary tabs with border bottom', () => {
407407
</Tabs>
408408
);
409409

410-
const tabsContainer = screen.queryByLabelText('Secondary bottom border');
410+
const tabsContainer = screen.queryByLabelText('Subtab bottom border');
411411

412412
expect(tabsContainer).not.toHaveClass('pf-m-no-border-bottom');
413413
});

0 commit comments

Comments
 (0)