Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ class Tabs extends Component<TabsProps, TabsState> {
backScrollAriaLabel: 'Scroll back',
rightScrollAriaLabel: 'Scroll right',
forwardScrollAriaLabel: 'Scroll forward',
component: TabsComponent.div,
mountOnEnter: false,
unmountOnExit: false,
ouiaSafe: true,
Expand Down Expand Up @@ -529,7 +528,8 @@ class Tabs extends Component<TabsProps, TabsState> {
const overflowingTabProps = filteredChildrenOverflowing.map((child: React.ReactElement<TabProps>) => child.props);

const uniqueId = id || getUniqueId();
const Component: any = component === TabsComponent.nav ? 'nav' : 'div';
const defaultComponent = isNav && !component ? 'nav' : 'div';
const Component: any = component === TabsComponent.nav || (isNav && component !== 'div') ? 'nav' : defaultComponent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

532's logic is a little confusing to me, would this be equivalent and slightly cleaner?
const Component: any = component !== undefined ? component : defaultComponent;

Because defaultComponent is already set to "nav" for isNav and "div" otherwise, and if TabsComponent.nav is passed in that's should already be setting it to "nav".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's the part re "this could be cleaned up Im sure" 😆 Using the logic you mention does work the same so using that would be better

const localActiveKey = defaultActiveKey !== undefined ? uncontrolledActiveKey : activeKey;

const isExpandedLocal = defaultIsExpanded !== undefined ? uncontrolledIsExpandedLocal : isExpanded;
Expand Down
8 changes: 8 additions & 0 deletions packages/react-core/src/components/Tabs/examples/Tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ Subtabs can also link to nav elements.

```

### Tabs used for site navigation

Site navigation tabs

```ts file="./TabsSiteNav.tsx"

```

### With separate content

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.
Expand Down
40 changes: 40 additions & 0 deletions packages/react-core/src/components/Tabs/examples/TabsSiteNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from 'react';
import { Tabs, Tab, TabTitleText } from '@patternfly/react-core';

export const TabsSiteNav: React.FunctionComponent = () => {
const [activeTabKey, setActiveTabKey] = useState<string | number>(0);
// Toggle currently active tab
const handleTabClick = (
event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent,
tabIndex: string | number
) => {
setActiveTabKey(tabIndex);
};
return (
<Tabs
activeKey={activeTabKey}
onSelect={handleTabClick}
isNav={true}
aria-label="Site navigation with nav styling example"
>
<Tab eventKey={0} title={<TabTitleText>Users</TabTitleText>} href="#users" aria-label="Nav element content users">
Users
</Tab>
<Tab eventKey={1} title={<TabTitleText>Containers</TabTitleText>} href="#containers">
Containers
</Tab>
<Tab eventKey={2} title={<TabTitleText>Database</TabTitleText>} href="#database">
Database
</Tab>
<Tab eventKey={3} title={<TabTitleText>Disabled</TabTitleText>} isDisabled href="#disabled">
Disabled
</Tab>
<Tab eventKey={4} title={<TabTitleText>ARIA Disabled</TabTitleText>} isAriaDisabled href="#aria-disabled">
ARIA Disabled
</Tab>
<Tab eventKey={6} title={<TabTitleText>Network</TabTitleText>} href="#network">
Network
</Tab>
</Tabs>
);
};
Loading