Debian Codegraph @

node/@patternfly/react-core/src/components/Tabs/examples/TabsSeparateContent.tsx

raw
1 import { createRef, Fragment, useState } from 'react';
2 import { Tabs, Tab, TabTitleText, TabContent } from '@patternfly/react-core';
3
4 export const TabsSeparateContent: 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 const contentRef1 = createRef<HTMLElement>();
15 const contentRef2 = createRef<HTMLElement>();
16 const contentRef3 = createRef<HTMLElement>();
17
18 return (
19 <Fragment>
20 <Tabs
21 activeKey={activeTabKey}
22 onSelect={handleTabClick}
23 aria-label="Tabs in the separate content example"
24 role="region"
25 >
26 <Tab
27 eventKey={0}
28 title={<TabTitleText>Tab item 1</TabTitleText>}
29 tabContentId="refTab1Section"
30 tabContentRef={contentRef1}
31 />
32 <Tab
33 eventKey={1}
34 title={<TabTitleText>Tab item 2</TabTitleText>}
35 tabContentId="refTab2Section"
36 tabContentRef={contentRef2}
37 />
38 <Tab
39 eventKey={2}
40 title={<TabTitleText>Tab item 3</TabTitleText>}
41 tabContentId="refTab3Section"
42 tabContentRef={contentRef3}
43 />
44 </Tabs>
45 <div>
46 <TabContent
47 eventKey={0}
48 id="refTab1Section"
49 ref={contentRef1}
50 aria-label="This is content for the first separate content tab"
51 hidden={activeTabKey !== 0}
52 >
53 Tab 1 section
54 </TabContent>
55 <TabContent
56 eventKey={1}
57 id="refTab2Section"
58 ref={contentRef2}
59 aria-label="This is content for the second separate content tab"
60 hidden={activeTabKey !== 1}
61 >
62 Tab 2 section
63 </TabContent>
64 <TabContent
65 eventKey={2}
66 id="refTab3Section"
67 ref={contentRef3}
68 aria-label="This is content for the third separate content tab"
69 hidden={activeTabKey !== 2}
70 >
71 Tab 3 section
72 </TabContent>
73 </div>
74 </Fragment>
75 );
76 };