@patternfly/react-core 6.7.0-prerelease.7 → 6.7.1-prerelease.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/AboutModal/package.json +1 -1
- package/dist/dynamic/components/Accordion/package.json +1 -1
- package/dist/dynamic/components/ActionList/package.json +1 -1
- package/dist/dynamic/components/Alert/package.json +1 -1
- package/dist/dynamic/components/Avatar/package.json +1 -1
- package/dist/dynamic/components/BackToTop/package.json +1 -1
- package/dist/dynamic/components/Backdrop/package.json +1 -1
- package/dist/dynamic/components/BackgroundImage/package.json +1 -1
- package/dist/dynamic/components/Badge/package.json +1 -1
- package/dist/dynamic/components/Banner/package.json +1 -1
- package/dist/dynamic/components/Brand/package.json +1 -1
- package/dist/dynamic/components/Breadcrumb/package.json +1 -1
- package/dist/dynamic/components/Button/package.json +1 -1
- package/dist/dynamic/components/CalendarMonth/package.json +1 -1
- package/dist/dynamic/components/Card/package.json +1 -1
- package/dist/dynamic/components/Checkbox/package.json +1 -1
- package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
- package/dist/dynamic/components/CodeBlock/package.json +1 -1
- package/dist/dynamic/components/Compass/package.json +1 -1
- package/dist/dynamic/components/Content/package.json +1 -1
- package/dist/dynamic/components/DataList/package.json +1 -1
- package/dist/dynamic/components/DatePicker/package.json +1 -1
- package/dist/dynamic/components/DescriptionList/package.json +1 -1
- package/dist/dynamic/components/Divider/package.json +1 -1
- package/dist/dynamic/components/Drawer/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/components/EmptyState/package.json +1 -1
- package/dist/dynamic/components/ExpandableSection/package.json +1 -1
- package/dist/dynamic/components/FileUpload/package.json +1 -1
- package/dist/dynamic/components/Form/package.json +1 -1
- package/dist/dynamic/components/FormSelect/package.json +1 -1
- package/dist/dynamic/components/HelperText/package.json +1 -1
- package/dist/dynamic/components/Hero/package.json +1 -1
- package/dist/dynamic/components/Hint/package.json +1 -1
- package/dist/dynamic/components/Icon/package.json +1 -1
- package/dist/dynamic/components/InputGroup/package.json +1 -1
- package/dist/dynamic/components/JumpLinks/package.json +1 -1
- package/dist/dynamic/components/Label/package.json +1 -1
- package/dist/dynamic/components/List/package.json +1 -1
- package/dist/dynamic/components/LoginPage/package.json +1 -1
- package/dist/dynamic/components/Masthead/package.json +1 -1
- package/dist/dynamic/components/Menu/package.json +1 -1
- package/dist/dynamic/components/MenuToggle/package.json +1 -1
- package/dist/dynamic/components/Modal/package.json +1 -1
- package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
- package/dist/dynamic/components/Nav/package.json +1 -1
- package/dist/dynamic/components/NotificationBadge/package.json +1 -1
- package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
- package/dist/dynamic/components/NumberInput/package.json +1 -1
- package/dist/dynamic/components/OverflowMenu/package.json +1 -1
- package/dist/dynamic/components/Page/package.json +1 -1
- package/dist/dynamic/components/Pagination/package.json +1 -1
- package/dist/dynamic/components/Panel/package.json +1 -1
- package/dist/dynamic/components/Popover/package.json +1 -1
- package/dist/dynamic/components/Progress/package.json +1 -1
- package/dist/dynamic/components/ProgressStepper/package.json +1 -1
- package/dist/dynamic/components/Radio/package.json +1 -1
- package/dist/dynamic/components/SearchInput/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic/components/Sidebar/package.json +1 -1
- package/dist/dynamic/components/SimpleList/package.json +1 -1
- package/dist/dynamic/components/Skeleton/package.json +1 -1
- package/dist/dynamic/components/SkipToContent/package.json +1 -1
- package/dist/dynamic/components/Slider/package.json +1 -1
- package/dist/dynamic/components/Spinner/package.json +1 -1
- package/dist/dynamic/components/Switch/package.json +1 -1
- package/dist/dynamic/components/Tabs/package.json +1 -1
- package/dist/dynamic/components/TextArea/package.json +1 -1
- package/dist/dynamic/components/TextInput/package.json +1 -1
- package/dist/dynamic/components/TextInputGroup/package.json +1 -1
- package/dist/dynamic/components/TimePicker/package.json +1 -1
- package/dist/dynamic/components/Timestamp/package.json +1 -1
- package/dist/dynamic/components/Title/package.json +1 -1
- package/dist/dynamic/components/ToggleGroup/package.json +1 -1
- package/dist/dynamic/components/Toolbar/package.json +1 -1
- package/dist/dynamic/components/Tooltip/package.json +1 -1
- package/dist/dynamic/components/TreeView/package.json +1 -1
- package/dist/dynamic/components/Truncate/package.json +1 -1
- package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
- package/dist/dynamic/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/Chip/package.json +1 -1
- package/dist/dynamic/deprecated/components/DragDrop/package.json +1 -1
- package/dist/dynamic/deprecated/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/deprecated/components/Modal/package.json +1 -1
- package/dist/dynamic/deprecated/components/Tile/package.json +1 -1
- package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/dynamic/helpers/AnimationsProvider/AnimationsProvider/package.json +1 -1
- package/dist/dynamic/helpers/AnimationsProvider/package.json +1 -1
- package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
- package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
- package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
- package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
- package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
- package/dist/dynamic/helpers/SSRSafeIds/SSRSafeIds/package.json +1 -1
- package/dist/dynamic/helpers/constants/package.json +1 -1
- package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
- package/dist/dynamic/helpers/fileUtils/package.json +1 -1
- package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
- package/dist/dynamic/helpers/inert/package.json +1 -1
- package/dist/dynamic/helpers/package.json +1 -1
- package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
- package/dist/dynamic/helpers/typeUtils/package.json +1 -1
- package/dist/dynamic/helpers/useInterval/package.json +1 -1
- package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
- package/dist/dynamic/helpers/useSSRSafeId/package.json +1 -1
- package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
- package/dist/dynamic/helpers/util/package.json +1 -1
- package/dist/dynamic/layouts/Bullseye/package.json +1 -1
- package/dist/dynamic/layouts/Flex/package.json +1 -1
- package/dist/dynamic/layouts/Gallery/package.json +1 -1
- package/dist/dynamic/layouts/Grid/package.json +1 -1
- package/dist/dynamic/layouts/Level/package.json +1 -1
- package/dist/dynamic/layouts/Split/package.json +1 -1
- package/dist/dynamic/layouts/Stack/package.json +1 -1
- package/dist/dynamic/styles/package.json +1 -1
- package/dist/esm/components/Tabs/Tab.d.ts +3 -1
- package/dist/esm/components/Tabs/Tab.d.ts.map +1 -1
- package/dist/esm/components/Tabs/Tab.js +11 -3
- package/dist/esm/components/Tabs/Tab.js.map +1 -1
- package/dist/esm/components/Tabs/TabButton.d.ts +3 -1
- package/dist/esm/components/Tabs/TabButton.d.ts.map +1 -1
- package/dist/esm/components/Tabs/TabButton.js +3 -3
- package/dist/esm/components/Tabs/TabButton.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.d.ts +2 -2
- package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +4 -2
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/components/Tabs/TabsContext.d.ts +1 -1
- package/dist/esm/components/Tabs/TabsContext.d.ts.map +1 -1
- package/dist/esm/components/Tabs/TabsContext.js.map +1 -1
- package/dist/js/components/Tabs/Tab.d.ts +3 -1
- package/dist/js/components/Tabs/Tab.d.ts.map +1 -1
- package/dist/js/components/Tabs/Tab.js +11 -3
- package/dist/js/components/Tabs/Tab.js.map +1 -1
- package/dist/js/components/Tabs/TabButton.d.ts +3 -1
- package/dist/js/components/Tabs/TabButton.d.ts.map +1 -1
- package/dist/js/components/Tabs/TabButton.js +3 -3
- package/dist/js/components/Tabs/TabButton.js.map +1 -1
- package/dist/js/components/Tabs/Tabs.d.ts +2 -2
- package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/js/components/Tabs/Tabs.js +4 -2
- package/dist/js/components/Tabs/Tabs.js.map +1 -1
- package/dist/js/components/Tabs/TabsContext.d.ts +1 -1
- package/dist/js/components/Tabs/TabsContext.d.ts.map +1 -1
- package/dist/js/components/Tabs/TabsContext.js.map +1 -1
- package/dist/umd/assets/{output-Be1kBTeX.css → output-CC2rDgxR.css} +13892 -13892
- package/dist/umd/react-core.min.js +1 -1
- package/helpers/package.json +1 -1
- package/layouts/package.json +1 -1
- package/next/package.json +1 -1
- package/package.json +5 -5
- package/src/components/Tabs/Tab.tsx +18 -5
- package/src/components/Tabs/TabButton.tsx +6 -3
- package/src/components/Tabs/Tabs.tsx +8 -3
- package/src/components/Tabs/TabsContext.ts +2 -1
- package/src/components/Tabs/__tests__/TabButton.test.tsx +26 -1
- package/src/components/Tabs/__tests__/TabsCustomComponent.test.tsx +176 -0
- package/src/components/Tabs/examples/Tabs.md +38 -3
- package/src/components/Tabs/examples/TabsCustomComponent.tsx +57 -0
- package/src/demos/Page.md +5 -0
package/helpers/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.7.0
|
|
1
|
+
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"6.7.0","private":true}
|
package/layouts/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.7.0
|
|
1
|
+
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"6.7.0","private":true}
|
package/next/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.7.0
|
|
1
|
+
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"6.7.0","private":true}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.1-prerelease.0",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@patternfly/react-icons": "^6.7.0
|
|
50
|
-
"@patternfly/react-styles": "^6.7.0
|
|
51
|
-
"@patternfly/react-tokens": "^6.7.0
|
|
49
|
+
"@patternfly/react-icons": "^6.7.0",
|
|
50
|
+
"@patternfly/react-styles": "^6.7.0",
|
|
51
|
+
"@patternfly/react-tokens": "^6.7.0",
|
|
52
52
|
"focus-trap": "7.6.6",
|
|
53
53
|
"react-dropzone": "^14.3.5",
|
|
54
54
|
"tslib": "^2.8.1"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"react": "^17 || ^18 || ^19",
|
|
64
64
|
"react-dom": "^17 || ^18 || ^19"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "eb3b20788f36f06720acff42801ba07fe3b7992d"
|
|
67
67
|
}
|
|
@@ -14,8 +14,10 @@ export interface TabProps
|
|
|
14
14
|
children?: React.ReactNode;
|
|
15
15
|
/** additional classes added to the Tab */
|
|
16
16
|
className?: string;
|
|
17
|
-
/** URL associated with the Tab. A Tab with an href will render as an <a> instead of a <button
|
|
17
|
+
/** URL associated with the Tab. A Tab with an href will render as an <a> instead of a <button> unless component is supplied. */
|
|
18
18
|
href?: string;
|
|
19
|
+
/** Sets the element or custom component used for this Tab's button or link. Defaults to an anchor when href is supplied, otherwise a button. Does not change the Tabs container's outer wrapper. Custom components must forward the ref and supplied props to the underlying element. For custom components that render a button, pass type="button" or set it inside the component to prevent form submission. */
|
|
20
|
+
component?: React.ElementType<any> | React.ComponentType<any>;
|
|
19
21
|
/** Content rendered in the tab title. Should be <TabTitleText> and/or <TabTitleIcon> for proper styling. */
|
|
20
22
|
title: React.ReactNode;
|
|
21
23
|
/** uniquely identifies the tab */
|
|
@@ -58,11 +60,13 @@ const TabBase: React.FunctionComponent<TabProps> = ({
|
|
|
58
60
|
isAriaDisabled,
|
|
59
61
|
inoperableEvents = ['onClick', 'onKeyPress'],
|
|
60
62
|
href,
|
|
63
|
+
component = href ? 'a' : 'button',
|
|
61
64
|
innerRef,
|
|
62
65
|
tooltip,
|
|
63
66
|
closeButtonAriaLabel,
|
|
64
67
|
isCloseDisabled = false,
|
|
65
68
|
actions,
|
|
69
|
+
onClick,
|
|
66
70
|
...props
|
|
67
71
|
}: TabProps) => {
|
|
68
72
|
const preventedEvents = inoperableEvents.reduce(
|
|
@@ -80,7 +84,8 @@ const TabBase: React.FunctionComponent<TabProps> = ({
|
|
|
80
84
|
if ((mountOnEnter || unmountOnExit) && eventKey !== localActiveKey) {
|
|
81
85
|
ariaControls = undefined;
|
|
82
86
|
}
|
|
83
|
-
const isButtonElement =
|
|
87
|
+
const isButtonElement = component === 'button';
|
|
88
|
+
const isCustomComponent = component !== 'a' && !isButtonElement;
|
|
84
89
|
const getDefaultTabIdx = () => {
|
|
85
90
|
if (isDisabled) {
|
|
86
91
|
return isButtonElement ? null : -1;
|
|
@@ -94,22 +99,30 @@ const TabBase: React.FunctionComponent<TabProps> = ({
|
|
|
94
99
|
parentInnerRef={innerRef}
|
|
95
100
|
className={css(
|
|
96
101
|
styles.tabsLink,
|
|
97
|
-
isDisabled &&
|
|
102
|
+
isDisabled && !isButtonElement && styles.modifiers.disabled,
|
|
98
103
|
isAriaDisabled && styles.modifiers.ariaDisabled
|
|
99
104
|
)}
|
|
100
105
|
disabled={isButtonElement ? isDisabled : null}
|
|
101
106
|
aria-disabled={isDisabled || isAriaDisabled}
|
|
102
107
|
tabIndex={getDefaultTabIdx()}
|
|
103
|
-
onClick={(event: any) => handleTabClick(event, eventKey, tabContentRef)}
|
|
104
|
-
{...(isAriaDisabled ? preventedEvents : null)}
|
|
105
108
|
id={`pf-tab-${eventKey}-${childId || uniqueId}`}
|
|
106
109
|
aria-controls={ariaControls}
|
|
107
110
|
tabContentRef={tabContentRef}
|
|
108
111
|
ouiaId={childOuiaId}
|
|
109
112
|
href={href}
|
|
113
|
+
component={component}
|
|
110
114
|
role="tab"
|
|
111
115
|
aria-selected={eventKey === localActiveKey}
|
|
112
116
|
{...props}
|
|
117
|
+
onClick={(event: any) => {
|
|
118
|
+
if (isDisabled) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
handleTabClick(event, eventKey, tabContentRef, isCustomComponent);
|
|
123
|
+
onClick?.(event);
|
|
124
|
+
}}
|
|
125
|
+
{...(isAriaDisabled || (isDisabled && !isButtonElement) ? preventedEvents : null)}
|
|
113
126
|
>
|
|
114
127
|
{title}
|
|
115
128
|
</TabButton>
|
|
@@ -5,8 +5,10 @@ export interface TabButtonProps extends Omit<React.HTMLProps<HTMLAnchorElement |
|
|
|
5
5
|
children?: React.ReactNode;
|
|
6
6
|
/** additional classes added to the Tab */
|
|
7
7
|
className?: string;
|
|
8
|
-
/** URL associated with the Tab. A Tab with an href will render as an <a> instead of a <button
|
|
8
|
+
/** URL associated with the Tab. A Tab with an href will render as an <a> instead of a <button> unless component is supplied. */
|
|
9
9
|
href?: string;
|
|
10
|
+
/** Sets the element or custom component used for the tab's button or link. Defaults to an anchor when href is supplied, otherwise a button. For custom components that render a button, pass type="button" or set it inside the component to prevent form submission. */
|
|
11
|
+
component?: React.ElementType<any> | React.ComponentType<any>;
|
|
10
12
|
/** child reference for case in which a TabContent section is defined outside of a Tabs component */
|
|
11
13
|
tabContentRef?: React.Ref<any>;
|
|
12
14
|
/** Parents' innerRef passed down for properly displaying Tooltips */
|
|
@@ -20,13 +22,14 @@ export const TabButton: React.FunctionComponent<TabButtonProps> = ({
|
|
|
20
22
|
ouiaId,
|
|
21
23
|
parentInnerRef,
|
|
22
24
|
ouiaSafe,
|
|
25
|
+
component,
|
|
23
26
|
...props
|
|
24
27
|
}: TabButtonProps) => {
|
|
25
|
-
const Component = (props.href ? 'a' : 'button') as any;
|
|
28
|
+
const Component = (component || (props.href ? 'a' : 'button')) as any;
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
31
|
<Component
|
|
29
|
-
{...(
|
|
32
|
+
{...(Component === 'button' && { type: 'button' })}
|
|
30
33
|
ref={parentInnerRef}
|
|
31
34
|
{...getOUIAProps(TabButton.displayName, ouiaId, ouiaSafe)}
|
|
32
35
|
{...props}
|
|
@@ -89,7 +89,7 @@ export interface TabsProps
|
|
|
89
89
|
backScrollAriaLabel?: string;
|
|
90
90
|
/** Aria-label for the forward scroll button */
|
|
91
91
|
forwardScrollAriaLabel?: string;
|
|
92
|
-
/** Determines
|
|
92
|
+
/** Determines the outer wrapper element for the Tabs container. Use "nav" to define a navigation region. To customize an individual tab's button or link, use the component property of Tab instead. */
|
|
93
93
|
component?: 'div' | 'nav';
|
|
94
94
|
/** 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. */
|
|
95
95
|
'aria-label'?: string;
|
|
@@ -242,12 +242,17 @@ class Tabs extends Component<TabsProps, TabsState> {
|
|
|
242
242
|
handleTabClick(
|
|
243
243
|
event: React.MouseEvent<HTMLElement, MouseEvent>,
|
|
244
244
|
eventKey: number | string,
|
|
245
|
-
tabContentRef: React.RefObject<any
|
|
245
|
+
tabContentRef: React.RefObject<any>,
|
|
246
|
+
isCustomComponent = false
|
|
246
247
|
) {
|
|
247
248
|
const { shownKeys, initialActiveKey } = this.state;
|
|
248
249
|
const { onSelect, defaultActiveKey, component, isNav } = this.props;
|
|
249
250
|
|
|
250
|
-
if (
|
|
251
|
+
if (
|
|
252
|
+
!isCustomComponent &&
|
|
253
|
+
event.currentTarget instanceof HTMLAnchorElement &&
|
|
254
|
+
event.currentTarget.hasAttribute('href')
|
|
255
|
+
) {
|
|
251
256
|
event.preventDefault();
|
|
252
257
|
|
|
253
258
|
if (canUseDOM && (component === TabsComponent.nav || isNav)) {
|
|
@@ -10,7 +10,8 @@ export interface TabsContextProps {
|
|
|
10
10
|
handleTabClick: (
|
|
11
11
|
event: React.MouseEvent<HTMLElement, MouseEvent>,
|
|
12
12
|
eventKey: number | string,
|
|
13
|
-
tabContentRef: React.RefObject<any
|
|
13
|
+
tabContentRef: React.RefObject<any>,
|
|
14
|
+
isCustomComponent?: boolean
|
|
14
15
|
) => void;
|
|
15
16
|
handleTabClose?: (
|
|
16
17
|
event: React.MouseEvent<HTMLElement, MouseEvent>,
|
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import { TabButton } from '../TabButton';
|
|
3
3
|
|
|
4
4
|
test('should render tab button', () => {
|
|
5
5
|
const { asFragment } = render(<TabButton>Tab button</TabButton>);
|
|
6
6
|
expect(asFragment()).toMatchSnapshot();
|
|
7
7
|
});
|
|
8
|
+
|
|
9
|
+
test('renders an anchor by default when href is supplied', () => {
|
|
10
|
+
render(<TabButton href="#tab">Tab link</TabButton>);
|
|
11
|
+
expect(screen.getByRole('link')).toHaveAttribute('href', '#tab');
|
|
12
|
+
expect(screen.getByRole('link')).not.toHaveAttribute('type');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('uses the explicit component instead of the href-based default', () => {
|
|
16
|
+
render(
|
|
17
|
+
<TabButton component="button" href="#tab">
|
|
18
|
+
Tab button
|
|
19
|
+
</TabButton>
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByRole('button')).toHaveAttribute('type', 'button');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('renders an explicit anchor without button-specific attributes', () => {
|
|
25
|
+
render(
|
|
26
|
+
<TabButton component="a" role="tab">
|
|
27
|
+
Tab link
|
|
28
|
+
</TabButton>
|
|
29
|
+
);
|
|
30
|
+
expect(screen.getByRole('tab').tagName).toBe('A');
|
|
31
|
+
expect(screen.getByRole('tab')).not.toHaveAttribute('type');
|
|
32
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Generated with OpenCode (GPT-6.1).
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { createRef, forwardRef } from 'react';
|
|
5
|
+
import { Tabs } from '../Tabs';
|
|
6
|
+
import { Tab } from '../Tab';
|
|
7
|
+
|
|
8
|
+
const onNavigate = jest.fn();
|
|
9
|
+
// Router links invoke the supplied handler before navigating, and honor preventDefault.
|
|
10
|
+
const CustomLink = forwardRef<HTMLAnchorElement, React.ComponentPropsWithoutRef<'a'>>(
|
|
11
|
+
({ onClick, href = '#custom-link', ...props }, ref) => (
|
|
12
|
+
<a
|
|
13
|
+
{...props}
|
|
14
|
+
href={href}
|
|
15
|
+
ref={ref}
|
|
16
|
+
onClick={(event) => {
|
|
17
|
+
onClick?.(event);
|
|
18
|
+
if (!event.defaultPrevented) {
|
|
19
|
+
onNavigate();
|
|
20
|
+
}
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
CustomLink.displayName = 'CustomLink';
|
|
27
|
+
|
|
28
|
+
const CustomButton = forwardRef<HTMLButtonElement, React.ComponentPropsWithoutRef<'button'>>((props, ref) => (
|
|
29
|
+
<button {...props} ref={ref} />
|
|
30
|
+
));
|
|
31
|
+
CustomButton.displayName = 'CustomButton';
|
|
32
|
+
|
|
33
|
+
describe('custom tab components', () => {
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.restoreAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it.each([
|
|
39
|
+
{ description: 'default tabs without href', tabsProps: {}, href: undefined },
|
|
40
|
+
{ description: 'default tabs with href', tabsProps: {}, href: '#custom-link' },
|
|
41
|
+
{ description: 'nav wrapper without href', tabsProps: { component: 'nav' as const }, href: undefined },
|
|
42
|
+
{ description: 'nav wrapper with href', tabsProps: { component: 'nav' as const }, href: '#custom-link' },
|
|
43
|
+
{ description: 'nav styling without href', tabsProps: { isNav: true }, href: undefined },
|
|
44
|
+
{ description: 'nav styling with href', tabsProps: { isNav: true }, href: '#custom-link' }
|
|
45
|
+
])('allows custom navigation and tab selection for $description', async ({ tabsProps, href }) => {
|
|
46
|
+
const user = userEvent.setup();
|
|
47
|
+
const pushState = jest.spyOn(window.history, 'pushState');
|
|
48
|
+
const ref = createRef<HTMLAnchorElement>();
|
|
49
|
+
|
|
50
|
+
render(
|
|
51
|
+
<Tabs defaultActiveKey={0} {...tabsProps}>
|
|
52
|
+
<Tab eventKey={0} title="First tab" />
|
|
53
|
+
<Tab eventKey={1} title="Custom tab" component={CustomLink} href={href} ref={ref}>
|
|
54
|
+
Custom content
|
|
55
|
+
</Tab>
|
|
56
|
+
</Tabs>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const tab = screen.getByRole('tab', { name: 'Custom tab' });
|
|
60
|
+
expect(ref.current).toBe(tab);
|
|
61
|
+
expect(tab).toHaveAttribute('href', '#custom-link');
|
|
62
|
+
expect(tab).not.toHaveAttribute('type');
|
|
63
|
+
expect(tab).not.toHaveAttribute('disabled');
|
|
64
|
+
|
|
65
|
+
await user.click(tab);
|
|
66
|
+
|
|
67
|
+
expect(onNavigate).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(pushState).not.toHaveBeenCalled();
|
|
69
|
+
expect(tab).toHaveAttribute('aria-selected', 'true');
|
|
70
|
+
expect(screen.getByRole('tabpanel')).toHaveTextContent('Custom content');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('calls onSelect when clicking a controlled custom tab', async () => {
|
|
74
|
+
const user = userEvent.setup();
|
|
75
|
+
const onSelect = jest.fn();
|
|
76
|
+
const onClick = jest.fn();
|
|
77
|
+
render(
|
|
78
|
+
<Tabs activeKey={0} onSelect={onSelect}>
|
|
79
|
+
<Tab eventKey={0} title="First tab" />
|
|
80
|
+
<Tab eventKey={1} title="Custom tab" component={CustomLink} onClick={onClick} />
|
|
81
|
+
</Tabs>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
await user.click(screen.getByRole('tab', { name: 'Custom tab' }));
|
|
85
|
+
|
|
86
|
+
expect(onSelect).toHaveBeenCalledWith(expect.any(Object), 1);
|
|
87
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(onNavigate).toHaveBeenCalledTimes(1);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('allows a caller to prevent custom navigation without replacing tab selection', async () => {
|
|
92
|
+
const user = userEvent.setup();
|
|
93
|
+
const onSelect = jest.fn();
|
|
94
|
+
render(
|
|
95
|
+
<Tabs onSelect={onSelect}>
|
|
96
|
+
<Tab eventKey={1} title="Custom tab" component={CustomLink} onClick={(event) => event.preventDefault()} />
|
|
97
|
+
</Tabs>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
await user.click(screen.getByRole('tab', { name: 'Custom tab' }));
|
|
101
|
+
|
|
102
|
+
expect(onSelect).toHaveBeenCalledWith(expect.any(Object), 1);
|
|
103
|
+
expect(onNavigate).not.toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('selects a custom button tab without submitting its form when type="button" is supplied', async () => {
|
|
107
|
+
const user = userEvent.setup();
|
|
108
|
+
const onSubmit = jest.fn();
|
|
109
|
+
render(
|
|
110
|
+
<form
|
|
111
|
+
onSubmit={(event) => {
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
onSubmit();
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<Tabs defaultActiveKey={0}>
|
|
117
|
+
<Tab eventKey={0} title="First tab" />
|
|
118
|
+
<Tab eventKey={1} title="Custom button tab" component={CustomButton} type="button">
|
|
119
|
+
Custom button content
|
|
120
|
+
</Tab>
|
|
121
|
+
</Tabs>
|
|
122
|
+
</form>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const tab = screen.getByRole('tab', { name: 'Custom button tab' });
|
|
126
|
+
expect(tab).toHaveAttribute('type', 'button');
|
|
127
|
+
|
|
128
|
+
await user.click(tab);
|
|
129
|
+
await user.keyboard('{Enter}');
|
|
130
|
+
|
|
131
|
+
expect(tab).toHaveAttribute('aria-selected', 'true');
|
|
132
|
+
expect(screen.getByRole('tabpanel')).toHaveTextContent('Custom button content');
|
|
133
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it.each([
|
|
137
|
+
{ description: 'disabled', disabledProps: { isDisabled: true }, tabIndex: '-1' },
|
|
138
|
+
{ description: 'aria-disabled', disabledProps: { isAriaDisabled: true }, tabIndex: null }
|
|
139
|
+
])('prevents mouse and keyboard navigation for a $description custom link', async ({ disabledProps, tabIndex }) => {
|
|
140
|
+
const user = userEvent.setup();
|
|
141
|
+
const onSelect = jest.fn();
|
|
142
|
+
const onClick = jest.fn();
|
|
143
|
+
const onKeyPress = jest.fn();
|
|
144
|
+
render(
|
|
145
|
+
<Tabs onSelect={onSelect}>
|
|
146
|
+
<Tab
|
|
147
|
+
eventKey={0}
|
|
148
|
+
title="Custom tab"
|
|
149
|
+
component={CustomLink}
|
|
150
|
+
onClick={onClick}
|
|
151
|
+
onKeyPress={onKeyPress}
|
|
152
|
+
{...disabledProps}
|
|
153
|
+
/>
|
|
154
|
+
</Tabs>
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const tab = screen.getByRole('tab', { name: 'Custom tab' });
|
|
158
|
+
expect(tab).toHaveAttribute('aria-disabled', 'true');
|
|
159
|
+
expect(tab).not.toHaveAttribute('disabled');
|
|
160
|
+
if (tabIndex) {
|
|
161
|
+
expect(tab).toHaveAttribute('tabindex', tabIndex);
|
|
162
|
+
} else {
|
|
163
|
+
await user.tab();
|
|
164
|
+
expect(tab).toHaveFocus();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await user.click(tab);
|
|
168
|
+
tab.focus();
|
|
169
|
+
await user.keyboard('{Enter}');
|
|
170
|
+
|
|
171
|
+
expect(onNavigate).not.toHaveBeenCalled();
|
|
172
|
+
expect(onSelect).not.toHaveBeenCalled();
|
|
173
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
174
|
+
expect(onKeyPress).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
@@ -17,7 +17,7 @@ propComponents:
|
|
|
17
17
|
ouia: true
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
-
import { createRef, Fragment, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { createRef, forwardRef, Fragment, useEffect, useRef, useState } from 'react';
|
|
21
21
|
import RhUiUsersFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-users-fill-icon';
|
|
22
22
|
import RhUiContainerFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-container-fill-icon';
|
|
23
23
|
import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon';
|
|
@@ -175,9 +175,9 @@ To allow tabs to fill the available width of the page section, use the `isFilled
|
|
|
175
175
|
|
|
176
176
|
### Tabs linked to nav elements
|
|
177
177
|
|
|
178
|
-
To
|
|
178
|
+
To render the `<Tabs>` container inside a navigation region, pass `{TabsComponent.nav}` into the `component` property of `<Tabs>`. This property controls the outer wrapper, not the individual tab links.
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
In this example, each `<Tab>` uses `href` to render its clickable element as an `<a>` instead of a `<button>`. To use a router link instead, see the [custom component example](#custom-component).
|
|
181
181
|
|
|
182
182
|
```ts file="./TabsNav.tsx"
|
|
183
183
|
|
|
@@ -199,6 +199,20 @@ Site navigation tabs
|
|
|
199
199
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
+
### Custom component
|
|
203
|
+
|
|
204
|
+
Pass `component={CustomLink}` to an individual `<Tab>` to replace its button or anchor with a custom component. This is separate from `<Tabs component={TabsComponent.nav}>`, which controls the outer wrapper.
|
|
205
|
+
|
|
206
|
+
The custom component must forward the supplied props and ref to its underlying element. `<Tabs>` continues handling selection, while the custom component handles navigation.
|
|
207
|
+
|
|
208
|
+
For a custom component that renders a `<button>`, pass `type="button"` to `<Tab>` or set it inside the custom component to prevent form submission. Tabs cannot determine which element a custom component renders, so it only supplies a default button type for `component="button"`.
|
|
209
|
+
|
|
210
|
+
The following example uses a custom anchor and prevents default browser navigation so you can try tab selection without leaving the example. For integration with a router, see [using router links](#using-router-links).
|
|
211
|
+
|
|
212
|
+
```ts file="./TabsCustomComponent.tsx"
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
|
|
202
216
|
### With separate content
|
|
203
217
|
|
|
204
218
|
If a `<TabContent>` component is defined outside of a `<Tabs>` component, use the `tabContentRef` and `tabContentId` properties. The `hidden` property is used on `TabContent` to set the initial visible content.
|
|
@@ -270,3 +284,24 @@ The following example passes in both help popover and close actions.
|
|
|
270
284
|
```ts file="./TabsHelpAndClose.tsx"
|
|
271
285
|
|
|
272
286
|
```
|
|
287
|
+
|
|
288
|
+
## Using router links
|
|
289
|
+
|
|
290
|
+
Router links can be used for in-app navigation without reloading the page. Following the [custom component example](#custom-component), pass a component that wraps your router's `Link` to the `component` property of `<Tab>`. This wrapper maps the tab's `href` to the router's `to` property and forwards the supplied props and ref.
|
|
291
|
+
|
|
292
|
+
```nolive
|
|
293
|
+
const RouterTabLink = forwardRef<HTMLAnchorElement, React.ComponentPropsWithoutRef<'a'>>(
|
|
294
|
+
({ href = '/', ...props }, ref) => <Link {...props} to={href} ref={ref} />
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
<Tab
|
|
298
|
+
eventKey="users"
|
|
299
|
+
title={<TabTitleText>Users</TabTitleText>}
|
|
300
|
+
component={RouterTabLink}
|
|
301
|
+
href="/users"
|
|
302
|
+
/>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Define the wrapper outside the parent component so re-renders preserve the link element and keyboard focus.
|
|
306
|
+
|
|
307
|
+
When the current route determines which tab is selected, use it to set the `activeKey` property of `<Tabs>`.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Generated with OpenCode (GPT-6.1).
|
|
2
|
+
import { forwardRef, useState } from 'react';
|
|
3
|
+
import { Tabs, Tab, TabTitleText } from '@patternfly/react-core';
|
|
4
|
+
|
|
5
|
+
// This custom link stands in for a router link without requiring a router in the example.
|
|
6
|
+
const CustomTabLink = forwardRef<HTMLAnchorElement, React.ComponentPropsWithoutRef<'a'>>(
|
|
7
|
+
({ onClick, ...props }, ref) => (
|
|
8
|
+
<a
|
|
9
|
+
{...props}
|
|
10
|
+
ref={ref}
|
|
11
|
+
onClick={(event) => {
|
|
12
|
+
onClick?.(event);
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
}}
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
);
|
|
18
|
+
CustomTabLink.displayName = 'CustomTabLink';
|
|
19
|
+
|
|
20
|
+
export const TabsCustomComponent: React.FunctionComponent = () => {
|
|
21
|
+
const [activeTabKey, setActiveTabKey] = useState<string | number>(0);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Tabs
|
|
25
|
+
activeKey={activeTabKey}
|
|
26
|
+
onSelect={(_event, eventKey) => setActiveTabKey(eventKey)}
|
|
27
|
+
isNav
|
|
28
|
+
aria-label="Tabs with custom links example"
|
|
29
|
+
>
|
|
30
|
+
<Tab eventKey={0} title={<TabTitleText>Users</TabTitleText>} component={CustomTabLink} href="#custom-users">
|
|
31
|
+
Users
|
|
32
|
+
</Tab>
|
|
33
|
+
<Tab
|
|
34
|
+
eventKey={1}
|
|
35
|
+
title={<TabTitleText>Containers</TabTitleText>}
|
|
36
|
+
component={CustomTabLink}
|
|
37
|
+
href="#custom-containers"
|
|
38
|
+
>
|
|
39
|
+
Containers
|
|
40
|
+
</Tab>
|
|
41
|
+
<Tab
|
|
42
|
+
eventKey={2}
|
|
43
|
+
title={<TabTitleText>Disabled</TabTitleText>}
|
|
44
|
+
component={CustomTabLink}
|
|
45
|
+
href="#custom-disabled"
|
|
46
|
+
isDisabled
|
|
47
|
+
/>
|
|
48
|
+
<Tab
|
|
49
|
+
eventKey={3}
|
|
50
|
+
title={<TabTitleText>ARIA disabled</TabTitleText>}
|
|
51
|
+
component={CustomTabLink}
|
|
52
|
+
href="#custom-aria-disabled"
|
|
53
|
+
isAriaDisabled
|
|
54
|
+
/>
|
|
55
|
+
</Tabs>
|
|
56
|
+
);
|
|
57
|
+
};
|
package/src/demos/Page.md
CHANGED
|
@@ -23,6 +23,11 @@ import swaggerIcon from '@patternfly/react-core/src/demos/assets/camel-swagger-j
|
|
|
23
23
|
import azureIcon from '@patternfly/react-core/src/demos/assets/FuseConnector_Icons_AzureServices.png';
|
|
24
24
|
import restIcon from '@patternfly/react-core/src/demos/assets/FuseConnector_Icons_REST.png';
|
|
25
25
|
import { data } from '@patternfly/react-core/src/demos/CardView/examples/CardViewData.jsx';
|
|
26
|
+
import RhUiSettingsFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-settings-fill-icon';
|
|
27
|
+
import RhUiQuestionMarkCircleIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-question-mark-circle-icon';
|
|
28
|
+
import RhUiQuestionMarkCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-question-mark-circle-fill-icon';
|
|
29
|
+
import pfLogo from '@patternfly/react-core/src/demos/assets/PF-HorizontalLogo-Color.svg';
|
|
30
|
+
import imgAvatar from '@patternfly/react-core/src/components/assets/avatarImg.svg';
|
|
26
31
|
|
|
27
32
|
- All examples set the `isManagedSidebar` prop on the Page component to have the sidebar automatically close for smaller screen widths. You can also manually control this behavior by not adding the `isManagedSidebar` prop and instead:
|
|
28
33
|
1. Add an onNavToggle callback to PageHeader
|