@patternfly/react-core 4.214.3 → 4.215.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/esm/components/Checkbox/Checkbox.d.ts +2 -0
- package/dist/esm/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +4 -3
- package/dist/esm/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/components/Menu/MenuItem.d.ts +3 -1
- package/dist/esm/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuItem.js +15 -6
- package/dist/esm/components/Menu/MenuItem.js.map +1 -1
- package/dist/esm/components/Slider/Slider.d.ts +4 -0
- package/dist/esm/components/Slider/Slider.d.ts.map +1 -1
- package/dist/esm/components/Slider/Slider.js +2 -2
- package/dist/esm/components/Slider/Slider.js.map +1 -1
- package/dist/esm/components/TextArea/TextArea.d.ts +1 -1
- package/dist/esm/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/js/components/Checkbox/Checkbox.d.ts +2 -0
- package/dist/js/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/js/components/Checkbox/Checkbox.js +4 -3
- package/dist/js/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/js/components/Menu/MenuItem.d.ts +3 -1
- package/dist/js/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuItem.js +15 -6
- package/dist/js/components/Menu/MenuItem.js.map +1 -1
- package/dist/js/components/Slider/Slider.d.ts +4 -0
- package/dist/js/components/Slider/Slider.d.ts.map +1 -1
- package/dist/js/components/Slider/Slider.js +2 -2
- package/dist/js/components/Slider/Slider.js.map +1 -1
- package/dist/js/components/TextArea/TextArea.d.ts +1 -1
- package/dist/js/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/js/components/TextArea/TextArea.js.map +1 -1
- package/dist/umd/react-core.js +19 -11
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +5 -5
- package/src/components/Checkbox/Checkbox.tsx +7 -3
- package/src/components/Checkbox/__tests__/Checkbox.test.tsx +9 -0
- package/src/components/Dropdown/examples/Dropdown.md +25 -1530
- package/src/components/Dropdown/examples/DropdownAlignmentOnBreakpoints.tsx +64 -0
- package/src/components/Dropdown/examples/DropdownAppendBodyVsParent.tsx +83 -0
- package/src/components/Dropdown/examples/DropdownBadge.tsx +46 -0
- package/src/components/Dropdown/examples/DropdownBasic.tsx +57 -0
- package/src/components/Dropdown/examples/DropdownBasicPanel.tsx +34 -0
- package/src/components/Dropdown/examples/DropdownDescriptions.tsx +55 -0
- package/src/components/Dropdown/examples/DropdownDirectionUp.tsx +58 -0
- package/src/components/Dropdown/examples/DropdownDisabled.tsx +57 -0
- package/src/components/Dropdown/examples/DropdownGroups.tsx +55 -0
- package/src/components/Dropdown/examples/DropdownIconOnly.tsx +59 -0
- package/src/components/Dropdown/examples/DropdownImageAndText.tsx +64 -0
- package/src/components/Dropdown/examples/DropdownInitialSelection.tsx +57 -0
- package/src/components/Dropdown/examples/DropdownKebab.tsx +54 -0
- package/src/components/Dropdown/examples/DropdownPlainTextToggle.tsx +59 -0
- package/src/components/Dropdown/examples/DropdownPositionRight.tsx +58 -0
- package/src/components/Dropdown/examples/DropdownPrimaryToggle.tsx +57 -0
- package/src/components/Dropdown/examples/DropdownRouterLink.tsx +36 -0
- package/src/components/Dropdown/examples/DropdownSecondaryToggle.tsx +57 -0
- package/src/components/Dropdown/examples/DropdownSplitButton.tsx +67 -0
- package/src/components/Dropdown/examples/DropdownSplitButtonAction.tsx +105 -0
- package/src/components/Dropdown/examples/DropdownSplitButtonActionPrimary.tsx +107 -0
- package/src/components/Dropdown/examples/DropdownSplitButtonDisabled.tsx +73 -0
- package/src/components/Dropdown/examples/DropdownSplitButtonIndeterminate.tsx +78 -0
- package/src/components/Dropdown/examples/DropdownSplitButtonText.tsx +69 -0
- package/src/components/Menu/MenuItem.tsx +69 -43
- package/src/components/Menu/__tests__/Menu.test.tsx +23 -0
- package/src/components/Menu/examples/Menu.md +5 -0
- package/src/components/Menu/examples/MenuWithCheckbox.tsx +34 -0
- package/src/components/Slider/Slider.tsx +8 -0
- package/src/components/Slider/_tests_/Slider.test.tsx +27 -1
- package/src/components/TextArea/TextArea.tsx +1 -1
- package/src/demos/ComposableMenu/ComposableMenu.md +5 -0
- package/src/demos/ComposableMenu/examples/ComposableSimpleCheckboxSelect.tsx +98 -0
|
@@ -20,1469 +20,112 @@ import avatarImg from '../../Avatar/examples/avatarImg.svg';
|
|
|
20
20
|
|
|
21
21
|
### Basic
|
|
22
22
|
|
|
23
|
-
```
|
|
24
|
-
import React from 'react';
|
|
25
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
26
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
27
|
-
|
|
28
|
-
class SimpleDropdown extends React.Component {
|
|
29
|
-
constructor(props) {
|
|
30
|
-
super(props);
|
|
31
|
-
this.state = {
|
|
32
|
-
isOpen: false
|
|
33
|
-
};
|
|
34
|
-
this.onToggle = isOpen => {
|
|
35
|
-
this.setState({
|
|
36
|
-
isOpen
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
this.onSelect = event => {
|
|
40
|
-
this.setState({
|
|
41
|
-
isOpen: !this.state.isOpen
|
|
42
|
-
});
|
|
43
|
-
this.onFocus();
|
|
44
|
-
};
|
|
45
|
-
this.onFocus = () => {
|
|
46
|
-
const element = document.getElementById('toggle-id');
|
|
47
|
-
element.focus();
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
render() {
|
|
52
|
-
const { isOpen } = this.state;
|
|
53
|
-
const dropdownItems = [
|
|
54
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
55
|
-
<DropdownItem key="action" component="button">
|
|
56
|
-
Action
|
|
57
|
-
</DropdownItem>,
|
|
58
|
-
<DropdownItem key="disabled link" isDisabled href="www.google.com">
|
|
59
|
-
Disabled link
|
|
60
|
-
</DropdownItem>,
|
|
61
|
-
<DropdownItem
|
|
62
|
-
key="disabled action"
|
|
63
|
-
isAriaDisabled
|
|
64
|
-
component="button"
|
|
65
|
-
tooltip="Tooltip for disabled item"
|
|
66
|
-
tooltipProps={{ position: 'top' }}
|
|
67
|
-
>
|
|
68
|
-
Disabled action
|
|
69
|
-
</DropdownItem>,
|
|
70
|
-
<DropdownSeparator key="separator" />,
|
|
71
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
72
|
-
<DropdownItem key="separated action" component="button">
|
|
73
|
-
Separated action
|
|
74
|
-
</DropdownItem>
|
|
75
|
-
];
|
|
76
|
-
return (
|
|
77
|
-
<Dropdown
|
|
78
|
-
onSelect={this.onSelect}
|
|
79
|
-
toggle={
|
|
80
|
-
<DropdownToggle id="toggle-id" onToggle={this.onToggle} toggleIndicator={CaretDownIcon}>
|
|
81
|
-
Dropdown
|
|
82
|
-
</DropdownToggle>
|
|
83
|
-
}
|
|
84
|
-
isOpen={isOpen}
|
|
85
|
-
dropdownItems={dropdownItems}
|
|
86
|
-
/>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
23
|
+
```ts file='./DropdownBasic.tsx'
|
|
90
24
|
```
|
|
91
25
|
|
|
92
26
|
### With initial selection
|
|
93
27
|
|
|
94
|
-
```
|
|
95
|
-
import React from 'react';
|
|
96
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
97
|
-
|
|
98
|
-
class IntialSelectionDropdown extends React.Component {
|
|
99
|
-
constructor(props) {
|
|
100
|
-
super(props);
|
|
101
|
-
this.state = {
|
|
102
|
-
isOpen: false
|
|
103
|
-
};
|
|
104
|
-
this.onToggle = isOpen => {
|
|
105
|
-
this.setState({
|
|
106
|
-
isOpen
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
this.onSelect = event => {
|
|
110
|
-
this.setState({
|
|
111
|
-
isOpen: !this.state.isOpen
|
|
112
|
-
});
|
|
113
|
-
this.onFocus();
|
|
114
|
-
};
|
|
115
|
-
this.onFocus = () => {
|
|
116
|
-
const element = document.getElementById('toggle-id-2');
|
|
117
|
-
element.focus();
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
render() {
|
|
122
|
-
const { isOpen } = this.state;
|
|
123
|
-
const dropdownItems = [
|
|
124
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
125
|
-
<DropdownItem key="action" component="button" autoFocus>
|
|
126
|
-
Action
|
|
127
|
-
</DropdownItem>,
|
|
128
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
129
|
-
Disabled link
|
|
130
|
-
</DropdownItem>,
|
|
131
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
132
|
-
Disabled action
|
|
133
|
-
</DropdownItem>,
|
|
134
|
-
<DropdownSeparator key="separator" />,
|
|
135
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
136
|
-
<DropdownItem key="separated action" component="button">
|
|
137
|
-
Separated action
|
|
138
|
-
</DropdownItem>
|
|
139
|
-
];
|
|
140
|
-
return (
|
|
141
|
-
<Dropdown
|
|
142
|
-
onSelect={this.onSelect}
|
|
143
|
-
toggle={
|
|
144
|
-
<DropdownToggle id="toggle-id-2" onToggle={this.onToggle}>
|
|
145
|
-
Dropdown
|
|
146
|
-
</DropdownToggle>
|
|
147
|
-
}
|
|
148
|
-
isOpen={isOpen}
|
|
149
|
-
dropdownItems={dropdownItems}
|
|
150
|
-
autoFocus={false}
|
|
151
|
-
/>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
28
|
+
```ts file="./DropdownInitialSelection.tsx"
|
|
155
29
|
```
|
|
156
30
|
|
|
157
31
|
### With groups
|
|
158
32
|
|
|
159
|
-
```
|
|
160
|
-
import React from 'react';
|
|
161
|
-
import { Dropdown, DropdownToggle, DropdownGroup, DropdownItem } from '@patternfly/react-core';
|
|
162
|
-
|
|
163
|
-
class GroupedDropdown extends React.Component {
|
|
164
|
-
constructor(props) {
|
|
165
|
-
super(props);
|
|
166
|
-
this.state = {
|
|
167
|
-
isOpen: false
|
|
168
|
-
};
|
|
169
|
-
this.onToggle = isOpen => {
|
|
170
|
-
this.setState({
|
|
171
|
-
isOpen
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
this.onSelect = event => {
|
|
175
|
-
this.setState({
|
|
176
|
-
isOpen: !this.state.isOpen
|
|
177
|
-
});
|
|
178
|
-
this.onFocus();
|
|
179
|
-
};
|
|
180
|
-
this.onFocus = () => {
|
|
181
|
-
const element = document.getElementById('toggle-id-3');
|
|
182
|
-
element.focus();
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
render() {
|
|
187
|
-
const { isOpen } = this.state;
|
|
188
|
-
const dropdownItems = [
|
|
189
|
-
<DropdownGroup key="group 1">
|
|
190
|
-
<DropdownItem key="group 1 link">Link</DropdownItem>
|
|
191
|
-
<DropdownItem key="group 1 action" component="button">
|
|
192
|
-
Action
|
|
193
|
-
</DropdownItem>
|
|
194
|
-
</DropdownGroup>,
|
|
195
|
-
<DropdownGroup label="Group 2" key="group 2">
|
|
196
|
-
<DropdownItem key="group 2 link">Group 2 link</DropdownItem>
|
|
197
|
-
<DropdownItem key="group 2 action" component="button">
|
|
198
|
-
Group 2 action
|
|
199
|
-
</DropdownItem>
|
|
200
|
-
</DropdownGroup>,
|
|
201
|
-
<DropdownGroup label="Group 3" key="group 3">
|
|
202
|
-
<DropdownItem key="group 3 link">Group 3 link</DropdownItem>
|
|
203
|
-
<DropdownItem key="group 3 action" component="button">
|
|
204
|
-
Group 3 action
|
|
205
|
-
</DropdownItem>
|
|
206
|
-
</DropdownGroup>
|
|
207
|
-
];
|
|
208
|
-
return (
|
|
209
|
-
<Dropdown
|
|
210
|
-
onSelect={this.onSelect}
|
|
211
|
-
toggle={
|
|
212
|
-
<DropdownToggle onToggle={this.onToggle} id="toggle-id-3">
|
|
213
|
-
Dropdown
|
|
214
|
-
</DropdownToggle>
|
|
215
|
-
}
|
|
216
|
-
isOpen={isOpen}
|
|
217
|
-
dropdownItems={dropdownItems}
|
|
218
|
-
isGrouped
|
|
219
|
-
/>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
33
|
+
```ts file="./DropdownGroups.tsx"
|
|
223
34
|
```
|
|
224
35
|
|
|
225
36
|
### Disabled
|
|
226
37
|
|
|
227
|
-
```
|
|
228
|
-
import React from 'react';
|
|
229
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
230
|
-
|
|
231
|
-
class DisabledDropdown extends React.Component {
|
|
232
|
-
constructor(props) {
|
|
233
|
-
super(props);
|
|
234
|
-
this.state = {
|
|
235
|
-
isOpen: false
|
|
236
|
-
};
|
|
237
|
-
this.onToggle = isOpen => {
|
|
238
|
-
this.setState({
|
|
239
|
-
isOpen
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
this.onSelect = event => {
|
|
243
|
-
this.setState({
|
|
244
|
-
isOpen: !this.state.isOpen
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
render() {
|
|
250
|
-
const { isOpen } = this.state;
|
|
251
|
-
const dropdownItems = [
|
|
252
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
253
|
-
<DropdownItem key="action" component="button">
|
|
254
|
-
Action
|
|
255
|
-
</DropdownItem>,
|
|
256
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
257
|
-
Disabled link
|
|
258
|
-
</DropdownItem>,
|
|
259
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
260
|
-
Disabled action
|
|
261
|
-
</DropdownItem>,
|
|
262
|
-
<DropdownSeparator key="separator" />,
|
|
263
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
264
|
-
<DropdownItem key="separated action" component="button">
|
|
265
|
-
Separated action
|
|
266
|
-
</DropdownItem>
|
|
267
|
-
];
|
|
268
|
-
return (
|
|
269
|
-
<Dropdown
|
|
270
|
-
onSelect={this.onSelect}
|
|
271
|
-
toggle={
|
|
272
|
-
<DropdownToggle isDisabled onToggle={this.onToggle}>
|
|
273
|
-
Dropdown
|
|
274
|
-
</DropdownToggle>
|
|
275
|
-
}
|
|
276
|
-
isOpen={isOpen}
|
|
277
|
-
dropdownItems={dropdownItems}
|
|
278
|
-
/>
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
38
|
+
```ts file="./DropdownDisabled.tsx"
|
|
282
39
|
```
|
|
283
40
|
|
|
284
41
|
### Primary toggle
|
|
285
42
|
|
|
286
|
-
```
|
|
287
|
-
import React from 'react';
|
|
288
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
289
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
290
|
-
|
|
291
|
-
class PrimaryDropdown extends React.Component {
|
|
292
|
-
constructor(props) {
|
|
293
|
-
super(props);
|
|
294
|
-
this.state = {
|
|
295
|
-
isOpen: false
|
|
296
|
-
};
|
|
297
|
-
this.onToggle = isOpen => {
|
|
298
|
-
this.setState({
|
|
299
|
-
isOpen
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
this.onSelect = event => {
|
|
303
|
-
this.setState({
|
|
304
|
-
isOpen: !this.state.isOpen
|
|
305
|
-
});
|
|
306
|
-
this.onFocus();
|
|
307
|
-
};
|
|
308
|
-
this.onFocus = () => {
|
|
309
|
-
const element = document.getElementById('toggle-id-4');
|
|
310
|
-
element.focus();
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
render() {
|
|
315
|
-
const { isOpen } = this.state;
|
|
316
|
-
const dropdownItems = [
|
|
317
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
318
|
-
<DropdownItem key="action" component="button">
|
|
319
|
-
Action
|
|
320
|
-
</DropdownItem>,
|
|
321
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
322
|
-
Disabled link
|
|
323
|
-
</DropdownItem>,
|
|
324
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
325
|
-
Disabled action
|
|
326
|
-
</DropdownItem>,
|
|
327
|
-
<DropdownSeparator key="separator" />,
|
|
328
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
329
|
-
<DropdownItem key="separated action" component="button">
|
|
330
|
-
Separated action
|
|
331
|
-
</DropdownItem>
|
|
332
|
-
];
|
|
333
|
-
return (
|
|
334
|
-
<Dropdown
|
|
335
|
-
onSelect={this.onSelect}
|
|
336
|
-
toggle={
|
|
337
|
-
<DropdownToggle onToggle={this.onToggle} toggleIndicator={CaretDownIcon} isPrimary id="toggle-id-4">
|
|
338
|
-
Dropdown
|
|
339
|
-
</DropdownToggle>
|
|
340
|
-
}
|
|
341
|
-
isOpen={isOpen}
|
|
342
|
-
dropdownItems={dropdownItems}
|
|
343
|
-
/>
|
|
344
|
-
);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
43
|
+
```ts file="./DropdownPrimaryToggle.tsx"
|
|
347
44
|
```
|
|
348
45
|
|
|
349
46
|
### Secondary toggle
|
|
350
47
|
|
|
351
|
-
```ts
|
|
352
|
-
import React from 'react';
|
|
353
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
354
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
355
|
-
|
|
356
|
-
const SecondaryDropdown = () => {
|
|
357
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
358
|
-
|
|
359
|
-
const onFocus = () => {
|
|
360
|
-
const element = document.getElementById('toggle-id-secondary');
|
|
361
|
-
element.focus();
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
const dropdownItems = [
|
|
365
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
366
|
-
<DropdownItem key="action" component="button">
|
|
367
|
-
Action
|
|
368
|
-
</DropdownItem>,
|
|
369
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
370
|
-
Disabled link
|
|
371
|
-
</DropdownItem>,
|
|
372
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
373
|
-
Disabled action
|
|
374
|
-
</DropdownItem>,
|
|
375
|
-
<DropdownSeparator key="separator" />,
|
|
376
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
377
|
-
<DropdownItem key="separated action" component="button">
|
|
378
|
-
Separated action
|
|
379
|
-
</DropdownItem>
|
|
380
|
-
];
|
|
381
|
-
|
|
382
|
-
return (
|
|
383
|
-
<Dropdown
|
|
384
|
-
onSelect={() => {
|
|
385
|
-
setIsOpen(!isOpen);
|
|
386
|
-
onFocus();
|
|
387
|
-
}}
|
|
388
|
-
toggle={
|
|
389
|
-
<DropdownToggle
|
|
390
|
-
onToggle={next => setIsOpen(next)}
|
|
391
|
-
toggleIndicator={CaretDownIcon}
|
|
392
|
-
toggleVariant="secondary"
|
|
393
|
-
id="toggle-id-secondary"
|
|
394
|
-
>
|
|
395
|
-
Dropdown
|
|
396
|
-
</DropdownToggle>
|
|
397
|
-
}
|
|
398
|
-
isOpen={isOpen}
|
|
399
|
-
dropdownItems={dropdownItems}
|
|
400
|
-
/>
|
|
401
|
-
);
|
|
402
|
-
};
|
|
48
|
+
```ts file="./DropdownSecondaryToggle.tsx"
|
|
403
49
|
```
|
|
404
50
|
|
|
405
51
|
### Plain with text toggle
|
|
406
52
|
|
|
407
|
-
```ts
|
|
408
|
-
import React from 'react';
|
|
409
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
410
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
411
|
-
|
|
412
|
-
const SecondaryDropdown = () => {
|
|
413
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
|
414
|
-
|
|
415
|
-
const onFocus = () => {
|
|
416
|
-
const element = document.getElementById('toggle-id-plain-text');
|
|
417
|
-
element.focus();
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
const dropdownItems = [
|
|
421
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
422
|
-
<DropdownItem key="action" component="button">
|
|
423
|
-
Action
|
|
424
|
-
</DropdownItem>,
|
|
425
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
426
|
-
Disabled link
|
|
427
|
-
</DropdownItem>,
|
|
428
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
429
|
-
Disabled action
|
|
430
|
-
</DropdownItem>,
|
|
431
|
-
<DropdownSeparator key="separator" />,
|
|
432
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
433
|
-
<DropdownItem key="separated action" component="button">
|
|
434
|
-
Separated action
|
|
435
|
-
</DropdownItem>
|
|
436
|
-
];
|
|
437
|
-
|
|
438
|
-
return (
|
|
439
|
-
<Dropdown
|
|
440
|
-
isText
|
|
441
|
-
isPlain
|
|
442
|
-
onSelect={() => {
|
|
443
|
-
setIsOpen(!isOpen);
|
|
444
|
-
onFocus();
|
|
445
|
-
}}
|
|
446
|
-
toggle={
|
|
447
|
-
<DropdownToggle onToggle={next => setIsOpen(next)} toggleIndicator={CaretDownIcon} id="toggle-id-plain-text">
|
|
448
|
-
Dropdown
|
|
449
|
-
</DropdownToggle>
|
|
450
|
-
}
|
|
451
|
-
isOpen={isOpen}
|
|
452
|
-
dropdownItems={dropdownItems}
|
|
453
|
-
/>
|
|
454
|
-
);
|
|
455
|
-
};
|
|
53
|
+
```ts file="./DropdownPlainTextToggle.tsx"
|
|
456
54
|
```
|
|
457
55
|
|
|
458
56
|
### Position right
|
|
459
57
|
|
|
460
|
-
```
|
|
461
|
-
import React from 'react';
|
|
462
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownPosition } from '@patternfly/react-core';
|
|
463
|
-
|
|
464
|
-
class PositionRightDropdown extends React.Component {
|
|
465
|
-
constructor(props) {
|
|
466
|
-
super(props);
|
|
467
|
-
this.state = {
|
|
468
|
-
isOpen: false
|
|
469
|
-
};
|
|
470
|
-
this.onToggle = isOpen => {
|
|
471
|
-
this.setState({
|
|
472
|
-
isOpen
|
|
473
|
-
});
|
|
474
|
-
};
|
|
475
|
-
this.onSelect = event => {
|
|
476
|
-
this.setState({
|
|
477
|
-
isOpen: !this.state.isOpen
|
|
478
|
-
});
|
|
479
|
-
this.onFocus();
|
|
480
|
-
};
|
|
481
|
-
this.onFocus = () => {
|
|
482
|
-
const element = document.getElementById('toggle-id-5');
|
|
483
|
-
element.focus();
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
render() {
|
|
488
|
-
const { isOpen } = this.state;
|
|
489
|
-
const dropdownItems = [
|
|
490
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
491
|
-
<DropdownItem key="action" component="button">
|
|
492
|
-
Action
|
|
493
|
-
</DropdownItem>,
|
|
494
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
495
|
-
Disabled link
|
|
496
|
-
</DropdownItem>,
|
|
497
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
498
|
-
Disabled action
|
|
499
|
-
</DropdownItem>,
|
|
500
|
-
<DropdownSeparator key="separator" />,
|
|
501
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
502
|
-
<DropdownItem key="separated action" component="button">
|
|
503
|
-
Separated action
|
|
504
|
-
</DropdownItem>
|
|
505
|
-
];
|
|
506
|
-
return (
|
|
507
|
-
<Dropdown
|
|
508
|
-
onSelect={this.onSelect}
|
|
509
|
-
position={DropdownPosition.right}
|
|
510
|
-
toggle={<DropdownToggle onToggle={this.onToggle}>Dropdown</DropdownToggle>}
|
|
511
|
-
isOpen={isOpen}
|
|
512
|
-
dropdownItems={dropdownItems}
|
|
513
|
-
/>
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
58
|
+
```ts file="./DropdownPositionRight.tsx"
|
|
517
59
|
```
|
|
518
60
|
|
|
519
61
|
### Alignments on different breakpoints
|
|
520
62
|
|
|
521
|
-
```
|
|
522
|
-
import React from 'react';
|
|
523
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
524
|
-
|
|
525
|
-
class AlignmentsDropdown extends React.Component {
|
|
526
|
-
constructor(props) {
|
|
527
|
-
super(props);
|
|
528
|
-
this.state = {
|
|
529
|
-
isOpen: false
|
|
530
|
-
};
|
|
531
|
-
this.onToggle = isOpen => {
|
|
532
|
-
this.setState({
|
|
533
|
-
isOpen
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
this.onSelect = event => {
|
|
537
|
-
this.setState({
|
|
538
|
-
isOpen: !this.state.isOpen
|
|
539
|
-
});
|
|
540
|
-
this.onFocus();
|
|
541
|
-
};
|
|
542
|
-
this.onFocus = () => {
|
|
543
|
-
const element = document.getElementById('toggle-id-5');
|
|
544
|
-
element.focus();
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
render() {
|
|
549
|
-
const { isOpen } = this.state;
|
|
550
|
-
const dropdownItems = [
|
|
551
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
552
|
-
<DropdownItem key="action" component="button">
|
|
553
|
-
Action
|
|
554
|
-
</DropdownItem>,
|
|
555
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
556
|
-
Disabled link
|
|
557
|
-
</DropdownItem>,
|
|
558
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
559
|
-
Disabled action
|
|
560
|
-
</DropdownItem>,
|
|
561
|
-
<DropdownSeparator key="separator" />,
|
|
562
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
563
|
-
<DropdownItem key="separated action" component="button">
|
|
564
|
-
Separated action
|
|
565
|
-
</DropdownItem>
|
|
566
|
-
];
|
|
567
|
-
return (
|
|
568
|
-
<Dropdown
|
|
569
|
-
onSelect={this.onSelect}
|
|
570
|
-
alignments={{
|
|
571
|
-
sm: 'left',
|
|
572
|
-
md: 'right',
|
|
573
|
-
lg: 'left',
|
|
574
|
-
xl: 'right',
|
|
575
|
-
'2xl': 'left'
|
|
576
|
-
}}
|
|
577
|
-
toggle={<DropdownToggle onToggle={this.onToggle}>Dropdown</DropdownToggle>}
|
|
578
|
-
isOpen={isOpen}
|
|
579
|
-
dropdownItems={dropdownItems}
|
|
580
|
-
/>
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
63
|
+
```ts file="./DropdownAlignmentOnBreakpoints.tsx"
|
|
584
64
|
```
|
|
585
65
|
|
|
586
66
|
### Direction up
|
|
587
67
|
|
|
588
|
-
```
|
|
589
|
-
import React from 'react';
|
|
590
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator, DropdownDirection } from '@patternfly/react-core';
|
|
591
|
-
|
|
592
|
-
class DirectionUpDropdown extends React.Component {
|
|
593
|
-
constructor(props) {
|
|
594
|
-
super(props);
|
|
595
|
-
this.state = {
|
|
596
|
-
isOpen: false
|
|
597
|
-
};
|
|
598
|
-
this.onToggle = isOpen => {
|
|
599
|
-
this.setState({
|
|
600
|
-
isOpen
|
|
601
|
-
});
|
|
602
|
-
};
|
|
603
|
-
this.onSelect = event => {
|
|
604
|
-
this.setState({
|
|
605
|
-
isOpen: !this.state.isOpen
|
|
606
|
-
});
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
render() {
|
|
611
|
-
const { isOpen } = this.state;
|
|
612
|
-
const dropdownItems = [
|
|
613
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
614
|
-
<DropdownItem key="action" component="button">
|
|
615
|
-
Action
|
|
616
|
-
</DropdownItem>,
|
|
617
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
618
|
-
Disabled link
|
|
619
|
-
</DropdownItem>,
|
|
620
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
621
|
-
Disabled action
|
|
622
|
-
</DropdownItem>,
|
|
623
|
-
<DropdownSeparator key="separator" />,
|
|
624
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
625
|
-
<DropdownItem key="separated action" component="button">
|
|
626
|
-
Separated action
|
|
627
|
-
</DropdownItem>
|
|
628
|
-
];
|
|
629
|
-
return (
|
|
630
|
-
<Dropdown
|
|
631
|
-
direction={DropdownDirection.up}
|
|
632
|
-
onSelect={this.onSelect}
|
|
633
|
-
toggle={
|
|
634
|
-
<DropdownToggle onToggle={this.onToggle} id="toggle-id-5">
|
|
635
|
-
Dropdown
|
|
636
|
-
</DropdownToggle>
|
|
637
|
-
}
|
|
638
|
-
isOpen={isOpen}
|
|
639
|
-
dropdownItems={dropdownItems}
|
|
640
|
-
/>
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
68
|
+
```ts file="./DropdownDirectionUp.tsx"
|
|
644
69
|
```
|
|
645
70
|
|
|
646
71
|
### With kebab
|
|
647
72
|
|
|
648
|
-
```
|
|
649
|
-
import React from 'react';
|
|
650
|
-
import { Dropdown, DropdownItem, DropdownSeparator, KebabToggle } from '@patternfly/react-core';
|
|
651
|
-
|
|
652
|
-
class KebabDropdown extends React.Component {
|
|
653
|
-
constructor(props) {
|
|
654
|
-
super(props);
|
|
655
|
-
this.state = {
|
|
656
|
-
isOpen: false
|
|
657
|
-
};
|
|
658
|
-
this.onToggle = isOpen => {
|
|
659
|
-
this.setState({
|
|
660
|
-
isOpen
|
|
661
|
-
});
|
|
662
|
-
};
|
|
663
|
-
this.onSelect = event => {
|
|
664
|
-
this.setState({
|
|
665
|
-
isOpen: !this.state.isOpen
|
|
666
|
-
});
|
|
667
|
-
this.onFocus();
|
|
668
|
-
};
|
|
669
|
-
this.onFocus = () => {
|
|
670
|
-
const element = document.getElementById('toggle-id-6');
|
|
671
|
-
element.focus();
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
render() {
|
|
676
|
-
const { isOpen } = this.state;
|
|
677
|
-
const dropdownItems = [
|
|
678
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
679
|
-
<DropdownItem key="action" component="button">
|
|
680
|
-
Action
|
|
681
|
-
</DropdownItem>,
|
|
682
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
683
|
-
Disabled link
|
|
684
|
-
</DropdownItem>,
|
|
685
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
686
|
-
Disabled action
|
|
687
|
-
</DropdownItem>,
|
|
688
|
-
<DropdownSeparator key="separator" />,
|
|
689
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
690
|
-
<DropdownItem key="separated action" component="button">
|
|
691
|
-
Separated action
|
|
692
|
-
</DropdownItem>
|
|
693
|
-
];
|
|
694
|
-
return (
|
|
695
|
-
<Dropdown
|
|
696
|
-
onSelect={this.onSelect}
|
|
697
|
-
toggle={<KebabToggle onToggle={this.onToggle} id="toggle-id-6" />}
|
|
698
|
-
isOpen={isOpen}
|
|
699
|
-
isPlain
|
|
700
|
-
dropdownItems={dropdownItems}
|
|
701
|
-
/>
|
|
702
|
-
);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
73
|
+
```ts file="./DropdownKebab.tsx"
|
|
705
74
|
```
|
|
706
75
|
|
|
707
76
|
### With badge
|
|
708
77
|
|
|
709
|
-
```
|
|
710
|
-
import React from 'react';
|
|
711
|
-
import { Dropdown, DropdownItem, BadgeToggle } from '@patternfly/react-core';
|
|
712
|
-
import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon';
|
|
713
|
-
|
|
714
|
-
class BadgeDropdown extends React.Component {
|
|
715
|
-
constructor(props) {
|
|
716
|
-
super(props);
|
|
717
|
-
this.state = {
|
|
718
|
-
isOpen: false
|
|
719
|
-
};
|
|
720
|
-
this.onToggle = isOpen => {
|
|
721
|
-
this.setState({
|
|
722
|
-
isOpen
|
|
723
|
-
});
|
|
724
|
-
};
|
|
725
|
-
this.onSelect = event => {
|
|
726
|
-
this.setState({
|
|
727
|
-
isOpen: !this.state.isOpen
|
|
728
|
-
});
|
|
729
|
-
this.onFocus();
|
|
730
|
-
};
|
|
731
|
-
this.onFocus = () => {
|
|
732
|
-
const element = document.getElementById('toggle-id');
|
|
733
|
-
element.focus();
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
render() {
|
|
738
|
-
const { isOpen } = this.state;
|
|
739
|
-
const dropdownItems = [
|
|
740
|
-
<DropdownItem key="edit" component="button" icon={<AngleLeftIcon />}>
|
|
741
|
-
Edit
|
|
742
|
-
</DropdownItem>,
|
|
743
|
-
<DropdownItem key="action" component="button" icon={<AngleLeftIcon />}>
|
|
744
|
-
Deployment
|
|
745
|
-
</DropdownItem>,
|
|
746
|
-
<DropdownItem key="apps" component="button" icon={<AngleLeftIcon />}>
|
|
747
|
-
Applications
|
|
748
|
-
</DropdownItem>
|
|
749
|
-
];
|
|
750
|
-
return (
|
|
751
|
-
<Dropdown
|
|
752
|
-
onSelect={this.onSelect}
|
|
753
|
-
toggle={
|
|
754
|
-
<BadgeToggle id="toggle-id" onToggle={this.onToggle}>
|
|
755
|
-
{dropdownItems.length}
|
|
756
|
-
</BadgeToggle>
|
|
757
|
-
}
|
|
758
|
-
isOpen={isOpen}
|
|
759
|
-
dropdownItems={dropdownItems}
|
|
760
|
-
/>
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
78
|
+
```ts file="./DropdownBadge.tsx"
|
|
764
79
|
```
|
|
765
80
|
|
|
766
81
|
### Icon only
|
|
767
82
|
|
|
768
|
-
```
|
|
769
|
-
import React from 'react';
|
|
770
|
-
import { Dropdown, DropdownToggle, DropdownItem, DropdownSeparator } from '@patternfly/react-core';
|
|
771
|
-
import ThIcon from '@patternfly/react-icons/dist/esm/icons/th-icon';
|
|
772
|
-
|
|
773
|
-
class IconDropdown extends React.Component {
|
|
774
|
-
constructor(props) {
|
|
775
|
-
super(props);
|
|
776
|
-
this.state = {
|
|
777
|
-
isOpen: false
|
|
778
|
-
};
|
|
779
|
-
this.onToggle = isOpen => {
|
|
780
|
-
this.setState({
|
|
781
|
-
isOpen
|
|
782
|
-
});
|
|
783
|
-
};
|
|
784
|
-
this.onSelect = event => {
|
|
785
|
-
this.setState({
|
|
786
|
-
isOpen: !this.state.isOpen
|
|
787
|
-
});
|
|
788
|
-
this.onFocus();
|
|
789
|
-
};
|
|
790
|
-
this.onFocus = () => {
|
|
791
|
-
const element = document.getElementById('toggle-id-7');
|
|
792
|
-
element.focus();
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
render() {
|
|
797
|
-
const { isOpen } = this.state;
|
|
798
|
-
const dropdownItems = [
|
|
799
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
800
|
-
<DropdownItem key="action" component="button">
|
|
801
|
-
Action
|
|
802
|
-
</DropdownItem>,
|
|
803
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
804
|
-
Disabled link
|
|
805
|
-
</DropdownItem>,
|
|
806
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
807
|
-
Disabled action
|
|
808
|
-
</DropdownItem>,
|
|
809
|
-
<DropdownSeparator key="separator" />,
|
|
810
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
811
|
-
<DropdownItem key="separated action" component="button">
|
|
812
|
-
Separated action
|
|
813
|
-
</DropdownItem>
|
|
814
|
-
];
|
|
815
|
-
return (
|
|
816
|
-
<Dropdown
|
|
817
|
-
onSelect={this.onSelect}
|
|
818
|
-
toggle={
|
|
819
|
-
<DropdownToggle toggleIndicator={null} onToggle={this.onToggle} aria-label="Applications" id="toggle-id-7">
|
|
820
|
-
<ThIcon />
|
|
821
|
-
</DropdownToggle>
|
|
822
|
-
}
|
|
823
|
-
isOpen={isOpen}
|
|
824
|
-
isPlain
|
|
825
|
-
dropdownItems={dropdownItems}
|
|
826
|
-
/>
|
|
827
|
-
);
|
|
828
|
-
}
|
|
829
|
-
}
|
|
83
|
+
```ts file="./DropdownIconOnly.tsx"
|
|
830
84
|
```
|
|
831
85
|
|
|
832
86
|
### Split button
|
|
833
87
|
|
|
834
|
-
```
|
|
835
|
-
import React from 'react';
|
|
836
|
-
import {
|
|
837
|
-
Dropdown,
|
|
838
|
-
DropdownToggle,
|
|
839
|
-
DropdownToggleCheckbox,
|
|
840
|
-
DropdownItem,
|
|
841
|
-
DropdownSeparator
|
|
842
|
-
} from '@patternfly/react-core';
|
|
843
|
-
|
|
844
|
-
class SplitButtonDropdown extends React.Component {
|
|
845
|
-
constructor(props) {
|
|
846
|
-
super(props);
|
|
847
|
-
this.state = {
|
|
848
|
-
isOpen: false
|
|
849
|
-
};
|
|
850
|
-
this.onToggle = isOpen => {
|
|
851
|
-
this.setState({
|
|
852
|
-
isOpen
|
|
853
|
-
});
|
|
854
|
-
};
|
|
855
|
-
this.onSelect = event => {
|
|
856
|
-
this.setState({
|
|
857
|
-
isOpen: !this.state.isOpen
|
|
858
|
-
});
|
|
859
|
-
this.onFocus();
|
|
860
|
-
};
|
|
861
|
-
this.onFocus = () => {
|
|
862
|
-
const element = document.getElementById('toggle-id-8');
|
|
863
|
-
element.focus();
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
render() {
|
|
868
|
-
const { isOpen } = this.state;
|
|
869
|
-
const dropdownItems = [
|
|
870
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
871
|
-
<DropdownItem key="action" component="button">
|
|
872
|
-
Action
|
|
873
|
-
</DropdownItem>,
|
|
874
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
875
|
-
Disabled link
|
|
876
|
-
</DropdownItem>,
|
|
877
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
878
|
-
Disabled action
|
|
879
|
-
</DropdownItem>,
|
|
880
|
-
<DropdownSeparator key="separator" />,
|
|
881
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
882
|
-
<DropdownItem key="separated action" component="button">
|
|
883
|
-
Separated action
|
|
884
|
-
</DropdownItem>
|
|
885
|
-
];
|
|
886
|
-
return (
|
|
887
|
-
<Dropdown
|
|
888
|
-
onSelect={this.onSelect}
|
|
889
|
-
toggle={
|
|
890
|
-
<DropdownToggle
|
|
891
|
-
splitButtonItems={[
|
|
892
|
-
<DropdownToggleCheckbox id="example-checkbox-1" key="split-checkbox" aria-label="Select all" />
|
|
893
|
-
]}
|
|
894
|
-
onToggle={this.onToggle}
|
|
895
|
-
id="toggle-id-8"
|
|
896
|
-
/>
|
|
897
|
-
}
|
|
898
|
-
isOpen={isOpen}
|
|
899
|
-
dropdownItems={dropdownItems}
|
|
900
|
-
/>
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
88
|
+
```ts file="./DropdownSplitButton.tsx"
|
|
904
89
|
```
|
|
905
90
|
|
|
906
91
|
### Split button (with text)
|
|
907
92
|
|
|
908
|
-
```
|
|
909
|
-
import React from 'react';
|
|
910
|
-
import {
|
|
911
|
-
Dropdown,
|
|
912
|
-
DropdownToggle,
|
|
913
|
-
DropdownToggleCheckbox,
|
|
914
|
-
DropdownItem,
|
|
915
|
-
DropdownSeparator
|
|
916
|
-
} from '@patternfly/react-core';
|
|
917
|
-
|
|
918
|
-
class SplitButtonDropdown extends React.Component {
|
|
919
|
-
constructor(props) {
|
|
920
|
-
super(props);
|
|
921
|
-
this.state = {
|
|
922
|
-
isOpen: false
|
|
923
|
-
};
|
|
924
|
-
this.onToggle = isOpen => {
|
|
925
|
-
this.setState({
|
|
926
|
-
isOpen
|
|
927
|
-
});
|
|
928
|
-
};
|
|
929
|
-
this.onSelect = event => {
|
|
930
|
-
this.setState({
|
|
931
|
-
isOpen: !this.state.isOpen
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
render() {
|
|
937
|
-
const { isOpen } = this.state;
|
|
938
|
-
const dropdownItems = [
|
|
939
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
940
|
-
<DropdownItem key="action" component="button">
|
|
941
|
-
Action
|
|
942
|
-
</DropdownItem>,
|
|
943
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
944
|
-
Disabled link
|
|
945
|
-
</DropdownItem>,
|
|
946
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
947
|
-
Disabled action
|
|
948
|
-
</DropdownItem>,
|
|
949
|
-
<DropdownSeparator key="separator" />,
|
|
950
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
951
|
-
<DropdownItem key="separated action" component="button">
|
|
952
|
-
Separated action
|
|
953
|
-
</DropdownItem>
|
|
954
|
-
];
|
|
955
|
-
return (
|
|
956
|
-
<Dropdown
|
|
957
|
-
onSelect={this.onSelect}
|
|
958
|
-
toggle={
|
|
959
|
-
<DropdownToggle
|
|
960
|
-
splitButtonItems={[
|
|
961
|
-
<DropdownToggleCheckbox id="example-checkbox-2" key="split-checkbox" aria-label="Select all">
|
|
962
|
-
10 selected
|
|
963
|
-
</DropdownToggleCheckbox>
|
|
964
|
-
]}
|
|
965
|
-
onToggle={this.onToggle}
|
|
966
|
-
/>
|
|
967
|
-
}
|
|
968
|
-
isOpen={isOpen}
|
|
969
|
-
dropdownItems={dropdownItems}
|
|
970
|
-
/>
|
|
971
|
-
);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
93
|
+
```ts file="./DropdownSplitButtonText.tsx"
|
|
974
94
|
```
|
|
975
95
|
|
|
976
|
-
### Split button (
|
|
96
|
+
### Split button (indeterminate state)
|
|
977
97
|
|
|
978
|
-
```
|
|
979
|
-
import React from 'react';
|
|
980
|
-
import {
|
|
981
|
-
Dropdown,
|
|
982
|
-
DropdownToggle,
|
|
983
|
-
DropdownToggleCheckbox,
|
|
984
|
-
DropdownItem,
|
|
985
|
-
DropdownSeparator
|
|
986
|
-
} from '@patternfly/react-core';
|
|
987
|
-
class SplitButtonDropdown extends React.Component {
|
|
988
|
-
constructor(props) {
|
|
989
|
-
super(props);
|
|
990
|
-
this.state = {
|
|
991
|
-
isOpen: false,
|
|
992
|
-
isChecked: null
|
|
993
|
-
};
|
|
994
|
-
this.onToggle = isOpen => {
|
|
995
|
-
this.setState({
|
|
996
|
-
isOpen
|
|
997
|
-
});
|
|
998
|
-
};
|
|
999
|
-
this.onSelect = event => {
|
|
1000
|
-
this.setState({
|
|
1001
|
-
isOpen: !this.state.isOpen
|
|
1002
|
-
});
|
|
1003
|
-
};
|
|
1004
|
-
this.onChange = isChecked => {
|
|
1005
|
-
this.setState({
|
|
1006
|
-
isChecked
|
|
1007
|
-
});
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
render() {
|
|
1011
|
-
const { isOpen, isChecked } = this.state;
|
|
1012
|
-
const dropdownItems = [
|
|
1013
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
1014
|
-
<DropdownItem key="action" component="button">
|
|
1015
|
-
Action
|
|
1016
|
-
</DropdownItem>,
|
|
1017
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
1018
|
-
Disabled link
|
|
1019
|
-
</DropdownItem>,
|
|
1020
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
1021
|
-
Disabled action
|
|
1022
|
-
</DropdownItem>,
|
|
1023
|
-
<DropdownSeparator key="separator" />,
|
|
1024
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
1025
|
-
<DropdownItem key="separated action" component="button">
|
|
1026
|
-
Separated action
|
|
1027
|
-
</DropdownItem>
|
|
1028
|
-
];
|
|
1029
|
-
return (
|
|
1030
|
-
<Dropdown
|
|
1031
|
-
onSelect={this.onSelect}
|
|
1032
|
-
toggle={
|
|
1033
|
-
<DropdownToggle
|
|
1034
|
-
splitButtonItems={[
|
|
1035
|
-
<DropdownToggleCheckbox
|
|
1036
|
-
id="example-checkbox-3rd-state"
|
|
1037
|
-
key="split-checkbox"
|
|
1038
|
-
aria-label="Select all"
|
|
1039
|
-
onChange={checked => this.onChange(checked)}
|
|
1040
|
-
isChecked={isChecked}
|
|
1041
|
-
/>
|
|
1042
|
-
]}
|
|
1043
|
-
onToggle={this.onToggle}
|
|
1044
|
-
/>
|
|
1045
|
-
}
|
|
1046
|
-
isOpen={isOpen}
|
|
1047
|
-
dropdownItems={dropdownItems}
|
|
1048
|
-
/>
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
98
|
+
```ts file="./DropdownSplitButtonIndeterminate.tsx"
|
|
1052
99
|
```
|
|
1053
100
|
|
|
1054
101
|
### Split button (disabled)
|
|
1055
102
|
|
|
1056
|
-
```
|
|
1057
|
-
import React from 'react';
|
|
1058
|
-
import {
|
|
1059
|
-
Dropdown,
|
|
1060
|
-
DropdownToggle,
|
|
1061
|
-
DropdownToggleCheckbox,
|
|
1062
|
-
DropdownItem,
|
|
1063
|
-
DropdownSeparator
|
|
1064
|
-
} from '@patternfly/react-core';
|
|
1065
|
-
|
|
1066
|
-
class SplitButtonDisabledDropdown extends React.Component {
|
|
1067
|
-
constructor(props) {
|
|
1068
|
-
super(props);
|
|
1069
|
-
this.state = {
|
|
1070
|
-
isOpen: false
|
|
1071
|
-
};
|
|
1072
|
-
this.onToggle = isOpen => {
|
|
1073
|
-
this.setState({
|
|
1074
|
-
isOpen
|
|
1075
|
-
});
|
|
1076
|
-
};
|
|
1077
|
-
this.onSelect = event => {
|
|
1078
|
-
this.setState({
|
|
1079
|
-
isOpen: !this.state.isOpen
|
|
1080
|
-
});
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
render() {
|
|
1085
|
-
const { isOpen } = this.state;
|
|
1086
|
-
const dropdownItems = [
|
|
1087
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
1088
|
-
<DropdownItem key="action" component="button">
|
|
1089
|
-
Action
|
|
1090
|
-
</DropdownItem>,
|
|
1091
|
-
<DropdownItem key="disabled link" isDisabled>
|
|
1092
|
-
Disabled link
|
|
1093
|
-
</DropdownItem>,
|
|
1094
|
-
<DropdownItem key="disabled action" isDisabled component="button">
|
|
1095
|
-
Disabled action
|
|
1096
|
-
</DropdownItem>,
|
|
1097
|
-
<DropdownSeparator key="separator" />,
|
|
1098
|
-
<DropdownItem key="separated link">Separated link</DropdownItem>,
|
|
1099
|
-
<DropdownItem key="separated action" component="button">
|
|
1100
|
-
Separated action
|
|
1101
|
-
</DropdownItem>
|
|
1102
|
-
];
|
|
1103
|
-
return (
|
|
1104
|
-
<Dropdown
|
|
1105
|
-
onSelect={this.onSelect}
|
|
1106
|
-
toggle={
|
|
1107
|
-
<DropdownToggle
|
|
1108
|
-
splitButtonItems={[
|
|
1109
|
-
<DropdownToggleCheckbox
|
|
1110
|
-
id="example-checkbox-3"
|
|
1111
|
-
key="disabled-checkbox"
|
|
1112
|
-
aria-label="Select all"
|
|
1113
|
-
isDisabled
|
|
1114
|
-
/>
|
|
1115
|
-
]}
|
|
1116
|
-
isDisabled
|
|
1117
|
-
onToggle={this.onToggle}
|
|
1118
|
-
/>
|
|
1119
|
-
}
|
|
1120
|
-
isOpen={isOpen}
|
|
1121
|
-
dropdownItems={dropdownItems}
|
|
1122
|
-
/>
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
103
|
+
```ts file="./DropdownSplitButtonDisabled.tsx"
|
|
1126
104
|
```
|
|
1127
105
|
|
|
1128
106
|
### Split button action
|
|
1129
107
|
|
|
1130
|
-
```
|
|
1131
|
-
import React from 'react';
|
|
1132
|
-
import { Dropdown, DropdownToggle, DropdownToggleAction, DropdownItem } from '@patternfly/react-core';
|
|
1133
|
-
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
|
|
1134
|
-
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
|
|
1135
|
-
import CubesIcon from '@patternfly/react-icons/dist/esm/icons/cubes-icon';
|
|
1136
|
-
|
|
1137
|
-
class SplitButtonActionDropdown extends React.Component {
|
|
1138
|
-
constructor(props) {
|
|
1139
|
-
super(props);
|
|
1140
|
-
this.state = {
|
|
1141
|
-
isActionOpen: false,
|
|
1142
|
-
isCogOpen: false
|
|
1143
|
-
};
|
|
1144
|
-
this.onActionToggle = isActionOpen => {
|
|
1145
|
-
this.setState({
|
|
1146
|
-
isActionOpen
|
|
1147
|
-
});
|
|
1148
|
-
};
|
|
1149
|
-
this.onCogToggle = isCogOpen => {
|
|
1150
|
-
this.setState({
|
|
1151
|
-
isCogOpen
|
|
1152
|
-
});
|
|
1153
|
-
};
|
|
1154
|
-
this.onActionClick = event => {
|
|
1155
|
-
window.alert('You selected an action button!');
|
|
1156
|
-
};
|
|
1157
|
-
this.onCogClick = event => {
|
|
1158
|
-
window.alert('You selected the Cog!');
|
|
1159
|
-
};
|
|
1160
|
-
this.onActionSelect = event => {
|
|
1161
|
-
this.setState({
|
|
1162
|
-
isActionOpen: !this.state.isActionOpen
|
|
1163
|
-
});
|
|
1164
|
-
};
|
|
1165
|
-
this.onCogSelect = event => {
|
|
1166
|
-
this.setState({
|
|
1167
|
-
isCogOpen: !this.state.isCogOpen
|
|
1168
|
-
});
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
render() {
|
|
1173
|
-
const { isActionOpen, isCogOpen } = this.state;
|
|
1174
|
-
const dropdownItems = [
|
|
1175
|
-
<DropdownItem key="action" component="button" onClick={this.onActionClick}>
|
|
1176
|
-
Action
|
|
1177
|
-
</DropdownItem>,
|
|
1178
|
-
<DropdownItem key="disabled link" component="button" isDisabled onClick={this.onActionClick}>
|
|
1179
|
-
Disabled action
|
|
1180
|
-
</DropdownItem>,
|
|
1181
|
-
<DropdownItem key="other action" component="button" onClick={this.onActionClick}>
|
|
1182
|
-
Other action
|
|
1183
|
-
</DropdownItem>
|
|
1184
|
-
];
|
|
1185
|
-
const dropdownIconItems = [
|
|
1186
|
-
<DropdownItem key="action" component="button" icon={<CogIcon />} onClick={this.onActionClick}>
|
|
1187
|
-
Action
|
|
1188
|
-
</DropdownItem>,
|
|
1189
|
-
<DropdownItem key="disabled link" component="button" icon={<BellIcon />} isDisabled onClick={this.onActionClick}>
|
|
1190
|
-
Disabled action
|
|
1191
|
-
</DropdownItem>,
|
|
1192
|
-
<DropdownItem key="other action" component="button" icon={<CubesIcon />} onClick={this.onActionClick}>
|
|
1193
|
-
Other action
|
|
1194
|
-
</DropdownItem>
|
|
1195
|
-
];
|
|
1196
|
-
return (
|
|
1197
|
-
<React.Fragment>
|
|
1198
|
-
<Dropdown
|
|
1199
|
-
onSelect={this.onActionSelect}
|
|
1200
|
-
toggle={
|
|
1201
|
-
<DropdownToggle
|
|
1202
|
-
splitButtonItems={[
|
|
1203
|
-
<DropdownToggleAction key="action" onClick={this.onActionClick}>
|
|
1204
|
-
Action
|
|
1205
|
-
</DropdownToggleAction>
|
|
1206
|
-
]}
|
|
1207
|
-
splitButtonVariant="action"
|
|
1208
|
-
onToggle={this.onActionToggle}
|
|
1209
|
-
/>
|
|
1210
|
-
}
|
|
1211
|
-
isOpen={isActionOpen}
|
|
1212
|
-
dropdownItems={dropdownItems}
|
|
1213
|
-
/>{' '}
|
|
1214
|
-
<Dropdown
|
|
1215
|
-
onSelect={this.onCogSelect}
|
|
1216
|
-
toggle={
|
|
1217
|
-
<DropdownToggle
|
|
1218
|
-
splitButtonItems={[
|
|
1219
|
-
<DropdownToggleAction key="cog-action" aria-label="Action" onClick={this.onCogClick}>
|
|
1220
|
-
<CogIcon />
|
|
1221
|
-
</DropdownToggleAction>
|
|
1222
|
-
]}
|
|
1223
|
-
splitButtonVariant="action"
|
|
1224
|
-
onToggle={this.onCogToggle}
|
|
1225
|
-
/>
|
|
1226
|
-
}
|
|
1227
|
-
isOpen={isCogOpen}
|
|
1228
|
-
dropdownItems={dropdownIconItems}
|
|
1229
|
-
/>
|
|
1230
|
-
</React.Fragment>
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
108
|
+
```ts file="./DropdownSplitButtonAction.tsx"
|
|
1234
109
|
```
|
|
1235
110
|
|
|
1236
111
|
### Split button primary action
|
|
1237
112
|
|
|
1238
|
-
```ts
|
|
1239
|
-
import React from 'react';
|
|
1240
|
-
import { Dropdown, DropdownToggle, DropdownToggleAction, DropdownItem } from '@patternfly/react-core';
|
|
1241
|
-
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
|
|
1242
|
-
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
|
|
1243
|
-
import CubesIcon from '@patternfly/react-icons/dist/esm/icons/cubes-icon';
|
|
1244
|
-
|
|
1245
|
-
const PrimarySplitActionDropdown = () => {
|
|
1246
|
-
const [isActionOpen, setIsActionOpen] = React.useState(false);
|
|
1247
|
-
const [isCogOpen, setIsCogOpen] = React.useState(false);
|
|
1248
|
-
|
|
1249
|
-
const onActionClick = () => {
|
|
1250
|
-
window.alert('You selected an action button!');
|
|
1251
|
-
};
|
|
1252
|
-
const onCogClick = () => {
|
|
1253
|
-
window.alert('You selected the Cog!');
|
|
1254
|
-
};
|
|
1255
|
-
|
|
1256
|
-
const dropdownItems = [
|
|
1257
|
-
<DropdownItem key="action" component="button" onClick={onActionClick}>
|
|
1258
|
-
Action
|
|
1259
|
-
</DropdownItem>,
|
|
1260
|
-
<DropdownItem key="disabled link" component="button" isDisabled onClick={onActionClick}>
|
|
1261
|
-
Disabled action
|
|
1262
|
-
</DropdownItem>,
|
|
1263
|
-
<DropdownItem key="other action" component="button" onClick={onActionClick}>
|
|
1264
|
-
Other action
|
|
1265
|
-
</DropdownItem>
|
|
1266
|
-
];
|
|
1267
|
-
const dropdownIconItems = [
|
|
1268
|
-
<DropdownItem key="action" component="button" icon={<CogIcon />} onClick={onActionClick}>
|
|
1269
|
-
Action
|
|
1270
|
-
</DropdownItem>,
|
|
1271
|
-
<DropdownItem key="disabled link" component="button" icon={<BellIcon />} isDisabled onClick={onActionClick}>
|
|
1272
|
-
Disabled action
|
|
1273
|
-
</DropdownItem>,
|
|
1274
|
-
<DropdownItem key="other action" component="button" icon={<CubesIcon />} onClick={onActionClick}>
|
|
1275
|
-
Other action
|
|
1276
|
-
</DropdownItem>
|
|
1277
|
-
];
|
|
1278
|
-
|
|
1279
|
-
return (
|
|
1280
|
-
<React.Fragment>
|
|
1281
|
-
<Dropdown
|
|
1282
|
-
onSelect={() => setIsActionOpen(!isActionOpen)}
|
|
1283
|
-
toggle={
|
|
1284
|
-
<DropdownToggle
|
|
1285
|
-
splitButtonItems={[
|
|
1286
|
-
<DropdownToggleAction key="action" onClick={onActionClick}>
|
|
1287
|
-
Action
|
|
1288
|
-
</DropdownToggleAction>
|
|
1289
|
-
]}
|
|
1290
|
-
toggleVariant="primary"
|
|
1291
|
-
splitButtonVariant="action"
|
|
1292
|
-
onToggle={next => setIsActionOpen(next)}
|
|
1293
|
-
/>
|
|
1294
|
-
}
|
|
1295
|
-
isOpen={isActionOpen}
|
|
1296
|
-
dropdownItems={dropdownItems}
|
|
1297
|
-
/>{' '}
|
|
1298
|
-
<Dropdown
|
|
1299
|
-
onSelect={() => setIsCogOpen(!isCogOpen)}
|
|
1300
|
-
toggle={
|
|
1301
|
-
<DropdownToggle
|
|
1302
|
-
splitButtonItems={[
|
|
1303
|
-
<DropdownToggleAction key="cog-action" aria-label="Action" onClick={onCogClick}>
|
|
1304
|
-
<CogIcon />
|
|
1305
|
-
</DropdownToggleAction>
|
|
1306
|
-
]}
|
|
1307
|
-
toggleVariant="primary"
|
|
1308
|
-
splitButtonVariant="action"
|
|
1309
|
-
onToggle={next => setIsCogOpen(next)}
|
|
1310
|
-
/>
|
|
1311
|
-
}
|
|
1312
|
-
isOpen={isCogOpen}
|
|
1313
|
-
dropdownItems={dropdownIconItems}
|
|
1314
|
-
/>
|
|
1315
|
-
</React.Fragment>
|
|
1316
|
-
);
|
|
1317
|
-
};
|
|
113
|
+
```ts file="./DropdownSplitButtonActionPrimary.tsx"
|
|
1318
114
|
```
|
|
1319
115
|
|
|
1320
116
|
### Basic panel
|
|
1321
117
|
|
|
1322
|
-
```
|
|
1323
|
-
import React from 'react';
|
|
1324
|
-
import { Dropdown, DropdownToggle } from '@patternfly/react-core';
|
|
1325
|
-
|
|
1326
|
-
class DropdownPanel extends React.Component {
|
|
1327
|
-
constructor(props) {
|
|
1328
|
-
super(props);
|
|
1329
|
-
this.state = {
|
|
1330
|
-
isOpen: false
|
|
1331
|
-
};
|
|
1332
|
-
this.onToggle = isOpen => {
|
|
1333
|
-
this.setState({
|
|
1334
|
-
isOpen
|
|
1335
|
-
});
|
|
1336
|
-
};
|
|
1337
|
-
this.onSelect = event => {
|
|
1338
|
-
this.setState({
|
|
1339
|
-
isOpen: !this.state.isOpen
|
|
1340
|
-
});
|
|
1341
|
-
};
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
render() {
|
|
1345
|
-
const { isOpen } = this.state;
|
|
1346
|
-
return (
|
|
1347
|
-
<Dropdown
|
|
1348
|
-
onSelect={this.onSelect}
|
|
1349
|
-
toggle={<DropdownToggle onToggle={this.onToggle}>Expanded dropdown</DropdownToggle>}
|
|
1350
|
-
isOpen={isOpen}
|
|
1351
|
-
>
|
|
1352
|
-
[Panel contents here]
|
|
1353
|
-
</Dropdown>
|
|
1354
|
-
);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
118
|
+
```ts file="./DropdownBasicPanel.tsx"
|
|
1357
119
|
```
|
|
1358
120
|
|
|
1359
121
|
### Router link
|
|
1360
122
|
|
|
1361
|
-
```
|
|
1362
|
-
import React from 'react';
|
|
1363
|
-
import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core';
|
|
1364
|
-
import { Link } from '@reach/router';
|
|
1365
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
1366
|
-
|
|
1367
|
-
class RouterDropdown extends React.Component {
|
|
1368
|
-
constructor(props) {
|
|
1369
|
-
super(props);
|
|
1370
|
-
this.state = {
|
|
1371
|
-
isOpen: false
|
|
1372
|
-
};
|
|
1373
|
-
this.onToggle = isOpen => {
|
|
1374
|
-
this.setState({
|
|
1375
|
-
isOpen
|
|
1376
|
-
});
|
|
1377
|
-
};
|
|
1378
|
-
this.onSelect = event => {
|
|
1379
|
-
this.setState({
|
|
1380
|
-
isOpen: !this.state.isOpen
|
|
1381
|
-
});
|
|
1382
|
-
this.onFocus();
|
|
1383
|
-
};
|
|
1384
|
-
this.onFocus = () => {
|
|
1385
|
-
const element = document.getElementById('toggle-id-8');
|
|
1386
|
-
element.focus();
|
|
1387
|
-
};
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
render() {
|
|
1391
|
-
const { isOpen } = this.state;
|
|
1392
|
-
const dropdownItems = [<DropdownItem key="routerlink" component={<Link to="/">@reach/router Link</Link>} />];
|
|
1393
|
-
|
|
1394
|
-
return (
|
|
1395
|
-
<Dropdown
|
|
1396
|
-
onSelect={this.onSelect}
|
|
1397
|
-
toggle={
|
|
1398
|
-
<DropdownToggle id="toggle-id-8" onToggle={this.onToggle} toggleIndicator={CaretDownIcon}>
|
|
1399
|
-
Dropdown
|
|
1400
|
-
</DropdownToggle>
|
|
1401
|
-
}
|
|
1402
|
-
isOpen={isOpen}
|
|
1403
|
-
dropdownItems={dropdownItems}
|
|
1404
|
-
/>
|
|
1405
|
-
);
|
|
1406
|
-
}
|
|
1407
|
-
}
|
|
123
|
+
```ts file="./DropdownRouterLink.tsx"
|
|
1408
124
|
```
|
|
1409
125
|
|
|
1410
126
|
### Dropdown with image and text
|
|
1411
127
|
|
|
1412
|
-
```
|
|
1413
|
-
import React from 'react';
|
|
1414
|
-
import {
|
|
1415
|
-
Avatar,
|
|
1416
|
-
Dropdown,
|
|
1417
|
-
DropdownGroup,
|
|
1418
|
-
DropdownToggle,
|
|
1419
|
-
DropdownItem,
|
|
1420
|
-
DropdownSeparator
|
|
1421
|
-
} from '@patternfly/react-core';
|
|
1422
|
-
import avatarImg from '../../Avatar/examples/avatarImg.svg';
|
|
1423
|
-
|
|
1424
|
-
class ImageTextDropdown extends React.Component {
|
|
1425
|
-
constructor(props) {
|
|
1426
|
-
super(props);
|
|
1427
|
-
this.state = {
|
|
1428
|
-
isOpen: false
|
|
1429
|
-
};
|
|
1430
|
-
this.onToggle = isOpen => {
|
|
1431
|
-
this.setState({
|
|
1432
|
-
isOpen
|
|
1433
|
-
});
|
|
1434
|
-
};
|
|
1435
|
-
this.onSelect = event => {
|
|
1436
|
-
this.setState({
|
|
1437
|
-
isOpen: !this.state.isOpen
|
|
1438
|
-
});
|
|
1439
|
-
this.onFocus();
|
|
1440
|
-
};
|
|
1441
|
-
this.onFocus = () => {
|
|
1442
|
-
const element = document.getElementById('toggle-id-9');
|
|
1443
|
-
element.focus();
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
render() {
|
|
1448
|
-
const { isOpen } = this.state;
|
|
1449
|
-
const dropdownItems = [
|
|
1450
|
-
<DropdownGroup key="group 1">
|
|
1451
|
-
<DropdownItem key="group 1 plaintext" component="div" isPlainText>
|
|
1452
|
-
Text
|
|
1453
|
-
</DropdownItem>
|
|
1454
|
-
<DropdownItem key="group 1 plaintext2" component="div" isPlainText>
|
|
1455
|
-
More text
|
|
1456
|
-
</DropdownItem>
|
|
1457
|
-
</DropdownGroup>,
|
|
1458
|
-
<DropdownSeparator key="dropdown separator" />,
|
|
1459
|
-
<DropdownGroup key="group 2">
|
|
1460
|
-
<DropdownItem key="group 2 profile">My profile</DropdownItem>
|
|
1461
|
-
<DropdownItem key="group 2 user" component="button">
|
|
1462
|
-
User management
|
|
1463
|
-
</DropdownItem>
|
|
1464
|
-
<DropdownItem key="group 2 logout">Logout</DropdownItem>
|
|
1465
|
-
</DropdownGroup>
|
|
1466
|
-
];
|
|
1467
|
-
return (
|
|
1468
|
-
<Dropdown
|
|
1469
|
-
onSelect={this.onSelect}
|
|
1470
|
-
toggle={
|
|
1471
|
-
<DropdownToggle
|
|
1472
|
-
id="toggle-id-9"
|
|
1473
|
-
onToggle={this.onToggle}
|
|
1474
|
-
toggleIndicator={CaretDownIcon}
|
|
1475
|
-
icon={<Avatar src={avatarImg} alt="avatar"></Avatar>}
|
|
1476
|
-
>
|
|
1477
|
-
Ned Username
|
|
1478
|
-
</DropdownToggle>
|
|
1479
|
-
}
|
|
1480
|
-
isOpen={isOpen}
|
|
1481
|
-
dropdownItems={dropdownItems}
|
|
1482
|
-
/>
|
|
1483
|
-
);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
128
|
+
```ts file="./DropdownImageAndText.tsx"
|
|
1486
129
|
```
|
|
1487
130
|
|
|
1488
131
|
### Appending document body vs parent
|
|
@@ -1493,158 +136,10 @@ Instead append to `"parent"` to achieve the same result without sacrificing acce
|
|
|
1493
136
|
|
|
1494
137
|
In this example, while, after making a selection, both variants retain focus on their respective Dropdown component, the options for the `document.body` variant cannot be navigated to via Voice Over.
|
|
1495
138
|
|
|
1496
|
-
```
|
|
1497
|
-
import React from 'react';
|
|
1498
|
-
import { Dropdown, DropdownToggle, DropdownItem, Flex } from '@patternfly/react-core';
|
|
1499
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
1500
|
-
|
|
1501
|
-
class DropdownDocumentBodyVsParent extends React.Component {
|
|
1502
|
-
constructor(props) {
|
|
1503
|
-
super(props);
|
|
1504
|
-
this.state = {
|
|
1505
|
-
isBodyOpen: false,
|
|
1506
|
-
isParentOpen: false
|
|
1507
|
-
};
|
|
1508
|
-
this.onBodyToggle = isBodyOpen => {
|
|
1509
|
-
this.setState({
|
|
1510
|
-
isBodyOpen
|
|
1511
|
-
});
|
|
1512
|
-
};
|
|
1513
|
-
this.onBodySelect = event => {
|
|
1514
|
-
this.setState({
|
|
1515
|
-
isBodyOpen: !this.state.isBodyOpen
|
|
1516
|
-
});
|
|
1517
|
-
this.onBodyFocus();
|
|
1518
|
-
};
|
|
1519
|
-
this.onBodyFocus = () => {
|
|
1520
|
-
const element = document.getElementById('toggle-id-document-body');
|
|
1521
|
-
element.focus();
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
|
-
this.onParentToggle = isParentOpen => {
|
|
1525
|
-
this.setState({
|
|
1526
|
-
isParentOpen
|
|
1527
|
-
});
|
|
1528
|
-
};
|
|
1529
|
-
this.onParentSelect = event => {
|
|
1530
|
-
this.setState({
|
|
1531
|
-
isParentOpen: !this.state.isParentOpen
|
|
1532
|
-
});
|
|
1533
|
-
this.onParentFocus();
|
|
1534
|
-
};
|
|
1535
|
-
this.onParentFocus = () => {
|
|
1536
|
-
const element = document.getElementById('toggle-id-parent');
|
|
1537
|
-
element.focus();
|
|
1538
|
-
};
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
render() {
|
|
1542
|
-
const { isBodyOpen, isParentOpen } = this.state;
|
|
1543
|
-
const dropdownItems = [
|
|
1544
|
-
<DropdownItem key="link">Link</DropdownItem>,
|
|
1545
|
-
<DropdownItem key="action" component="button">
|
|
1546
|
-
Action
|
|
1547
|
-
</DropdownItem>,
|
|
1548
|
-
<DropdownItem key="disabled link" isDisabled href="www.google.com">
|
|
1549
|
-
Disabled link
|
|
1550
|
-
</DropdownItem>
|
|
1551
|
-
];
|
|
1552
|
-
return (
|
|
1553
|
-
<Flex>
|
|
1554
|
-
<Dropdown
|
|
1555
|
-
onSelect={this.onBodySelect}
|
|
1556
|
-
toggle={
|
|
1557
|
-
<DropdownToggle id="toggle-id-document-body" onToggle={this.onBodyToggle} toggleIndicator={CaretDownIcon}>
|
|
1558
|
-
Dropdown - Document Body
|
|
1559
|
-
</DropdownToggle>
|
|
1560
|
-
}
|
|
1561
|
-
isOpen={isBodyOpen}
|
|
1562
|
-
dropdownItems={dropdownItems}
|
|
1563
|
-
menuAppendTo={() => document.body}
|
|
1564
|
-
/>
|
|
1565
|
-
<Dropdown
|
|
1566
|
-
onSelect={this.onParentSelect}
|
|
1567
|
-
toggle={
|
|
1568
|
-
<DropdownToggle id="toggle-id-parent" onToggle={this.onParentToggle} toggleIndicator={CaretDownIcon}>
|
|
1569
|
-
Dropdown - Parent
|
|
1570
|
-
</DropdownToggle>
|
|
1571
|
-
}
|
|
1572
|
-
isOpen={isParentOpen}
|
|
1573
|
-
dropdownItems={dropdownItems}
|
|
1574
|
-
menuAppendTo="parent"
|
|
1575
|
-
/>
|
|
1576
|
-
</Flex>
|
|
1577
|
-
);
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
139
|
+
```ts file="./DropdownAppendBodyVsParent.tsx"
|
|
1580
140
|
```
|
|
1581
141
|
|
|
1582
142
|
### Dropdown with descriptions
|
|
1583
143
|
|
|
1584
|
-
```
|
|
1585
|
-
import React from 'react';
|
|
1586
|
-
import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core';
|
|
1587
|
-
import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon';
|
|
1588
|
-
import CaretDownIcon from '@patternfly/react-icons/dist/esm/icons/caret-down-icon';
|
|
1589
|
-
import CubesIcon from '@patternfly/react-icons/dist/esm/icons/cubes-icon';
|
|
1590
|
-
|
|
1591
|
-
class SimpleDropdown extends React.Component {
|
|
1592
|
-
constructor(props) {
|
|
1593
|
-
super(props);
|
|
1594
|
-
this.state = {
|
|
1595
|
-
isOpen: false
|
|
1596
|
-
};
|
|
1597
|
-
this.onToggle = isOpen => {
|
|
1598
|
-
this.setState({
|
|
1599
|
-
isOpen
|
|
1600
|
-
});
|
|
1601
|
-
};
|
|
1602
|
-
this.onSelect = event => {
|
|
1603
|
-
this.setState({
|
|
1604
|
-
isOpen: !this.state.isOpen
|
|
1605
|
-
});
|
|
1606
|
-
this.onFocus();
|
|
1607
|
-
};
|
|
1608
|
-
this.onFocus = () => {
|
|
1609
|
-
const element = document.getElementById('toggle-id');
|
|
1610
|
-
element.focus();
|
|
1611
|
-
};
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
render() {
|
|
1615
|
-
const { isOpen } = this.state;
|
|
1616
|
-
|
|
1617
|
-
const dropdownItems = [
|
|
1618
|
-
<DropdownItem key="link" description="This is a description" icon={<CubesIcon />}>
|
|
1619
|
-
Link
|
|
1620
|
-
</DropdownItem>,
|
|
1621
|
-
<DropdownItem
|
|
1622
|
-
key="action"
|
|
1623
|
-
component="button"
|
|
1624
|
-
icon={<BellIcon />}
|
|
1625
|
-
description="This is a very long description that describes the menu item"
|
|
1626
|
-
>
|
|
1627
|
-
Action
|
|
1628
|
-
</DropdownItem>,
|
|
1629
|
-
<DropdownItem key="disabled link" isDisabled description="Disabled link description">
|
|
1630
|
-
Disabled link
|
|
1631
|
-
</DropdownItem>,
|
|
1632
|
-
<DropdownItem key="disabled action" isDisabled component="button" description="This is a description">
|
|
1633
|
-
Disabled action
|
|
1634
|
-
</DropdownItem>
|
|
1635
|
-
];
|
|
1636
|
-
return (
|
|
1637
|
-
<Dropdown
|
|
1638
|
-
onSelect={this.onSelect}
|
|
1639
|
-
toggle={
|
|
1640
|
-
<DropdownToggle id="toggle-id" onToggle={this.onToggle} toggleIndicator={CaretDownIcon}>
|
|
1641
|
-
Dropdown
|
|
1642
|
-
</DropdownToggle>
|
|
1643
|
-
}
|
|
1644
|
-
isOpen={isOpen}
|
|
1645
|
-
dropdownItems={dropdownItems}
|
|
1646
|
-
/>
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
144
|
+
```ts file="./DropdownDescriptions.tsx"
|
|
1650
145
|
```
|