| 1 |
import { useState } from 'react'; |
| 2 |
import { Tabs, Tab, TabTitleText } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const TabsChildrenMounting: 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 |
|
| 14 |
return ( |
| 15 |
<Tabs |
| 16 |
mountOnEnter |
| 17 |
activeKey={activeTabKey} |
| 18 |
onSelect={handleTabClick} |
| 19 |
aria-label="Tabs in the children mounting on click example" |
| 20 |
role="region" |
| 21 |
> |
| 22 |
<Tab eventKey={0} title={<TabTitleText>Tab item 1</TabTitleText>} aria-label="Tab 1"> |
| 23 |
Tab 1 section |
| 24 |
</Tab> |
| 25 |
<Tab eventKey={1} title={<TabTitleText>Tab item 2</TabTitleText>} aria-label="Tab 2"> |
| 26 |
Tab 2 section |
| 27 |
</Tab> |
| 28 |
<Tab eventKey={2} title={<TabTitleText>Tab item 3</TabTitleText>} aria-label="Tab 3"> |
| 29 |
Tab 3 section |
| 30 |
</Tab> |
| 31 |
</Tabs> |
| 32 |
); |
| 33 |
}; |