UNPKG

3.7 kBMarkdownView Raw
1---
2title: Tabs
3storybookPath: page-layout-tabs--default
4isExperimentalPackage: true
5---
6
7Tabs are a set of layered sections of content (known as tab panels) that display
8one panel of content at a time. Each tab panel has an associated tab element,
9that when activated, displays the panel. The list of tab elements is arranged
10along the top edge of the currently displayed panel.
11
12## Example
13
14```jsx live
15<Tabs>
16 <TabList>
17 <Tab>First tab</Tab>
18 <Tab>Second tab</Tab>
19 </TabList>
20 <TabPanels>
21 <TabPanel>
22 <Stack paddingY="medium">
23 <Placeholder label="Content from first panel" height={64} />
24 </Stack>
25 </TabPanel>
26 <TabPanel>
27 <Stack paddingY="medium">
28 <Placeholder label="Content from second panel" height={64} />
29 </Stack>
30 </TabPanel>
31 </TabPanels>
32</Tabs>
33```
34
35### Default Index
36
37By default, users will be shown the first tab. This can be overridden by
38providing a `defaultIndex` prop. You can also have _no_ tabs active by default
39by providing a `defaultIndex` of `-1`.
40
41```jsx live
42<Tabs defaultIndex={1}>
43 <TabList>
44 <Tab>First tab</Tab>
45 <Tab>Second tab (default)</Tab>
46 </TabList>
47 <TabPanels>
48 <TabPanel>
49 <Stack paddingY="medium">
50 <Placeholder label="Content from first panel" height={64} />
51 </Stack>
52 </TabPanel>
53 <TabPanel>
54 <Stack paddingY="medium">
55 <Placeholder
56 label="Content from second panel (this should be selected by default)"
57 height={64}
58 />
59 </Stack>
60 </TabPanel>
61 </TabPanels>
62</Tabs>
63```
64
65### Disabled tabs
66
67Individual tabs can be be disabled by providing them with a `disabled` prop.
68
69```jsx live
70<Tabs>
71 <TabList>
72 <Tab>First tab</Tab>
73 <Tab>Second tab</Tab>
74 <Tab disabled>Third tab (disabled)</Tab>
75 </TabList>
76 <TabPanels>
77 <TabPanel>
78 <Stack paddingY="medium">
79 <Placeholder label="Content from first panel" height={64} />
80 </Stack>
81 </TabPanel>
82 <TabPanel>
83 <Stack paddingY="medium">
84 <Placeholder label="Content from second panel" height={64} />
85 </Stack>
86 </TabPanel>
87 <TabPanel>
88 <Stack paddingY="medium">
89 <Placeholder
90 label="Content from third panel. You should not be able to see me!"
91 height={64}
92 />
93 </Stack>
94 </TabPanel>
95 </TabPanels>
96</Tabs>
97```
98
99### Manual Activation
100
101By default, when a tab has focus, users can cycle through the enabled tabs using
102the arrow keys. If `activationMode` is set to `"manual"`, users can activate a
103tab by pressing the `Enter` or `Space` key when the tab you want to view has
104focus.
105
106It is very important for usability that functionality of components behaves in a
107consistent manor. It is therefore recommended that you _do not_ use the manual
108activation mode unless you absolutely need it.
109
110```jsx live
111<Tabs activationMode="manual">
112 <TabList>
113 <Tab>First tab</Tab>
114 <Tab>Second tab</Tab>
115 </TabList>
116 <TabPanels>
117 <TabPanel>
118 <Stack paddingY="medium">
119 <Placeholder label="Content from first panel" height={64} />
120 </Stack>
121 </TabPanel>
122 <TabPanel>
123 <Stack paddingY="medium">
124 <Placeholder label="Content from second panel" height={64} />
125 </Stack>
126 </TabPanel>
127 </TabPanels>
128</Tabs>
129```
130
131## Props
132
133### Tabs
134
135<PropsTable displayName="Tabs" />
136
137### TabList
138
139<PropsTable displayName="TabList" />
140
141### Tab
142
143<PropsTable displayName="Tab" />
144
145### TabPanels
146
147<PropsTable displayName="TabPanels" />
148
149### TabPanel
150
151<PropsTable displayName="TabPanel" />
152
153[data-attribute-map]:
154 https://github.com/brighte-labs/spark-web/blob/e7f6f4285b4cfd876312cc89fbdd094039aa239a/packages/utils/src/internal/buildDataAttributes.ts#L1