forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabsSeparateContent.tsx
More file actions
76 lines (73 loc) · 2.18 KB
/
TabsSeparateContent.tsx
File metadata and controls
76 lines (73 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { createRef, Fragment, useState } from 'react';
import { Tabs, Tab, TabTitleText, TabContent } from '@patternfly/react-core';
export const TabsSeparateContent: 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);
};
const contentRef1 = createRef<HTMLElement>();
const contentRef2 = createRef<HTMLElement>();
const contentRef3 = createRef<HTMLElement>();
return (
<Fragment>
<Tabs
activeKey={activeTabKey}
onSelect={handleTabClick}
aria-label="Tabs in the separate content example"
role="region"
>
<Tab
eventKey={0}
title={<TabTitleText>Tab item 1</TabTitleText>}
tabContentId="refTab1Section"
tabContentRef={contentRef1}
/>
<Tab
eventKey={1}
title={<TabTitleText>Tab item 2</TabTitleText>}
tabContentId="refTab2Section"
tabContentRef={contentRef2}
/>
<Tab
eventKey={2}
title={<TabTitleText>Tab item 3</TabTitleText>}
tabContentId="refTab3Section"
tabContentRef={contentRef3}
/>
</Tabs>
<div>
<TabContent
eventKey={0}
id="refTab1Section"
ref={contentRef1}
aria-label="This is content for the first separate content tab"
hidden={activeTabKey !== 0}
>
Tab 1 section
</TabContent>
<TabContent
eventKey={1}
id="refTab2Section"
ref={contentRef2}
aria-label="This is content for the second separate content tab"
hidden={activeTabKey !== 1}
>
Tab 2 section
</TabContent>
<TabContent
eventKey={2}
id="refTab3Section"
ref={contentRef3}
aria-label="This is content for the third separate content tab"
hidden={activeTabKey !== 2}
>
Tab 3 section
</TabContent>
</div>
</Fragment>
);
};