Skip to content

Commit 4029230

Browse files
author
Eric Olkowski
committed
Added popperProps and updated cypress tests
1 parent 2fd75bc commit 4029230

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ import { TabsContext } from './TabsContext';
88
import { TabProps } from './Tab';
99
import { TabTitleText } from './TabTitleText';
1010

11+
export interface HorizontalOverflowPopperProps {
12+
/** Vertical direction of the popper. If enableFlip is set to true, this will set the initial direction before the popper flips. */
13+
direction?: 'up' | 'down';
14+
/** Horizontal position of the popper */
15+
position?: 'right' | 'left' | 'center' | 'start' | 'end';
16+
/** Custom width of the popper. If the value is "trigger", it will set the width to the select toggle's width */
17+
width?: string | 'trigger';
18+
/** Minimum width of the popper. If the value is "trigger", it will set the min width to the select toggle's width */
19+
minWidth?: string | 'trigger';
20+
/** Maximum width of the popper. If the value is "trigger", it will set the max width to the select toggle's width */
21+
maxWidth?: string | 'trigger';
22+
/** Enable to flip the popper when it reaches the boundary */
23+
enableFlip?: boolean;
24+
/** The container to append the select to. Defaults to document.body.
25+
* If your select is being cut off you can append it to an element higher up the DOM tree.
26+
* Some examples:
27+
* appendTo="inline"
28+
* appendTo={() => document.body}
29+
* appendTo={document.getElementById('target')}
30+
*/
31+
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
32+
/** Flag to prevent the popper from overflowing its container and becoming partially obscured. */
33+
preventOverflow?: boolean;
34+
}
35+
1136
export interface OverflowTabProps extends React.HTMLProps<HTMLLIElement> {
1237
/** Additional classes added to the overflow tab */
1338
className?: string;
@@ -25,6 +50,8 @@ export interface OverflowTabProps extends React.HTMLProps<HTMLLIElement> {
2550
shouldPreventScrollOnItemFocus?: boolean;
2651
/** Time in ms to wait before firing the toggles' focus event. Defaults to 0 */
2752
focusTimeoutDelay?: number;
53+
/** Additional props to spread to the popper menu. */
54+
popperProps?: HorizontalOverflowPopperProps;
2855
}
2956

3057
export const OverflowTab: React.FunctionComponent<OverflowTabProps> = ({
@@ -36,6 +63,7 @@ export const OverflowTab: React.FunctionComponent<OverflowTabProps> = ({
3663
zIndex = 9999,
3764
shouldPreventScrollOnItemFocus = true,
3865
focusTimeoutDelay = 0,
66+
popperProps,
3967
...props
4068
}: OverflowTabProps) => {
4169
const menuRef = useRef<HTMLDivElement>(undefined);
@@ -148,6 +176,7 @@ export const OverflowTab: React.FunctionComponent<OverflowTabProps> = ({
148176
minWidth="revert"
149177
appendTo={overflowLIRef.current}
150178
zIndex={zIndex}
179+
{...popperProps}
151180
/>
152181
</Fragment>
153182
);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { TabContent } from './TabContent';
1616
import { TabProps } from './Tab';
1717
import { TabsContextProvider } from './TabsContext';
18-
import { OverflowTab } from './OverflowTab';
18+
import { OverflowTab, HorizontalOverflowPopperProps } from './OverflowTab';
1919
import { Button } from '../Button';
2020
import { getOUIAProps, OUIAProps, getDefaultOUIAId, canUseDOM } from '../../helpers';
2121
import { GenerateId } from '../../helpers/GenerateId/GenerateId';
@@ -26,14 +26,15 @@ export enum TabsComponent {
2626
div = 'div',
2727
nav = 'nav'
2828
}
29-
3029
export interface HorizontalOverflowObject {
3130
/** Flag which shows the count of overflowing tabs when enabled */
3231
showTabCount?: boolean;
3332
/** The text which displays when an overflowing tab isn't selected */
3433
defaultTitleText?: string;
3534
/** The aria label applied to the button which toggles the tab overflow menu */
3635
toggleAriaLabel?: string;
36+
/** Additional props to spread to the popper menu. */
37+
popperProps?: HorizontalOverflowPopperProps;
3738
}
3839

3940
type TabElement = React.ReactElement<TabProps, React.JSXElementConstructor<TabProps>>;

packages/react-core/src/components/Tabs/examples/Tabs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
id: Tabs
33
section: components
44
cssPrefix: pf-v6-c-tabs
5-
propComponents: ['Tabs', 'Tab', 'TabContent', 'TabContentBody', 'TabTitleText', 'TabTitleIcon', 'horizontalOverflowObject', 'TabAction']
5+
propComponents: ['Tabs', 'Tab', 'TabContent', 'TabContentBody', 'TabTitleText', 'TabTitleIcon', 'HorizontalOverflowObject', 'HorizontalOverflowPopperProps' 'TabAction']
66
ouia: true
77
---
88

packages/react-integration/cypress/integration/tabshorizontaloverflow.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ describe('Tab Demo Test', () => {
3131
cy.contains('Tab 1 section').should('not.be.hidden');
3232
});
3333

34-
it('Adjusts tabs showing on resize', () => {
34+
// Re-enable once https://github.com/patternfly/patternfly/issues/7449 is resolved
35+
xit('Adjusts tabs showing on resize', () => {
3536
// shrink viewport and verify that tabs which would now overflow are moved to the overflow tab
3637
cy.viewport(700, 792);
3738
['Tab item 1', 'Tab item 2', 'Tab item 3', 'Tab item 4', 'Tab item 5', 'More'].forEach((tab) =>

packages/react-integration/demo-app-ts/src/components/demos/TabsDemo/TabsHorizontalOverflowDemo.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ export const TabsHorizontalOverflowDemo: React.FunctionComponent = () => {
1818
onSelect={handleTabClick}
1919
aria-label="Tabs in the horizontal overflow example"
2020
role="region"
21-
isOverflowHorizontal={{ showTabCount, defaultTitleText, toggleAriaLabel }}
21+
isOverflowHorizontal={{
22+
showTabCount,
23+
defaultTitleText,
24+
toggleAriaLabel,
25+
popperProps: { minWidth: 'max-content' }
26+
}}
2227
>
2328
<Tab
2429
eventKey={0}
@@ -62,16 +67,19 @@ export const TabsHorizontalOverflowDemo: React.FunctionComponent = () => {
6267
isChecked={showTabCount}
6368
onChange={() => setShowTabCount(!showTabCount)}
6469
id="toggle-show-count-overflow"
70+
label="Show tab count"
6571
/>
6672
<Checkbox
6773
isChecked={!!defaultTitleText}
6874
onChange={() => setDefaultTitleText(defaultTitleText ? undefined : 'Overflow')}
6975
id="toggle-change-toggle-text"
76+
label="Set default title text"
7077
/>
7178
<Checkbox
7279
isChecked={!!toggleAriaLabel}
7380
onChange={() => setToggleAriaLabel(toggleAriaLabel ? undefined : 'Overflow aria label')}
7481
id="toggle-add-aria-label"
82+
label="Toggle aria label"
7583
/>
7684
</div>
7785
);

0 commit comments

Comments
 (0)