Skip to content

Commit b79c4d6

Browse files
authored
feat: extend PopperProps in derivative component types (#11934)
* feat: extend `PopperProps` in derivative types * refactor: DRY up `Omit` types * feat: deprecate derivative PopperProps and prefer PopperOptions
1 parent b75c944 commit b79c4d6

File tree

9 files changed

+74
-142
lines changed

9 files changed

+74
-142
lines changed

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
import { forwardRef, useEffect, useRef } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { Menu, MenuContent, MenuProps } from '../Menu';
4-
import { Popper } from '../../helpers/Popper/Popper';
4+
import { Popper, PopperOptions } from '../../helpers/Popper/Popper';
55
import { useOUIAProps, OUIAProps, onToggleArrowKeydownDefault } from '../../helpers';
66

7-
export interface DropdownPopperProps {
8-
/** Vertical direction of the popper. If enableFlip is set to true, this will set the initial direction before the popper flips. */
9-
direction?: 'up' | 'down';
10-
/** Horizontal position of the popper */
11-
position?: 'right' | 'left' | 'center' | 'start' | 'end';
12-
/** Custom width of the popper. If the value is "trigger", it will set the width to the dropdown toggle's width */
13-
width?: string | 'trigger';
14-
/** Minimum width of the popper. If the value is "trigger", it will set the min width to the dropdown toggle's width */
15-
minWidth?: string | 'trigger';
16-
/** Maximum width of the popper. If the value is "trigger", it will set the max width to the dropdown toggle's width */
17-
maxWidth?: string | 'trigger';
18-
/** Enable to flip the popper when it reaches the boundary */
19-
enableFlip?: boolean;
20-
/** The container to append the popper to. Defaults to document.body. */
21-
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
22-
/** Flag to prevent the popper from overflowing its container and becoming partially obscured. */
23-
preventOverflow?: boolean;
24-
}
7+
/** @deprecated Use PopperOptions instead */
8+
export type DropdownPopperProps = PopperOptions;
259

2610
export interface DropdownToggleProps {
2711
/** Dropdown toggle node. */
@@ -66,7 +50,7 @@ export interface DropdownProps extends MenuProps, OUIAProps {
6650
/** z-index of the dropdown menu */
6751
zIndex?: number;
6852
/** Additional properties to pass to the Popper */
69-
popperProps?: DropdownPopperProps;
53+
popperProps?: PopperOptions;
7054
/** Height of the dropdown menu */
7155
menuHeight?: string;
7256
/** Maximum height of dropdown menu */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ propComponents:
1111
'DropdownList',
1212
'MenuToggle',
1313
'DropdownToggleProps',
14-
'DropdownPopperProps',
15-
'TooltipProps'
14+
'TooltipProps',
15+
'PopperOptions'
1616
]
1717
---
1818

packages/react-core/src/components/Menu/MenuContainer.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { useEffect, useRef } from 'react';
22
import { onToggleArrowKeydownDefault, Popper } from '../../helpers';
3+
import type { PopperOptions } from '../../helpers/Popper/Popper';
34

4-
export interface MenuPopperProps {
5-
/** Vertical direction of the popper. If enableFlip is set to true, this will set the initial direction before the popper flips. */
6-
direction?: 'up' | 'down';
7-
/** Horizontal position of the popper */
8-
position?: 'right' | 'left' | 'center' | 'start' | 'end';
9-
/** Custom width of the popper. If the value is "trigger", it will set the width to the dropdown toggle's width */
10-
width?: string | 'trigger';
11-
/** Minimum width of the popper. If the value is "trigger", it will set the min width to the dropdown toggle's width */
12-
minWidth?: string | 'trigger';
13-
/** Maximum width of the popper. If the value is "trigger", it will set the max width to the dropdown toggle's width */
14-
maxWidth?: string | 'trigger';
15-
/** Enable to flip the popper when it reaches the boundary */
16-
enableFlip?: boolean;
17-
/** Flag to prevent the popper from overflowing its container and becoming partially obscured. */
18-
preventOverflow?: boolean;
19-
}
5+
/** @deprecated Use PopperOptions instead */
6+
export type MenuPopperProps = PopperOptions;
207

218
export interface MenuContainerProps {
229
/** Menu to be rendered */
@@ -39,7 +26,7 @@ export interface MenuContainerProps {
3926
/** z-index of the dropdown menu */
4027
zIndex?: number;
4128
/** Additional properties to pass to the Popper */
42-
popperProps?: MenuPopperProps;
29+
popperProps?: PopperOptions;
4330
/** @beta Flag indicating the first menu item should be focused after opening the dropdown. */
4431
shouldFocusFirstItemOnOpen?: boolean;
4532
/** Flag indicating if scroll on focus of the first menu item should occur. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ propComponents:
1414
'MenuSearchInput',
1515
'MenuGroup',
1616
'MenuContainer',
17-
'MenuPopperProps',
18-
'TooltipProps'
17+
'TooltipProps',
18+
'PopperOptions'
1919
]
2020
ouia: true
2121
---
@@ -241,4 +241,4 @@ Router links can be used for in-app linking in React environments to prevent pag
241241
>
242242
{...Link Content}
243243
</MenuItem>
244-
```
244+
```

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
import { forwardRef, useEffect, useRef } from 'react';
22
import { css } from '@patternfly/react-styles';
33
import { Menu, MenuContent, MenuProps } from '../Menu';
4-
import { Popper } from '../../helpers/Popper/Popper';
4+
import { Popper, PopperOptions } from '../../helpers/Popper/Popper';
55
import { getOUIAProps, OUIAProps, getDefaultOUIAId, onToggleArrowKeydownDefault } from '../../helpers';
66

7-
export interface SelectPopperProps {
8-
/** Vertical direction of the popper. If enableFlip is set to true, this will set the initial direction before the popper flips. */
9-
direction?: 'up' | 'down';
10-
/** Horizontal position of the popper */
11-
position?: 'right' | 'left' | 'center' | 'start' | 'end';
12-
/** Custom width of the popper. If the value is "trigger", it will set the width to the select toggle's width */
13-
width?: string | 'trigger';
14-
/** Minimum width of the popper. If the value is "trigger", it will set the min width to the select toggle's width */
15-
minWidth?: string | 'trigger';
16-
/** Maximum width of the popper. If the value is "trigger", it will set the max width to the select toggle's width */
17-
maxWidth?: string | 'trigger';
18-
/** Enable to flip the popper when it reaches the boundary */
19-
enableFlip?: boolean;
20-
/** The container to append the select to. Defaults to document.body.
21-
* If your select is being cut off you can append it to an element higher up the DOM tree.
22-
* Some examples:
23-
* appendTo="inline"
24-
* appendTo={() => document.body}
25-
* appendTo={document.getElementById('target')}
26-
*/
27-
appendTo?: HTMLElement | (() => HTMLElement) | 'inline';
28-
/** Flag to prevent the popper from overflowing its container and becoming partially obscured. */
29-
preventOverflow?: boolean;
30-
}
7+
/** @deprecated Use PopperOptions instead */
8+
export type SelectPopperProps = PopperOptions;
319

3210
export interface SelectToggleProps {
3311
/** Select toggle node. */
@@ -75,7 +53,7 @@ export interface SelectProps extends MenuProps, OUIAProps {
7553
/** Determines the accessible role of the select. For a checkbox select pass in "menu". */
7654
role?: string;
7755
/** Additional properties to pass to the popper */
78-
popperProps?: SelectPopperProps;
56+
popperProps?: PopperOptions;
7957
/** Height of the select menu */
8058
menuHeight?: string;
8159
/** Maximum height of select menu */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ section: components
44
subsection: menus
55
cssPrefix: pf-v6-c-select
66
propComponents:
7-
['Select', 'SelectOption', 'SelectGroup', 'SelectList', 'MenuToggle', 'SelectToggleProps', 'SelectPopperProps']
7+
['Select', 'SelectOption', 'SelectGroup', 'SelectList', 'MenuToggle', 'SelectToggleProps', 'PopperOptions']
88
ouia: true
99
---
1010

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,14 @@ import { Fragment, useContext, useEffect, useRef, useState } from 'react';
22
import styles from '@patternfly/react-styles/css/components/Tabs/tabs';
33
import { css } from '@patternfly/react-styles';
44
import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon';
5-
import { Popper } from '../../helpers';
5+
import { Popper, PopperOptions } from '../../helpers';
66
import { Menu, MenuContent, MenuList, MenuItem } from '../Menu';
77
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-
}
11+
/** @deprecated Use PopperOptions instead */
12+
export type HorizontalOverflowPopperProps = PopperOptions;
3513

3614
export interface OverflowTabProps extends React.HTMLProps<HTMLLIElement> {
3715
/** Additional classes added to the overflow tab */
@@ -51,7 +29,7 @@ export interface OverflowTabProps extends React.HTMLProps<HTMLLIElement> {
5129
/** Time in ms to wait before firing the toggles' focus event. Defaults to 0 */
5230
focusTimeoutDelay?: number;
5331
/** Additional props to spread to the popper menu. */
54-
popperProps?: HorizontalOverflowPopperProps;
32+
popperProps?: PopperOptions;
5533
}
5634

5735
export const OverflowTab: React.FunctionComponent<OverflowTabProps> = ({

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

Lines changed: 27 additions & 27 deletions
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', 'HorizontalOverflowPopperProps', 'TabAction']
5+
propComponents: ['Tabs', 'Tab', 'TabContent', 'TabContentBody', 'TabTitleText', 'TabTitleIcon', 'HorizontalOverflowObject', 'TabAction', 'PopperOptions']
66
ouia: true
77
---
88

@@ -22,24 +22,24 @@ import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
2222

2323
A `<Tabs>` component contains multiple `<Tab>` components that may be used to navigate between sets of content within a page.
2424

25-
You can adjust a tab in the following ways:
25+
You can adjust a tab in the following ways:
2626

2727
- To label a tab with text, pass a `<TabTitleText>` component into the `title` property of a `<Tab>`.
28-
- To disable a tab, use the `isDisabled` property. Tabs using `isDisabled` are not perceivable or operable by users navigating via assistive technologies.
28+
- To disable a tab, use the `isDisabled` property. Tabs using `isDisabled` are not perceivable or operable by users navigating via assistive technologies.
2929
- To disable a tab, but keep it perceivable to assistive technology users, use the `isAriaDisabled` property. If a disabled tab has a tooltip, use this property instead of `isDisabled`.
30-
- To add a tooltip to an aria-disabled tab, use the `tooltip` property.
30+
- To add a tooltip to an aria-disabled tab, use the `tooltip` property.
3131

32-
Tabs can be styled as 'default' or 'boxed':
32+
Tabs can be styled as 'default' or 'boxed':
3333

34-
- Default tabs do not have any borders and use a bottom line to distinguish between a selected tab, a hovered tab, and an inactive tab.
34+
- Default tabs do not have any borders and use a bottom line to distinguish between a selected tab, a hovered tab, and an inactive tab.
3535
- Boxed tabs are outlined to emphasize the area that a tab spans. To preview boxed tabs in the following examples, select the 'isBox' checkbox, which sets the `isBox` property to true.
3636

3737
```ts file="./TabsDefault.tsx"
3838
```
3939

4040
### Boxed secondary tabs
4141

42-
To change the background color of boxed tabs or the tab content, use the `variant` property.
42+
To change the background color of boxed tabs or the tab content, use the `variant` property.
4343

4444
Toggle the tab color by selecting the 'Tabs secondary variant' checkbox in the following example.
4545

@@ -50,14 +50,14 @@ Toggle the tab color by selecting the 'Tabs secondary variant' checkbox in the f
5050

5151
Vertical tabs are placed on the left-hand side of a page or container and may appear in both 'default' and 'boxed' tab variations.
5252

53-
To style tabs vertically, use the `isVertical` property.
53+
To style tabs vertically, use the `isVertical` property.
5454

5555
```ts file="./TabsVertical.tsx"
5656
```
5757

5858
### Vertical expandable tabs
5959

60-
Vertical tabs can be made expandable to save space. Users can select the caret to expand a menu and switch between tabs.
60+
Vertical tabs can be made expandable to save space. Users can select the caret to expand a menu and switch between tabs.
6161

6262
Expandable tabs can be enabled at different breakpoints. The following example passes `expandable={{ default: 'expandable', md: 'nonExpandable', lg: 'expandable' }}` into the `<Tabs>` component.
6363

@@ -75,14 +75,14 @@ To flag the default expanded state for uncontrolled tabs, use the `defaultIsExpa
7575

7676
### Default overflow tabs
7777

78-
By default, overflow is applied when there are too many tabs for the width of the container they are in. This overflow can be navigated by side-scrolling within the tabs section, or by selecting the left and right arrows.
78+
By default, overflow is applied when there are too many tabs for the width of the container they are in. This overflow can be navigated by side-scrolling within the tabs section, or by selecting the left and right arrows.
7979

8080
```ts file="./TabsDefaultOverflow.tsx"
8181
```
8282

8383
### Horizontal overflow tabs
8484

85-
Horizontal overflow can be used instead of the default application. To navigate horizontal overflow tabs users can select the last tab, labeled “more”, to see the overflowed content.
85+
Horizontal overflow can be used instead of the default application. To navigate horizontal overflow tabs users can select the last tab, labeled “more”, to see the overflowed content.
8686

8787
To enable horizontal overflow, use the `isOverflowHorizontal` property.
8888

@@ -102,7 +102,7 @@ The tooltip should also have the `id` property passed in. The value of `id` shou
102102

103103
### Uncontrolled tabs
104104

105-
To allow the `<Tabs>` component to manage setting the active tab and displaying correct content itself, use uncontrolled tabs, as shown in the following example.
105+
To allow the `<Tabs>` component to manage setting the active tab and displaying correct content itself, use uncontrolled tabs, as shown in the following example.
106106

107107

108108
```ts file="./TabsUncontrolled.tsx"
@@ -124,7 +124,7 @@ To adjust the left padding of tabs, use the `usePageInsets` property. This prope
124124

125125
### With icons and text
126126

127-
You can render different content in the `title` property of a tab to add icons and text.
127+
You can render different content in the `title` property of a tab to add icons and text.
128128

129129
To add an icon to a tab, pass a `<TabTitleIcon>` component that contains the icon of your choice into the `title`. To use an icon alongside styled text, keep the text in the `<TabTitleText>` component.
130130

@@ -133,53 +133,53 @@ To add an icon to a tab, pass a `<TabTitleIcon>` component that contains the ico
133133

134134
### Subtabs
135135

136-
Use subtabs within other components, like modals. Subtabs have less visually prominent styling.
136+
Use subtabs within other components, like modals. Subtabs have less visually prominent styling.
137137

138-
To apply subtab styling to tabs, use the `isSubtab` property.
138+
To apply subtab styling to tabs, use the `isSubtab` property.
139139

140140
```ts file="./TabsSubtabs.tsx"
141141
```
142142

143143
### Filled tabs with icons
144144

145-
To allow tabs to fill the available width of the page section, use the `isFilled` property.
145+
To allow tabs to fill the available width of the page section, use the `isFilled` property.
146146

147147
```ts file="./TabsFilledWithIcons.tsx"
148148
```
149149

150150
### Tabs linked to nav elements
151151

152-
To let tabs link to nav elements, pass `{TabsComponent.nav}` into the `component` property.
152+
To let tabs link to nav elements, pass `{TabsComponent.nav}` into the `component` property.
153153

154-
Nav tabs should use the `href` property to link the tab to the URL of another page or page section. A tab with an `href` will render as an `<a>` instead of a `<button>`.
154+
Nav tabs should use the `href` property to link the tab to the URL of another page or page section. A tab with an `href` will render as an `<a>` instead of a `<button>`.
155155

156156
```ts file="./TabsNav.tsx"
157157
```
158158

159159
### Subtabs linked to nav elements
160160

161-
Subtabs can also link to nav elements.
161+
Subtabs can also link to nav elements.
162162

163163
```ts file="./TabsNavSubtab.tsx"
164164
```
165165

166166
### With separate content
167167

168-
If a `<TabContent>` component is defined outside of a `<Tabs>` component, use the `tabContentRef` and `tabContentId` properties
168+
If a `<TabContent>` component is defined outside of a `<Tabs>` component, use the `tabContentRef` and `tabContentId` properties
169169

170170
```ts file="./TabsSeparateContent.tsx"
171171
```
172172

173173
### With tab content with body and padding
174174

175-
To add a content body to a `<TabContent>` component, pass a `<TabContentBody>`. To add padding to the body section, use the `hasPadding` property.
175+
To add a content body to a `<TabContent>` component, pass a `<TabContentBody>`. To add padding to the body section, use the `hasPadding` property.
176176

177177
```ts file="./TabsContentWithBodyPadding.tsx"
178178
```
179179

180180
### Children mounting on click
181181

182-
To mount tab children (add to the DOM) when a tab is clicked, use the `mountOnEnter` property.
182+
To mount tab children (add to the DOM) when a tab is clicked, use the `mountOnEnter` property.
183183

184184
Note that this property does not create the tab children until the tab is clicked, so they are not preloaded into the DOM.
185185

@@ -197,30 +197,30 @@ To unmount tab children (remove from the DOM) when they are no longer visible, u
197197

198198
You may control tabs from outside of the tabs component. For example, select the "Hide tab 2" button below to make "Tab item 2" invisible.
199199

200-
The tab its content should only be mounted when the tab is visible.
200+
The tab its content should only be mounted when the tab is visible.
201201

202202
```ts file="./TabsToggledSeparateContent.tsx"
203203
```
204204

205205
### Dynamic tabs
206206

207-
To enable closeable tabs, pass the `onClose` property to the `<Tabs>` component. To enable a button that adds new tabs, pass the `onAdd` property to `<Tabs>`.
207+
To enable closeable tabs, pass the `onClose` property to the `<Tabs>` component. To enable a button that adds new tabs, pass the `onAdd` property to `<Tabs>`.
208208

209209
```ts file="./TabsDynamic.tsx"
210210
```
211211

212212
### With help action popover
213213

214-
You may add a help action to a tab to provide users with additional context in a popover.
214+
You may add a help action to a tab to provide users with additional context in a popover.
215215

216-
To render an action beside the tab content, use the `actions` property of a `<Tab>`. Pass a popover and a `<TabsAction>` component into the `actions` property.
216+
To render an action beside the tab content, use the `actions` property of a `<Tab>`. Pass a popover and a `<TabsAction>` component into the `actions` property.
217217

218218
```ts file="./TabsHelp.tsx"
219219
```
220220

221221
### With help and close actions
222222

223-
To add multiple actions to a tab, create a `<TabAction>` component for each action.
223+
To add multiple actions to a tab, create a `<TabAction>` component for each action.
224224

225225
The following example passes in both help popover and close actions.
226226

0 commit comments

Comments
 (0)