@splunk/react-ui 5.7.1 → 5.9.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/Accordion.js +6 -6
- package/Anchor.js +2 -1
- package/Box.js +83 -34
- package/CHANGELOG.md +51 -0
- package/Calendar.js +134 -134
- package/Clickable.js +131 -94
- package/CollapsiblePanel.js +175 -137
- package/ComboBox.js +32 -27
- package/ControlGroup.js +92 -91
- package/DefinitionList.js +9 -9
- package/Drawer.d.ts +2 -0
- package/Drawer.js +679 -0
- package/Dropdown.js +27 -18
- package/DualListbox.js +1 -1
- package/File.js +35 -35
- package/JSONTree.js +73 -72
- package/Link.js +2 -2
- package/MIGRATION.md +10 -0
- package/Menu.js +403 -261
- package/Modal.js +263 -252
- package/Monogram.js +2 -2
- package/Multiselect.js +551 -385
- package/Number.js +2 -1
- package/Paginator.js +14 -12
- package/Popover.js +4 -1
- package/README.md +11 -0
- package/RadioBar.js +1 -1
- package/Search.js +111 -95
- package/Select.js +42 -40
- package/SelectBase.js +819 -715
- package/SidePanel.js +346 -167
- package/SlidingPanels.js +11 -11
- package/StepBar.js +7 -7
- package/Switch.js +5 -5
- package/Table.js +116 -119
- package/Text.js +48 -48
- package/TextArea.js +7 -7
- package/TransitionOpen.js +188 -169
- package/docs-llm/Accordion.md +267 -0
- package/docs-llm/Anchor Menu.md +115 -0
- package/docs-llm/Anchor.md +54 -0
- package/docs-llm/AnimationToggle.md +254 -0
- package/docs-llm/Avatar.md +292 -0
- package/docs-llm/Badge.md +212 -0
- package/docs-llm/Breadcrumbs.md +306 -0
- package/docs-llm/Button Group.md +53 -0
- package/docs-llm/Button.md +361 -0
- package/docs-llm/Card Layout.md +286 -0
- package/docs-llm/Card.md +619 -0
- package/docs-llm/Checkbox.md +218 -0
- package/docs-llm/Chip.md +291 -0
- package/docs-llm/Clickable.md +160 -0
- package/docs-llm/Code.md +292 -0
- package/docs-llm/Collapsible Panel.md +744 -0
- package/docs-llm/Color.md +253 -0
- package/docs-llm/Column Layout.md +391 -0
- package/docs-llm/Combo Box.md +540 -0
- package/docs-llm/Control Group.md +594 -0
- package/docs-llm/Date.md +270 -0
- package/docs-llm/Definition List.md +278 -0
- package/docs-llm/Divider.md +216 -0
- package/docs-llm/Drawer.md +414 -0
- package/docs-llm/Dropdown.md +472 -0
- package/docs-llm/Dual Listbox.md +325 -0
- package/docs-llm/File.md +653 -0
- package/docs-llm/Form Rows.md +374 -0
- package/docs-llm/Heading.md +179 -0
- package/docs-llm/Image.md +109 -0
- package/docs-llm/JSON Tree.md +260 -0
- package/docs-llm/Layer.md +74 -0
- package/docs-llm/Layout.md +50 -0
- package/docs-llm/Link.md +318 -0
- package/docs-llm/List.md +189 -0
- package/docs-llm/Markdown.md +179 -0
- package/docs-llm/Menu.md +735 -0
- package/docs-llm/Message Bar.md +236 -0
- package/docs-llm/Message.md +248 -0
- package/docs-llm/Modal.md +443 -0
- package/docs-llm/Monogram.md +159 -0
- package/docs-llm/Multiselect.md +939 -0
- package/docs-llm/Notifications.md +46 -0
- package/docs-llm/Number.md +298 -0
- package/docs-llm/Paginator.md +395 -0
- package/docs-llm/Paragraph.md +148 -0
- package/docs-llm/Phone Number.md +254 -0
- package/docs-llm/Popover.md +166 -0
- package/docs-llm/Progress.md +141 -0
- package/docs-llm/Radio Bar.md +303 -0
- package/docs-llm/Radio List.md +350 -0
- package/docs-llm/Resize.md +362 -0
- package/docs-llm/Screen Reader Content.md +73 -0
- package/docs-llm/Scroll Container Context.md +155 -0
- package/docs-llm/Scroll.md +152 -0
- package/docs-llm/Search.md +381 -0
- package/docs-llm/Select.md +985 -0
- package/docs-llm/Side Panel.md +777 -0
- package/docs-llm/Slider.md +339 -0
- package/docs-llm/Sliding Panels.md +340 -0
- package/docs-llm/Split Button.md +295 -0
- package/docs-llm/Static Content.md +90 -0
- package/docs-llm/Step Bar.md +292 -0
- package/docs-llm/Switch.md +268 -0
- package/docs-llm/Tab Bar.md +439 -0
- package/docs-llm/Tab Layout.md +398 -0
- package/docs-llm/Table.md +2642 -0
- package/docs-llm/Text Area.md +253 -0
- package/docs-llm/Text.md +339 -0
- package/docs-llm/Tooltip.md +325 -0
- package/docs-llm/Transition Open.md +406 -0
- package/docs-llm/Tree.md +591 -0
- package/docs-llm/Typography.md +125 -0
- package/docs-llm/Wait Spinner.md +121 -0
- package/docs-llm/llms.txt +101 -0
- package/package.json +6 -5
- package/types/src/Box/Box.d.ts +2 -10
- package/types/src/Drawer/Body.d.ts +17 -0
- package/types/src/Drawer/Drawer.d.ts +114 -0
- package/types/src/Drawer/DrawerContext.d.ts +11 -0
- package/types/src/Drawer/Footer.d.ts +25 -0
- package/types/src/Drawer/Header.d.ts +41 -0
- package/types/src/Drawer/docs/examples/Basic.d.ts +6 -0
- package/types/src/Drawer/docs/examples/ContainerPosition.d.ts +7 -0
- package/types/src/Drawer/docs/examples/InitialFocus.d.ts +9 -0
- package/types/src/Drawer/docs/examples/InlinePosition.d.ts +7 -0
- package/types/src/Drawer/docs/examples/PagePosition.d.ts +7 -0
- package/types/src/Drawer/index.d.ts +2 -0
- package/types/src/JSONTree/JSONTree.d.ts +12 -5
- package/types/src/JSONTree/renderTreeItems.d.ts +2 -1
- package/types/src/Menu/Item.d.ts +2 -1
- package/types/src/Menu/docs/examples/SelectableCheckbox.d.ts +7 -0
- package/types/src/Modal/Modal.d.ts +1 -2
- package/types/src/Multiselect/Compact.d.ts +8 -3
- package/types/src/Multiselect/Multiselect.d.ts +8 -3
- package/types/src/Multiselect/Normal.d.ts +8 -3
- package/types/src/Multiselect/Option.d.ts +6 -3
- package/types/src/Multiselect/docs/examples/Disabled.d.ts +1 -0
- package/types/src/Select/Option.d.ts +6 -3
- package/types/src/Select/Select.d.ts +8 -5
- package/types/src/Select/docs/examples/Dimmed.d.ts +7 -0
- package/types/src/SelectBase/OptionBase.d.ts +6 -3
- package/types/src/SelectBase/SelectBase.d.ts +8 -3
- package/types/src/SidePanel/SidePanel.d.ts +43 -2
- package/types/src/SidePanel/docs/examples/DockLayout.d.ts +17 -0
- package/types/src/SidePanel/docs/examples/InitialFocus.d.ts +9 -0
- package/types/src/TransitionOpen/TransitionOpen.d.ts +29 -4
- package/types/src/useKeyPress/index.d.ts +9 -2
- package/types/src/useOnClickOutside/index.d.ts +2 -0
- package/types/src/useOnClickOutside/useOnClickOutside.d.ts +4 -0
- package/useKeyPress.js +23 -18
- package/useOnClickOutside.d.ts +2 -0
- package/useOnClickOutside.js +79 -0
- package/types/src/RadioList/docs/examples/Row.d.ts +0 -6
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Radio Bar
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of a Radio Bar component.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## When to use this component
|
|
10
|
+
- For quick selection within a form. Use only if there are less than 8 options that are simple and straightforward.
|
|
11
|
+
- As a filter for related content (e.g. filter messages by “All”, “Read”, and “Unread”).
|
|
12
|
+
- Useful to switch between alternate views of the same set of data in the same context. (e.g. list view, grid view, or map view).
|
|
13
|
+
- If additional visual affordances and adornments, such as icons, can provide separation between options.
|
|
14
|
+
|
|
15
|
+
## When to use another component
|
|
16
|
+
- If vertical space is not a concern or the options labels are long, use Radio List.
|
|
17
|
+
- For binary selections like “on/off”, “yes/no”, “true/false”, consider using a Switch - Toggle.
|
|
18
|
+
- Use Tab Bar to change the entire display of different sets of data, as a form of navigation.
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
graph TD
|
|
22
|
+
accDescr: Decision tree that guides on when to use the RadioBar component or something else
|
|
23
|
+
A(Are users selecting an option in the context of a form?) -- Yes --- B(Are there fewer than 8 options?)
|
|
24
|
+
B -- Yes --- C(Do the options have long labels or you don't need to conserve vertical space?)
|
|
25
|
+
C -- Yes --- D(Radio List)
|
|
26
|
+
C -- No --- E(Radio Bar)
|
|
27
|
+
B -- No --- F(Select or Combo Box)
|
|
28
|
+
A -- No --- G(Do the options work as a form of navigation or switch between completely different content?)
|
|
29
|
+
G -- Yes --- H(Tabs)
|
|
30
|
+
G -- No --- I(Radio Bar)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Check out
|
|
34
|
+
- [Radio List][1]
|
|
35
|
+
- [Switch][2]
|
|
36
|
+
- [Tab Bar][3]
|
|
37
|
+
- [Select][4]
|
|
38
|
+
- [Combo Box][5]
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Inutitive icons
|
|
43
|
+
Use icon-only variants when the icons are intuitive and easy to understand.
|
|
44
|
+
|
|
45
|
+
> Image: Examples of a icon-only Radio Bar with two options. In the first example with heart eyes emojis, the icons are intutive
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Radio Bar as a menu bar
|
|
49
|
+
Radio Bar can be used outside the context of a form and behave like a menu `role="menubar"`. When used in this context, ensure the options are straightforward and mutually exclusive.
|
|
50
|
+
|
|
51
|
+
> Image: Examples of a Radio Bar with two options. In the first example with heart eyes emojis, the options are
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Content
|
|
55
|
+
|
|
56
|
+
### Be concise
|
|
57
|
+
Keep option labels short and concise to prevent text wrapping. Use sentence-case capitalization and avoid punctuation and articles (“the”, “an”, “a”).
|
|
58
|
+
|
|
59
|
+
> Image: Examples of a Radio Bar with two options. In the first example with heart eyes emojis, the options are
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[1]: ./RadioList
|
|
63
|
+
[2]: ./Switch
|
|
64
|
+
[3]: ./TabBar
|
|
65
|
+
[4]: ./Select
|
|
66
|
+
[5]: ./ComboBox
|
|
67
|
+
|
|
68
|
+
## Examples
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Controlled
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import React, { useState } from 'react';
|
|
75
|
+
|
|
76
|
+
import RadioBar, { RadioBarChangeHandler } from '@splunk/react-ui/RadioBar';
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
function Basic() {
|
|
80
|
+
const [value, setValue] = useState(3);
|
|
81
|
+
|
|
82
|
+
const handleChange: RadioBarChangeHandler = (e, { value: radioValue }) => {
|
|
83
|
+
setValue(radioValue);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<RadioBar onChange={handleChange} value={value} style={{ width: 500 }}>
|
|
88
|
+
<RadioBar.Option value={1} label="one" />
|
|
89
|
+
<RadioBar.Option value={2} label="two" />
|
|
90
|
+
<RadioBar.Option value={3} label="threethreethree" />
|
|
91
|
+
<RadioBar.Option value={4} label="four" />
|
|
92
|
+
</RadioBar>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default Basic;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Uncontrolled
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import React from 'react';
|
|
105
|
+
|
|
106
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
function Uncontrolled() {
|
|
110
|
+
return (
|
|
111
|
+
<RadioBar defaultValue={2} style={{ width: 500 }}>
|
|
112
|
+
<RadioBar.Option value={1} label="one" />
|
|
113
|
+
<RadioBar.Option value={2} label="two" />
|
|
114
|
+
<RadioBar.Option value={3} label="threethreethree" />
|
|
115
|
+
<RadioBar.Option value={4} label="four" />
|
|
116
|
+
</RadioBar>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default Uncontrolled;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Error
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import React from 'react';
|
|
129
|
+
|
|
130
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
function RadioBarError() {
|
|
134
|
+
return (
|
|
135
|
+
<RadioBar defaultValue={2} style={{ width: 500 }} error>
|
|
136
|
+
<RadioBar.Option value={1} label="one" />
|
|
137
|
+
<RadioBar.Option value={2} label="two" />
|
|
138
|
+
<RadioBar.Option value={3} label="threethreethree" />
|
|
139
|
+
<RadioBar.Option value={4} label="four" />
|
|
140
|
+
</RadioBar>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default RadioBarError;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
### Disabled
|
|
150
|
+
|
|
151
|
+
Either the entire RadioBar or individual Options can be disabled using the disabled prop. When set on the RadioBar, this overrides any individual Option disabled states.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import React from 'react';
|
|
155
|
+
|
|
156
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
function Disabled() {
|
|
160
|
+
return (
|
|
161
|
+
<RadioBar defaultValue={2} disabled style={{ width: 500 }}>
|
|
162
|
+
<RadioBar.Option value={1} label="one" />
|
|
163
|
+
<RadioBar.Option value={2} label="two" />
|
|
164
|
+
<RadioBar.Option value={3} label="threethreethree" />
|
|
165
|
+
<RadioBar.Option value={4} label="four" />
|
|
166
|
+
</RadioBar>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default Disabled;
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### Adornments using `aria-*` attributes
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import React from 'react';
|
|
179
|
+
|
|
180
|
+
import styled from 'styled-components';
|
|
181
|
+
|
|
182
|
+
import ChartArea from '@splunk/react-icons/ChartArea';
|
|
183
|
+
import ChartBubble from '@splunk/react-icons/ChartBubble';
|
|
184
|
+
import ChartLine from '@splunk/react-icons/ChartLine';
|
|
185
|
+
import Plus from '@splunk/react-icons/Plus';
|
|
186
|
+
import Chip from '@splunk/react-ui/Chip';
|
|
187
|
+
import RadioBar from '@splunk/react-ui/RadioBar';
|
|
188
|
+
import { mixins, variables } from '@splunk/themes';
|
|
189
|
+
|
|
190
|
+
const StyledNewChip = styled(Chip)`
|
|
191
|
+
${mixins.typography('smallBody', { weight: 'bold' })}
|
|
192
|
+
background-color: ${variables.notificationColorInfoWeak};
|
|
193
|
+
height: calc(${variables.inputHeight} - ${variables.spacingMedium});
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
function AdornmentAriaExamples() {
|
|
198
|
+
return (
|
|
199
|
+
<RadioBar defaultValue={3} style={{ width: 800 }}>
|
|
200
|
+
<RadioBar.Option value={1} label="Option one" endAdornment={<ChartLine />} />
|
|
201
|
+
<RadioBar.Option value={2} label="Option two" startAdornment={<ChartBubble />} />
|
|
202
|
+
|
|
203
|
+
<RadioBar.Option
|
|
204
|
+
value={3}
|
|
205
|
+
label="Option three"
|
|
206
|
+
aria-describedby="new"
|
|
207
|
+
endAdornment={<StyledNewChip id="new">New</StyledNewChip>}
|
|
208
|
+
/>
|
|
209
|
+
|
|
210
|
+
<RadioBar.Option
|
|
211
|
+
value={4}
|
|
212
|
+
label="Option four"
|
|
213
|
+
startAdornment={<Plus />}
|
|
214
|
+
endAdornment={<ChartArea />}
|
|
215
|
+
/>
|
|
216
|
+
</RadioBar>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export default AdornmentAriaExamples;
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
### menubar
|
|
226
|
+
|
|
227
|
+
Radio Bar can be used outside of a form context to behave like a menu bar by setting role="menubar"
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import React, { useState } from 'react';
|
|
231
|
+
|
|
232
|
+
import RadioBar, { RadioBarChangeHandler } from '@splunk/react-ui/RadioBar';
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
function MenuBar() {
|
|
236
|
+
const [value, setValue] = useState('ts');
|
|
237
|
+
|
|
238
|
+
const handleChange: RadioBarChangeHandler = (e, { value: radioValue }) => {
|
|
239
|
+
setValue(radioValue);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<RadioBar role="menubar" onChange={handleChange} value={value}>
|
|
244
|
+
<RadioBar.Option value="ts" label="Typescript" />
|
|
245
|
+
<RadioBar.Option value="js" label="Javascript" />
|
|
246
|
+
</RadioBar>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default MenuBar;
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
## API
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
### RadioBar API
|
|
260
|
+
|
|
261
|
+
RadioBar is a form control that provides the ability to select one option out of a group.
|
|
262
|
+
|
|
263
|
+
#### Props
|
|
264
|
+
|
|
265
|
+
| Name | Type | Required | Default | Description |
|
|
266
|
+
|------|------|------|------|------|
|
|
267
|
+
| children | React.ReactNode | no | | `children` should be `RadioBar.Option`. |
|
|
268
|
+
| defaultValue | string \| number \| boolean | no | | The default value. Only applicable if this is an uncontrolled component. Otherwise, use the value prop. |
|
|
269
|
+
| describedBy | string | no | | The id of the description. When placed in a ControlGroup, this is automatically set to the ControlGroup's help component. |
|
|
270
|
+
| disabled | boolean | no | false | Disable all options in the RadioBar. This will override the disabled prop on any individual Option. |
|
|
271
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts, and null when it unmounts. |
|
|
272
|
+
| error | boolean | no | | Highlight the field as having an error. The buttons will turn red. |
|
|
273
|
+
| inline | boolean | no | | |
|
|
274
|
+
| labelledBy | string | no | | The id of the label. When placed in a ControlGroup, this is automatically set to the ControlGroup's label. |
|
|
275
|
+
| name | string | no | | The name is returned with onChange events, which can be used to identify the control when multiple controls share an onChange callback. |
|
|
276
|
+
| onChange | RadioBarChangeHandler | no | | A callback that receives the new value. |
|
|
277
|
+
| role | 'radiogroup' \| 'menubar' | no | 'radiogroup' | The role of the RadioBar. The children Options' `role` will be set to `radio` or `menuitemradio` respectively. |
|
|
278
|
+
| value | string \| number \| boolean | no | | The currently selected value. Only applicable if this is a controlled component. |
|
|
279
|
+
|
|
280
|
+
#### Types
|
|
281
|
+
|
|
282
|
+
| Name | Type | Description |
|
|
283
|
+
|------|------|------|
|
|
284
|
+
| RadioBarChangeHandler | ( e: React.MouseEvent<HTMLButtonElement \| HTMLAnchorElement> \| React.KeyboardEvent<HTMLElement>, data: { label?: string; name?: string; value: any; // eslint-disable-line @typescript-eslint/no-explicit-any } ) => void | |
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
### RadioBar.Option API
|
|
289
|
+
|
|
290
|
+
#### Props
|
|
291
|
+
|
|
292
|
+
| Name | Type | Required | Default | Description |
|
|
293
|
+
|------|------|------|------|------|
|
|
294
|
+
| disabled | boolean | no | | Add a disabled attribute and prevent clicking. |
|
|
295
|
+
| endAdornment | React.ReactNode | no | | Adornment after the label. |
|
|
296
|
+
| label | string | no | | The text shown on the button. |
|
|
297
|
+
| startAdornment | React.ReactNode | no | | Adornment in front of the label. |
|
|
298
|
+
| value | any | yes | | The value of the `Option`. |
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
# Radio List
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> Image: Illustration of a Radio List component.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## When to use this component
|
|
10
|
+
- To select a single option from a set of two or more that are mutually exclusive.
|
|
11
|
+
- Exposing all available options would benefits the user.
|
|
12
|
+
|
|
13
|
+
## When to use another component
|
|
14
|
+
- The options a user has are opposing states (e.g. on/off, before/after). Use a Switch instead.
|
|
15
|
+
- More than one option can be selected; use a Checkbox or Multiselect component.
|
|
16
|
+
- Visual indicators (like icons for Radio Bar) help the user find an option faster.
|
|
17
|
+
- Options can be collapsed; use Select or Combo Box to conserve space.
|
|
18
|
+
|
|
19
|
+
```mermaid
|
|
20
|
+
graph TD
|
|
21
|
+
accDescr: Decision tree that guides on when to use the RadioList component or something else
|
|
22
|
+
A(Are there fewer than 8 options?) -- Yes --- B("Do the options have long labels or you don't need to conserve vertical space?")
|
|
23
|
+
B -- Yes --- C(Radio List)
|
|
24
|
+
B -- No --- D(Radio Bar)
|
|
25
|
+
A -- No --- E(Select or Combo Box)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Check out
|
|
29
|
+
- [Switch][1]
|
|
30
|
+
- [Multiselect][2]
|
|
31
|
+
- [Select][3]
|
|
32
|
+
- [Radio Bar][4]
|
|
33
|
+
- [Combo Box][5]
|
|
34
|
+
|
|
35
|
+
## Behaviors
|
|
36
|
+
|
|
37
|
+
### Customization
|
|
38
|
+
Child elements, like a text input, can be included if necessary.
|
|
39
|
+
|
|
40
|
+
> Image: Image of a Radio List with the label,
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Always include a label
|
|
46
|
+
> Image: Examples of a Radio List with the three options,
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Make options distinct
|
|
50
|
+
Users should be able to easily differentiate between options.
|
|
51
|
+
> Image: Examples of mutual exclusivity: The first example with the heart eyes emoji shows a Radio List with the options,
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### List options in a logical order
|
|
55
|
+
Order your list of options in a way that will make the most sense. Possible orders include:
|
|
56
|
+
- Most likely to least likely to be selected
|
|
57
|
+
- Simplest to most complex operation
|
|
58
|
+
- Least to most risk
|
|
59
|
+
|
|
60
|
+
> Image: Examples of a Radio List with label
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Default option
|
|
64
|
+
An option must be selected at all times. If you need an unselected state, add a "None" option.
|
|
65
|
+
|
|
66
|
+
> Image: Examples of a Radio List with label
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Content
|
|
71
|
+
|
|
72
|
+
### Avoid punctuation and articles (“the”, “an”, “a”)
|
|
73
|
+
Be descriptive, not instructional. If the selection needs more explanation, use help text.
|
|
74
|
+
|
|
75
|
+
> Image: Examples of label punctuation: The first example with the heart eyes emoji shows a Radio List with the label,
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
### Keep descriptions concise
|
|
79
|
+
Descriptions should be text only and short enough that bullet points aren't needed. If more detail is needed, move the description outside of the radio list.
|
|
80
|
+
|
|
81
|
+
> Image: Examples of description length: The first example with the heart eyes emoji shows a Radio List with label
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
[1]: ./Switch
|
|
85
|
+
[2]: ./Multiselect
|
|
86
|
+
[3]: ./Select
|
|
87
|
+
[4]: ./RadioBar
|
|
88
|
+
[5]: ./ComboBox
|
|
89
|
+
|
|
90
|
+
## Examples
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
### Controlled
|
|
94
|
+
|
|
95
|
+
Radio List requires a value prop and an onChange callback to update the value prop for most use cases.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import React, { useState } from 'react';
|
|
99
|
+
|
|
100
|
+
import RadioList, { RadioListChangeHandler, RadioListValueTypes } from '@splunk/react-ui/RadioList';
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
function Basic() {
|
|
104
|
+
const [value, setValue] = useState<RadioListValueTypes>(2);
|
|
105
|
+
|
|
106
|
+
const handleChange: RadioListChangeHandler = (e, { value: radioValue }) => {
|
|
107
|
+
setValue(radioValue);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<RadioList value={value} onChange={handleChange}>
|
|
112
|
+
<RadioList.Option value={1}>One</RadioList.Option>
|
|
113
|
+
<RadioList.Option value={2}>Two</RadioList.Option>
|
|
114
|
+
<RadioList.Option value={3}>Three three three</RadioList.Option>
|
|
115
|
+
<RadioList.Option disabled value={4}>
|
|
116
|
+
Four
|
|
117
|
+
</RadioList.Option>
|
|
118
|
+
</RadioList>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default Basic;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### Uncontrolled
|
|
128
|
+
|
|
129
|
+
Alternately, Radio List can be uncontrolled and optionally provided a defaultValue. The onChange callback still fires. The value prop cannot be set or updated externally.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import React from 'react';
|
|
133
|
+
|
|
134
|
+
import RadioList from '@splunk/react-ui/RadioList';
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
function Uncontrolled() {
|
|
138
|
+
return (
|
|
139
|
+
<RadioList defaultValue={2}>
|
|
140
|
+
<RadioList.Option value={1}>One</RadioList.Option>
|
|
141
|
+
<RadioList.Option value={2}>Two</RadioList.Option>
|
|
142
|
+
<RadioList.Option value={3}>Three three three</RadioList.Option>
|
|
143
|
+
<RadioList.Option value={4}>Four</RadioList.Option>
|
|
144
|
+
</RadioList>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default Uncontrolled;
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Disabled
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import React, { useState } from 'react';
|
|
157
|
+
|
|
158
|
+
import RadioList, { RadioListChangeHandler, RadioListValueTypes } from '@splunk/react-ui/RadioList';
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
function Disabled() {
|
|
162
|
+
const [value, setValue] = useState<RadioListValueTypes>(2);
|
|
163
|
+
|
|
164
|
+
const handleChange: RadioListChangeHandler = (e, { value: radioValue }) => {
|
|
165
|
+
setValue(radioValue);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<RadioList value={value} disabled onChange={handleChange}>
|
|
170
|
+
<RadioList.Option value={1}>One</RadioList.Option>
|
|
171
|
+
<RadioList.Option value={2}>Two</RadioList.Option>
|
|
172
|
+
<RadioList.Option value={3}>Three three three</RadioList.Option>
|
|
173
|
+
<RadioList.Option disabled value={4}>
|
|
174
|
+
Four
|
|
175
|
+
</RadioList.Option>
|
|
176
|
+
</RadioList>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default Disabled;
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
### Error
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import React, { useState } from 'react';
|
|
189
|
+
|
|
190
|
+
import RadioList, { RadioListChangeHandler, RadioListValueTypes } from '@splunk/react-ui/RadioList';
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
function RadioListError() {
|
|
194
|
+
const [value, setValue] = useState<RadioListValueTypes>(2);
|
|
195
|
+
|
|
196
|
+
const handleChange: RadioListChangeHandler = (e, { value: radioValue }) => {
|
|
197
|
+
setValue(radioValue);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<RadioList value={value} onChange={handleChange} error>
|
|
202
|
+
<RadioList.Option value={1}>One</RadioList.Option>
|
|
203
|
+
<RadioList.Option value={2}>Two</RadioList.Option>
|
|
204
|
+
<RadioList.Option value={3}>Three three three</RadioList.Option>
|
|
205
|
+
<RadioList.Option value={4}>Four</RadioList.Option>
|
|
206
|
+
</RadioList>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default RadioListError;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
### Description
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import React from 'react';
|
|
219
|
+
|
|
220
|
+
import RadioList from '@splunk/react-ui/RadioList';
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
function Description() {
|
|
224
|
+
return (
|
|
225
|
+
<RadioList defaultValue={2}>
|
|
226
|
+
<RadioList.Option value={1} description="This is the first option.">
|
|
227
|
+
One
|
|
228
|
+
</RadioList.Option>
|
|
229
|
+
<RadioList.Option value={2} description="This is the second option.">
|
|
230
|
+
Two
|
|
231
|
+
</RadioList.Option>
|
|
232
|
+
<RadioList.Option value={3} description="This is the third option.">
|
|
233
|
+
Three three three
|
|
234
|
+
</RadioList.Option>
|
|
235
|
+
<RadioList.Option value={4} description="This is the fourth option.">
|
|
236
|
+
Four
|
|
237
|
+
</RadioList.Option>
|
|
238
|
+
</RadioList>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export default Description;
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## API
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
### RadioList API
|
|
252
|
+
|
|
253
|
+
#### Props
|
|
254
|
+
|
|
255
|
+
| Name | Type | Required | Default | Description |
|
|
256
|
+
|------|------|------|------|------|
|
|
257
|
+
| children | React.ReactNode | no | | `children` should be `RadioList.Option`s. |
|
|
258
|
+
| defaultValue | number \| string \| boolean \| Record<string, unknown> \| symbol | no | | Set this property instead of value to make value uncontrolled. |
|
|
259
|
+
| direction | 'column' \| 'row' | no | | **DEPRECATED**: This prop is deprecated and will be removed in the next major version. Changes the layout of the RadioList. |
|
|
260
|
+
| disabled | boolean | no | false | |
|
|
261
|
+
| elementRef | React.Ref<HTMLDivElement> | no | | A React ref which is set to the DOM element when the component mounts and null when it unmounts. |
|
|
262
|
+
| error | boolean | no | false | Highlight the field as having an error. The buttons and labels will turn red. |
|
|
263
|
+
| name | string | no | | The name is returned with onChange events, which can be used to identify the control when multiple controls share an onChange callback. A randomly generated name is used if one is not provided. |
|
|
264
|
+
| onChange | RadioListChangeHandler | no | | A callback to receive the change events. If value is set, this callback is required. This must set the value prop to retain the change. |
|
|
265
|
+
| value | number \| string \| boolean \| Record<string, unknown> \| symbol | no | | The current selected value. Setting this value makes the property controlled. A callback is required. |
|
|
266
|
+
|
|
267
|
+
#### Types
|
|
268
|
+
|
|
269
|
+
| Name | Type | Description |
|
|
270
|
+
|------|------|------|
|
|
271
|
+
| RadioListChangeHandler | ( event: React.ChangeEvent<HTMLInputElement>, data: { name?: string; value: RadioListValueTypes } ) => void | |
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
### RadioList.Option API
|
|
276
|
+
|
|
277
|
+
#### Props
|
|
278
|
+
|
|
279
|
+
| Name | Type | Required | Default | Description |
|
|
280
|
+
|------|------|------|------|------|
|
|
281
|
+
| children | React.ReactNode | no | | |
|
|
282
|
+
| description | string | no | | Additional information to explain the option. |
|
|
283
|
+
| disabled | boolean | no | false | |
|
|
284
|
+
| error | boolean | no | false | |
|
|
285
|
+
| id | string | no | | |
|
|
286
|
+
| onChange | RadioListChangeHandler | no | | |
|
|
287
|
+
| value | RadioListValueTypes | yes | | The selectable value. If this matches the ControlRadioList value, the item is selected. |
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
## Accessibility
|
|
294
|
+
|
|
295
|
+
## Visual Design
|
|
296
|
+
|
|
297
|
+
- Color contrast ratio **MUST** be:
|
|
298
|
+
- >=4.5:1 for...[SC 1.4.3][1]
|
|
299
|
+
- Label text to page-background (all states)
|
|
300
|
+
- >=3:1 for...[SC 1.4.11][2]
|
|
301
|
+
- Circle to toggle-background-color (selected)
|
|
302
|
+
- Toggle-background-color to page-background (selected)
|
|
303
|
+
- Border to page-background (unselected)
|
|
304
|
+
- Focus State: if the focus ring has a radius of [SC 1.4.11][2]
|
|
305
|
+
- < 3px: >=4.5.1 between button <> focus <> background
|
|
306
|
+
- > 3px: >=3.1 between button <> focus <> background
|
|
307
|
+
|
|
308
|
+
## States
|
|
309
|
+
|
|
310
|
+
- Color contrast rules do not apply to disabled radio buttons
|
|
311
|
+
|
|
312
|
+
## Interaction Model
|
|
313
|
+
|
|
314
|
+
### Focus management
|
|
315
|
+
- For radio groups not in a toolbar (most cases), keyboard navigation **MUST** have [SC 2.1][3]
|
|
316
|
+
- <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move focus into and out of the radio group.
|
|
317
|
+
When focus moves into a radio group :
|
|
318
|
+
|
|
319
|
+
- If a radio button is checked, focus is set on the checked button.
|
|
320
|
+
- If none of the radio buttons are checked, focus is set on the first radio button in the group.
|
|
321
|
+
- <kbd>Space</kbd> to check the focused radio button if it is not already checked.
|
|
322
|
+
- <kbd>Right/Down Arrow</kbd> to move focus to the next radio button in the group, uncheck the
|
|
323
|
+
previously focused button, and check the newly focused button. If focus is on the last button,
|
|
324
|
+
focus moves to the first button.
|
|
325
|
+
- <kbd>Left/Up Arrow</kbd> to move focus to the previous radio button in the group, uncheck the
|
|
326
|
+
previously focused button, and check the newly focused button. If focus is on the first button,
|
|
327
|
+
focus moves to the last button.
|
|
328
|
+
- For Radio Group inside a toolbar, consult [WAI-ARIA][4]
|
|
329
|
+
|
|
330
|
+
## Implementation
|
|
331
|
+
|
|
332
|
+
- Every radio button **MUST** have...[SC 4.1.2][5]
|
|
333
|
+
- label (name)--visible label referenced by `aria-labelledby`, or a label specified with aria-label
|
|
334
|
+
- `"radio"` role
|
|
335
|
+
- `"checked"` or `"unchecked"` (value)
|
|
336
|
+
- `aria-checked` set to either `"true"` (checked) or `"false"` (unchecked)
|
|
337
|
+
- A group of radio buttons **MUST** ...
|
|
338
|
+
- be contained in or owned by an element with the role radiogroup.
|
|
339
|
+
- have a visible label referenced by `aria-labelledby` or has a label specified with aria-label
|
|
340
|
+
- If elements providing additonal information about either the radio group or each radio button are present, those elements **MUST** be labeled using one of the following:
|
|
341
|
+
- the `aria-describedby` property
|
|
342
|
+
- radiogroup element
|
|
343
|
+
- radio element
|
|
344
|
+
|
|
345
|
+
[1]: https://www.w3.org/TR/WCAG21/#contrast-minimum
|
|
346
|
+
[2]: https://www.w3.org/TR/WCAG21/#non-text-contrast
|
|
347
|
+
[3]: https://www.w3.org/TR/WCAG21/#keyboard-accessible
|
|
348
|
+
[4]: https://www.w3.org/TR/wai-aria-practices-1.1/#for-radio-group-contained-in-a-toolbar
|
|
349
|
+
[5]: https://www.w3.org/TR/WCAG21/#name-role-value
|
|
350
|
+
|