File size: 5,711 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Tabs

Tabs is a collection of React components that combine to render
an [ARIA-compliant tabs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/tabs/).

Tabs organizes content across different screens, data sets, and interactions.
It has two sections: a list of tabs, and the view to show when a tab is chosen.

`Tabs` itself is a wrapper component and context provider.
It is responsible for managing the state of the tabs, and rendering one instance of the `Tabs.TabList` component and one or more instances of the `Tab.TabPanel` component.

## Props

### `activeTabId`

- Type: `string`
- Required: No

The current active tab `id`. The active tab is the tab element within the
tablist widget that has DOM focus.

- `null` represents the tablist (ie. the base composite element). Users
  will be able to navigate out of it using arrow keys.
- If `activeTabId` is initially set to `null`, the base composite element
  itself will have focus and users will be able to navigate to it using
  arrow keys.

### `children`

- Type: `ReactNode`
- Required: Yes

The children elements, which should include one instance of the
`Tabs.Tablist` component and as many instances of the `Tabs.TabPanel`
components as there are `Tabs.Tab` components.

### `defaultTabId`

- Type: `string`
- Required: No

The id of the tab whose panel is currently visible.

If left `undefined`, it will be automatically set to the first enabled
tab. If set to `null`, no tab will be selected, and the tablist will be
tabbable.

Note: this prop will be overridden by the `selectedTabId` prop if it is
provided (meaning the component will be used in "controlled" mode).

### `defaultActiveTabId`

- Type: `string`
- Required: No

The tab id that should be active by default when the composite widget is
rendered. If `null`, the tablist element itself will have focus
and users will be able to navigate to it using arrow keys. If `undefined`,
the first enabled item will be focused.

Note: this prop will be overridden by the `activeTabId` prop if it is
provided.

### `onSelect`

- Type: `(selectedId: string) => void`
- Required: No

The function called when the `selectedTabId` changes.

### `onActiveTabIdChange`

- Type: `(activeId: string) => void`
- Required: No

A callback that gets called when the `activeTabId` state changes.

### `orientation`

- Type: `"horizontal" | "vertical" | "both"`
- Required: No
- Default: `"horizontal"`

Defines the orientation of the tablist and determines which arrow keys
can be used to move focus:

- `both`: all arrow keys work.
- `horizontal`: only left and right arrow keys work.
- `vertical`: only up and down arrow keys work.

### `selectOnMove`

- Type: `boolean`
- Required: No
- Default: `true`

Determines if the tab should be selected when it receives focus. If set to
`false`, the tab will only be selected upon clicking, not when using arrow
keys to shift focus (manual tab activation). See the [official W3C docs](https://www.w3.org/WAI/ARIA/apg/patterns/tabpanel/)
for more info.

### `selectedTabId`

- Type: `string`
- Required: No

The id of the tab whose panel is currently visible.

If left `undefined`, it will be automatically set to the first enabled
tab, and the component assumes it is being used in "uncontrolled" mode.

Consequently, any value different than `undefined` will set the component
in "controlled" mode. When in "controlled" mode, the `null` value will
result in no tabs being selected, and the tablist becoming tabbable.

## Subcomponents

### Tabs.TabList

A wrapper component for the `Tab` components.

It is responsible for rendering the list of tabs.

#### Props

##### `children`

- Type: `ReactNode`
- Required: Yes

The children elements, which should include one or more instances of the
`Tabs.Tab` component.

### Tabs.Tab

Renders a single tab.

The currently active tab receives default styling that can be
overridden with CSS targeting `[aria-selected="true"]`.

#### Props

##### `children`

- Type: `ReactNode`
- Required: No

The contents of the tab.

##### `disabled`

- Type: `boolean`
- Required: No
- Default: `false`

Determines if the tab should be disabled. Note that disabled tabs can
still be accessed via the keyboard when navigating through the tablist.

##### `render`

- Type: `RenderProp<HTMLAttributes<any> & { ref?: Ref<any>; }> | ReactElement<any, string | JSXElementConstructor<any>>`
- Required: No

Allows the component to be rendered as a different HTML element or React
component. The value can be a React element or a function that takes in the
original component props and gives back a React element with the props
merged.

By default, the tab will be rendered as a `button` element.

##### `tabId`

- Type: `string`
- Required: Yes

The unique ID of the tab. It will be used to register the tab and match
it to a corresponding `Tabs.TabPanel` component.

### Tabs.TabPanel

Renders the content to display for a single tab once that tab is selected.

#### Props

##### `children`

- Type: `ReactNode`
- Required: No

The contents of the tab panel.

##### `focusable`

- Type: `boolean`
- Required: No
- Default: `true`

Determines whether or not the tabpanel element should be focusable.
If `false`, pressing the tab key will skip over the tabpanel, and instead
focus on the first focusable element in the panel (if there is one).

##### `tabId`

- Type: `string`
- Required: Yes

The unique `id` of the `Tabs.Tab` component controlling this panel. This
connection is used to assign the `aria-labelledby` attribute to the tab
panel and to determine if the tab panel should be visible.

If not provided, this link is automatically established by matching the
order of `Tabs.Tab` and `Tabs.TabPanel` elements in the DOM.