Skip to content

Commit 190e749

Browse files
feat: Added Tab updates for site Navigation (#12111)
* feat: Added updates for site Navigation * Update packages/react-core/src/components/Tabs/examples/TabsSiteNav.tsx Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> * Updated with changes to allow a div to be set when using isNav. * Updated the code with feedback from reviews. --------- Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
1 parent 0f921f1 commit 190e749

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ class Tabs extends Component<TabsProps, TabsState> {
206206
backScrollAriaLabel: 'Scroll back',
207207
rightScrollAriaLabel: 'Scroll right',
208208
forwardScrollAriaLabel: 'Scroll forward',
209-
component: TabsComponent.div,
210209
mountOnEnter: false,
211210
unmountOnExit: false,
212211
ouiaSafe: true,
@@ -529,7 +528,8 @@ class Tabs extends Component<TabsProps, TabsState> {
529528
const overflowingTabProps = filteredChildrenOverflowing.map((child: React.ReactElement<TabProps>) => child.props);
530529

531530
const uniqueId = id || getUniqueId();
532-
const Component: any = component === TabsComponent.nav ? 'nav' : 'div';
531+
const defaultComponent = isNav && !component ? 'nav' : 'div';
532+
const Component: any = component !== undefined ? component : defaultComponent;
533533
const localActiveKey = defaultActiveKey !== undefined ? uncontrolledActiveKey : activeKey;
534534

535535
const isExpandedLocal = defaultIsExpanded !== undefined ? uncontrolledIsExpandedLocal : isExpanded;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ Subtabs can also link to nav elements.
189189

190190
```
191191

192+
### Tabs used for site navigation
193+
194+
Site navigation tabs
195+
196+
```ts file="./TabsSiteNav.tsx"
197+
198+
```
199+
192200
### With separate content
193201

194202
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.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { useState } from 'react';
2+
import { Tabs, Tab, TabTitleText } from '@patternfly/react-core';
3+
4+
export const TabsSiteNav: React.FunctionComponent = () => {
5+
const [activeTabKey, setActiveTabKey] = useState<string | number>(0);
6+
// Toggle currently active tab
7+
const handleTabClick = (
8+
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent,
9+
tabIndex: string | number
10+
) => {
11+
setActiveTabKey(tabIndex);
12+
};
13+
return (
14+
<Tabs
15+
activeKey={activeTabKey}
16+
onSelect={handleTabClick}
17+
isNav={true}
18+
aria-label="Site navigation with nav styling example"
19+
>
20+
<Tab eventKey={0} title={<TabTitleText>Users</TabTitleText>} href="#users" aria-label="Nav element content users">
21+
Users
22+
</Tab>
23+
<Tab eventKey={1} title={<TabTitleText>Containers</TabTitleText>} href="#containers">
24+
Containers
25+
</Tab>
26+
<Tab eventKey={2} title={<TabTitleText>Database</TabTitleText>} href="#database">
27+
Database
28+
</Tab>
29+
<Tab eventKey={3} title={<TabTitleText>Disabled</TabTitleText>} isDisabled href="#disabled">
30+
Disabled
31+
</Tab>
32+
<Tab eventKey={4} title={<TabTitleText>ARIA Disabled</TabTitleText>} isAriaDisabled href="#aria-disabled">
33+
ARIA Disabled
34+
</Tab>
35+
<Tab eventKey={6} title={<TabTitleText>Network</TabTitleText>} href="#network">
36+
Network
37+
</Tab>
38+
</Tabs>
39+
);
40+
};

0 commit comments

Comments
 (0)