playbook_ui 15.7.0.pre.alpha.PLAY2678emojimask13284 → 15.7.0.pre.alpha.PLAY2704multilevelselectsingledisabledoptions13404
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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.rb +9 -7
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/index.js +3 -8
- data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +2 -2
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +7 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_disabled_options.md +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_single_disabled.html.erb +135 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_single_disabled.jsx +147 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_single_disabled.md +1 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.test.jsx +402 -27
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select_options.tsx +1 -0
- data/app/pb_kits/playbook/pb_radio/_radio.scss +8 -0
- data/dist/chunks/{_typeahead-CSCNg6cp.js → _typeahead-DQWz6v7R.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +6 -3
|
@@ -1,39 +1,414 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { render, screen } from '../utilities/test-utils'
|
|
2
|
+
import { render, screen, fireEvent } from '../utilities/test-utils'
|
|
3
3
|
|
|
4
4
|
import { MultiLevelSelect } from 'playbook-ui'
|
|
5
5
|
|
|
6
|
-
const treeData =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
const treeData = [
|
|
7
|
+
{
|
|
8
|
+
label: 'Power Home Remodeling',
|
|
9
|
+
value: 'powerHomeRemodeling',
|
|
10
|
+
id: 'powerhome1',
|
|
11
|
+
expanded: true,
|
|
12
|
+
children: [
|
|
13
|
+
{
|
|
14
|
+
label: 'People',
|
|
15
|
+
value: 'people',
|
|
16
|
+
id: 'people1',
|
|
17
|
+
children: [
|
|
18
|
+
{
|
|
19
|
+
label: 'Talent Acquisition',
|
|
20
|
+
value: 'talentAcquisition',
|
|
21
|
+
id: 'talent1',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'Business Affairs',
|
|
25
|
+
value: 'businessAffairs',
|
|
26
|
+
id: 'business1',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: 'Contact Center',
|
|
32
|
+
value: 'contactCenter',
|
|
33
|
+
id: 'contact1',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const treeDataWithDisabledOptions = [
|
|
40
|
+
{
|
|
41
|
+
label: 'Power Home Remodeling',
|
|
42
|
+
value: 'powerHomeRemodeling',
|
|
43
|
+
id: 'powerhome1',
|
|
44
|
+
expanded: true,
|
|
45
|
+
children: [
|
|
46
|
+
{
|
|
47
|
+
label: 'People',
|
|
48
|
+
value: 'people',
|
|
49
|
+
id: 'people1',
|
|
50
|
+
disabled: true,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Contact Center',
|
|
54
|
+
value: 'contactCenter',
|
|
55
|
+
id: 'contact1',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
const treeDataWithDisabledParent = [
|
|
62
|
+
{
|
|
63
|
+
label: 'Power Home Remodeling',
|
|
64
|
+
value: 'powerHomeRemodeling',
|
|
65
|
+
id: 'powerhome1',
|
|
66
|
+
expanded: true,
|
|
67
|
+
disabled: true,
|
|
68
|
+
children: [
|
|
69
|
+
{
|
|
70
|
+
label: 'People',
|
|
71
|
+
value: 'people',
|
|
72
|
+
id: 'people1',
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
label: 'Contact Center',
|
|
76
|
+
value: 'contactCenter',
|
|
77
|
+
id: 'contact1',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
]
|
|
25
82
|
|
|
26
83
|
const testId = "multiselect-test"
|
|
27
|
-
|
|
28
|
-
|
|
84
|
+
|
|
85
|
+
describe('MultiLevelSelect', () => {
|
|
86
|
+
test('should render custom class', () => {
|
|
87
|
+
render(
|
|
29
88
|
<MultiLevelSelect
|
|
30
89
|
className='custom-class'
|
|
31
|
-
data={{ testid: testId}}
|
|
90
|
+
data={{ testid: testId }}
|
|
91
|
+
treeData={treeData}
|
|
92
|
+
/>
|
|
93
|
+
)
|
|
94
|
+
const kit = screen.getByTestId(testId)
|
|
95
|
+
expect(kit).toHaveClass('custom-class')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('should render with default multi variant', () => {
|
|
99
|
+
render(
|
|
100
|
+
<MultiLevelSelect
|
|
101
|
+
data={{ testid: testId }}
|
|
102
|
+
treeData={treeData}
|
|
103
|
+
/>
|
|
104
|
+
)
|
|
105
|
+
const kit = screen.getByTestId(testId)
|
|
106
|
+
expect(kit).toHaveClass('pb_multi_level_select')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('should render label when provided', () => {
|
|
110
|
+
render(
|
|
111
|
+
<MultiLevelSelect
|
|
112
|
+
data={{ testid: testId }}
|
|
113
|
+
label="Select Location"
|
|
114
|
+
treeData={treeData}
|
|
115
|
+
/>
|
|
116
|
+
)
|
|
117
|
+
const kit = screen.getByTestId(testId)
|
|
118
|
+
expect(kit).toHaveTextContent('Select Location')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('should render error message when provided', () => {
|
|
122
|
+
render(
|
|
123
|
+
<MultiLevelSelect
|
|
124
|
+
data={{ testid: testId }}
|
|
125
|
+
error="Please select an option"
|
|
126
|
+
treeData={treeData}
|
|
127
|
+
/>
|
|
128
|
+
)
|
|
129
|
+
const kit = screen.getByTestId(testId)
|
|
130
|
+
expect(kit).toHaveTextContent('Please select an option')
|
|
131
|
+
expect(kit).toHaveClass('error')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('should disable input when disabled prop is true', () => {
|
|
135
|
+
render(
|
|
136
|
+
<MultiLevelSelect
|
|
137
|
+
data={{ testid: testId }}
|
|
138
|
+
disabled
|
|
32
139
|
treeData={treeData}
|
|
33
|
-
/>
|
|
34
|
-
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
142
|
+
const kit = screen.getByTestId(testId)
|
|
143
|
+
const input = kit.querySelector('#multiselect_input')
|
|
144
|
+
expect(input).toBeDisabled()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
35
147
|
|
|
36
|
-
|
|
37
|
-
|
|
148
|
+
describe('MultiLevelSelect multi variant', () => {
|
|
149
|
+
test('should render checkboxes for multi variant', () => {
|
|
150
|
+
render(
|
|
151
|
+
<MultiLevelSelect
|
|
152
|
+
data={{ testid: testId }}
|
|
153
|
+
treeData={treeData}
|
|
154
|
+
variant="multi"
|
|
155
|
+
/>
|
|
156
|
+
)
|
|
157
|
+
const kit = screen.getByTestId(testId)
|
|
158
|
+
const input = kit.querySelector('#multiselect_input')
|
|
159
|
+
fireEvent.click(input)
|
|
160
|
+
|
|
161
|
+
const checkboxes = kit.querySelectorAll('input[type="checkbox"]')
|
|
162
|
+
expect(checkboxes.length).toBeGreaterThan(0)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('should call onSelect when checkbox is clicked', () => {
|
|
166
|
+
const mockOnSelect = jest.fn()
|
|
167
|
+
render(
|
|
168
|
+
<MultiLevelSelect
|
|
169
|
+
data={{ testid: testId }}
|
|
170
|
+
onSelect={mockOnSelect}
|
|
171
|
+
treeData={treeData}
|
|
172
|
+
variant="multi"
|
|
173
|
+
/>
|
|
174
|
+
)
|
|
175
|
+
const kit = screen.getByTestId(testId)
|
|
176
|
+
const input = kit.querySelector('#multiselect_input')
|
|
177
|
+
fireEvent.click(input)
|
|
178
|
+
|
|
179
|
+
const checkbox = kit.querySelector('input[type="checkbox"]')
|
|
180
|
+
fireEvent.click(checkbox)
|
|
181
|
+
|
|
182
|
+
expect(mockOnSelect).toHaveBeenCalled()
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('should render disabled checkbox inputs for disabled options', () => {
|
|
186
|
+
render(
|
|
187
|
+
<MultiLevelSelect
|
|
188
|
+
data={{ testid: testId }}
|
|
189
|
+
id="multi-disabled-test"
|
|
190
|
+
treeData={treeDataWithDisabledOptions}
|
|
191
|
+
variant="multi"
|
|
192
|
+
/>
|
|
193
|
+
)
|
|
194
|
+
const kit = screen.getByTestId(testId)
|
|
195
|
+
const input = kit.querySelector('#multiselect_input')
|
|
196
|
+
fireEvent.click(input)
|
|
197
|
+
|
|
198
|
+
const disabledCheckbox = kit.querySelector('input[type="checkbox"][disabled]')
|
|
199
|
+
expect(disabledCheckbox).toBeInTheDocument()
|
|
200
|
+
})
|
|
38
201
|
})
|
|
39
202
|
|
|
203
|
+
describe('MultiLevelSelect single variant', () => {
|
|
204
|
+
test('should render radio buttons for single variant', () => {
|
|
205
|
+
render(
|
|
206
|
+
<MultiLevelSelect
|
|
207
|
+
data={{ testid: testId }}
|
|
208
|
+
treeData={treeData}
|
|
209
|
+
variant="single"
|
|
210
|
+
/>
|
|
211
|
+
)
|
|
212
|
+
const kit = screen.getByTestId(testId)
|
|
213
|
+
const input = kit.querySelector('#multiselect_input')
|
|
214
|
+
fireEvent.click(input)
|
|
215
|
+
|
|
216
|
+
const radios = kit.querySelectorAll('input[type="radio"]')
|
|
217
|
+
expect(radios.length).toBeGreaterThan(0)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('should render disabled radio inputs for disabled options', () => {
|
|
221
|
+
render(
|
|
222
|
+
<MultiLevelSelect
|
|
223
|
+
data={{ testid: testId }}
|
|
224
|
+
id="single-disabled-test"
|
|
225
|
+
treeData={treeDataWithDisabledOptions}
|
|
226
|
+
variant="single"
|
|
227
|
+
/>
|
|
228
|
+
)
|
|
229
|
+
const kit = screen.getByTestId(testId)
|
|
230
|
+
const input = kit.querySelector('#multiselect_input')
|
|
231
|
+
fireEvent.click(input)
|
|
232
|
+
|
|
233
|
+
const disabledRadio = kit.querySelector('input[type="radio"][disabled]')
|
|
234
|
+
expect(disabledRadio).toBeInTheDocument()
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
test('disabled options cannot be selected', () => {
|
|
238
|
+
const mockOnSelect = jest.fn()
|
|
239
|
+
render(
|
|
240
|
+
<MultiLevelSelect
|
|
241
|
+
data={{ testid: testId }}
|
|
242
|
+
id="single-disabled-click-test"
|
|
243
|
+
onSelect={mockOnSelect}
|
|
244
|
+
treeData={treeDataWithDisabledOptions}
|
|
245
|
+
variant="single"
|
|
246
|
+
/>
|
|
247
|
+
)
|
|
248
|
+
const kit = screen.getByTestId(testId)
|
|
249
|
+
const input = kit.querySelector('#multiselect_input')
|
|
250
|
+
fireEvent.click(input)
|
|
251
|
+
|
|
252
|
+
const disabledRadio = kit.querySelector('input[type="radio"][disabled]')
|
|
253
|
+
fireEvent.click(disabledRadio)
|
|
254
|
+
|
|
255
|
+
expect(mockOnSelect).not.toHaveBeenCalled()
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
test('enabled options can be selected', () => {
|
|
259
|
+
const mockOnSelect = jest.fn()
|
|
260
|
+
render(
|
|
261
|
+
<MultiLevelSelect
|
|
262
|
+
data={{ testid: testId }}
|
|
263
|
+
id="single-enabled-click-test"
|
|
264
|
+
onSelect={mockOnSelect}
|
|
265
|
+
treeData={treeDataWithDisabledOptions}
|
|
266
|
+
variant="single"
|
|
267
|
+
/>
|
|
268
|
+
)
|
|
269
|
+
const kit = screen.getByTestId(testId)
|
|
270
|
+
const input = kit.querySelector('#multiselect_input')
|
|
271
|
+
fireEvent.click(input)
|
|
272
|
+
|
|
273
|
+
const enabledRadio = kit.querySelector('input[type="radio"]:not([disabled])')
|
|
274
|
+
fireEvent.click(enabledRadio)
|
|
275
|
+
|
|
276
|
+
expect(mockOnSelect).toHaveBeenCalled()
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('should close dropdown after selection', () => {
|
|
280
|
+
render(
|
|
281
|
+
<MultiLevelSelect
|
|
282
|
+
data={{ testid: testId }}
|
|
283
|
+
treeData={treeDataWithDisabledOptions}
|
|
284
|
+
variant="single"
|
|
285
|
+
/>
|
|
286
|
+
)
|
|
287
|
+
const kit = screen.getByTestId(testId)
|
|
288
|
+
const input = kit.querySelector('#multiselect_input')
|
|
289
|
+
fireEvent.click(input)
|
|
290
|
+
|
|
291
|
+
const enabledRadio = kit.querySelector('input[type="radio"]:not([disabled])')
|
|
292
|
+
fireEvent.click(enabledRadio)
|
|
293
|
+
|
|
294
|
+
const dropdownClosed = kit.querySelector('.dropdown_menu.close')
|
|
295
|
+
expect(dropdownClosed).toBeInTheDocument()
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
test('should update input value after selection', () => {
|
|
299
|
+
render(
|
|
300
|
+
<MultiLevelSelect
|
|
301
|
+
data={{ testid: testId }}
|
|
302
|
+
treeData={treeDataWithDisabledOptions}
|
|
303
|
+
variant="single"
|
|
304
|
+
/>
|
|
305
|
+
)
|
|
306
|
+
const kit = screen.getByTestId(testId)
|
|
307
|
+
const input = kit.querySelector('#multiselect_input')
|
|
308
|
+
fireEvent.click(input)
|
|
309
|
+
|
|
310
|
+
const enabledRadio = kit.querySelector('input[type="radio"]:not([disabled])')
|
|
311
|
+
fireEvent.click(enabledRadio)
|
|
312
|
+
|
|
313
|
+
expect(input.value).toBe('Power Home Remodeling')
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
describe('MultiLevelSelect disabled parent behavior', () => {
|
|
318
|
+
test('children of disabled parent should also be disabled in single variant', () => {
|
|
319
|
+
render(
|
|
320
|
+
<MultiLevelSelect
|
|
321
|
+
data={{ testid: testId }}
|
|
322
|
+
treeData={treeDataWithDisabledParent}
|
|
323
|
+
variant="single"
|
|
324
|
+
/>
|
|
325
|
+
)
|
|
326
|
+
const kit = screen.getByTestId(testId)
|
|
327
|
+
const input = kit.querySelector('#multiselect_input')
|
|
328
|
+
fireEvent.click(input)
|
|
329
|
+
|
|
330
|
+
const radios = kit.querySelectorAll('input[type="radio"]')
|
|
331
|
+
radios.forEach(radio => {
|
|
332
|
+
expect(radio).toBeDisabled()
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
test('children of disabled parent should also be disabled in multi variant', () => {
|
|
337
|
+
render(
|
|
338
|
+
<MultiLevelSelect
|
|
339
|
+
data={{ testid: testId }}
|
|
340
|
+
treeData={treeDataWithDisabledParent}
|
|
341
|
+
variant="multi"
|
|
342
|
+
/>
|
|
343
|
+
)
|
|
344
|
+
const kit = screen.getByTestId(testId)
|
|
345
|
+
const input = kit.querySelector('#multiselect_input')
|
|
346
|
+
fireEvent.click(input)
|
|
347
|
+
|
|
348
|
+
const checkboxes = kit.querySelectorAll('input[type="checkbox"]')
|
|
349
|
+
checkboxes.forEach(checkbox => {
|
|
350
|
+
expect(checkbox).toBeDisabled()
|
|
351
|
+
})
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
describe('MultiLevelSelect onChange callback', () => {
|
|
356
|
+
test('should call onChange when selection changes in multi variant', () => {
|
|
357
|
+
const mockOnChange = jest.fn()
|
|
358
|
+
render(
|
|
359
|
+
<MultiLevelSelect
|
|
360
|
+
data={{ testid: testId }}
|
|
361
|
+
onChange={mockOnChange}
|
|
362
|
+
treeData={treeData}
|
|
363
|
+
variant="multi"
|
|
364
|
+
/>
|
|
365
|
+
)
|
|
366
|
+
const kit = screen.getByTestId(testId)
|
|
367
|
+
const input = kit.querySelector('#multiselect_input')
|
|
368
|
+
fireEvent.click(input)
|
|
369
|
+
|
|
370
|
+
const checkbox = kit.querySelector('input[type="checkbox"]')
|
|
371
|
+
fireEvent.click(checkbox)
|
|
372
|
+
|
|
373
|
+
expect(mockOnChange).toHaveBeenCalled()
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
test('should call onChange when selection changes in single variant', () => {
|
|
377
|
+
const mockOnChange = jest.fn()
|
|
378
|
+
render(
|
|
379
|
+
<MultiLevelSelect
|
|
380
|
+
data={{ testid: testId }}
|
|
381
|
+
onChange={mockOnChange}
|
|
382
|
+
treeData={treeDataWithDisabledOptions}
|
|
383
|
+
variant="single"
|
|
384
|
+
/>
|
|
385
|
+
)
|
|
386
|
+
const kit = screen.getByTestId(testId)
|
|
387
|
+
const input = kit.querySelector('#multiselect_input')
|
|
388
|
+
fireEvent.click(input)
|
|
389
|
+
|
|
390
|
+
const enabledRadio = kit.querySelector('input[type="radio"]:not([disabled])')
|
|
391
|
+
fireEvent.click(enabledRadio)
|
|
392
|
+
|
|
393
|
+
expect(mockOnChange).toHaveBeenCalled()
|
|
394
|
+
})
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
describe('MultiLevelSelect inputName prop', () => {
|
|
398
|
+
test('should use inputName for radio button name attribute', () => {
|
|
399
|
+
render(
|
|
400
|
+
<MultiLevelSelect
|
|
401
|
+
data={{ testid: testId }}
|
|
402
|
+
inputName="location_select"
|
|
403
|
+
treeData={treeData}
|
|
404
|
+
variant="single"
|
|
405
|
+
/>
|
|
406
|
+
)
|
|
407
|
+
const kit = screen.getByTestId(testId)
|
|
408
|
+
const input = kit.querySelector('#multiselect_input')
|
|
409
|
+
fireEvent.click(input)
|
|
410
|
+
|
|
411
|
+
const radio = kit.querySelector('input[type="radio"]')
|
|
412
|
+
expect(radio).toHaveAttribute('name', 'location_select')
|
|
413
|
+
})
|
|
414
|
+
})
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
display: inline-flex;
|
|
14
14
|
cursor: pointer;
|
|
15
15
|
|
|
16
|
+
&:has(input:disabled) {
|
|
17
|
+
cursor: not-allowed;
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
.pb_radio_button {
|
|
17
21
|
width: 22px;
|
|
18
22
|
min-width: 22px;
|
|
@@ -84,6 +88,10 @@
|
|
|
84
88
|
.pb_radio_kit.dark.error.vertical,
|
|
85
89
|
.pb_radio_kit_vertical.dark,
|
|
86
90
|
.pb_radio_kit_vertical.dark.error {
|
|
91
|
+
&:has(input:disabled) {
|
|
92
|
+
cursor: not-allowed;
|
|
93
|
+
}
|
|
94
|
+
|
|
87
95
|
.pb_radio_button {
|
|
88
96
|
border-color: $border_dark;
|
|
89
97
|
}
|