playbook_ui 18.3.0.pre.rc.1 → 18.3.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.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +1 -1
- data/app/pb_kits/playbook/pb_avatar/_avatar.tsx +3 -1
- data/app/pb_kits/playbook/pb_avatar/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_contact/_contact.tsx +4 -1
- data/app/pb_kits/playbook/pb_contact/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date/_date.tsx +3 -1
- data/app/pb_kits/playbook/pb_date/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_range_inline/_date_range_inline.tsx +3 -1
- data/app/pb_kits/playbook/pb_date_range_inline/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_range_stacked/_date_range_stacked.tsx +3 -1
- data/app/pb_kits/playbook/pb_date_range_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_stacked/_date_stacked.tsx +4 -1
- data/app/pb_kits/playbook/pb_date_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_time/_date_time.tsx +3 -1
- data/app/pb_kits/playbook/pb_date_time/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_time_stacked/_date_time_stacked.tsx +2 -1
- data/app/pb_kits/playbook/pb_date_time_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_year_stacked/_date_year_stacked.tsx +3 -1
- data/app/pb_kits/playbook/pb_date_year_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_draggable/utilities/touchDrag.ts +10 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +112 -0
- data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +11 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_draggable_pills.html.erb +51 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_draggable_pills.jsx +62 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_draggable_pills_rails.md +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_draggable_pills_react.md +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_playground.json +16 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/_playground.overrides.json +7 -1
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +10 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +194 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown_index.test.js +254 -0
- data/app/pb_kits/playbook/pb_dropdown/index.js +166 -7
- data/app/pb_kits/playbook/pb_dropdown/kit.schema.json +24 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/MultiSelectTriggerDisplay.tsx +336 -31
- data/app/pb_kits/playbook/pb_dropdown/utilities/pillReorder.js +281 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/usePillDropIndicator.ts +144 -0
- data/app/pb_kits/playbook/pb_form/pb_form_validation.js +1 -0
- data/app/pb_kits/playbook/pb_form_group/_form_group.scss +1 -4
- data/app/pb_kits/playbook/pb_image/_image.tsx +3 -1
- data/app/pb_kits/playbook/pb_image/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_list/_list_item.tsx +6 -3
- data/app/pb_kits/playbook/pb_map/docs/_map_default.md +22 -3
- data/app/pb_kits/playbook/pb_person/_person.tsx +3 -1
- data/app/pb_kits/playbook/pb_person/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_playground.json +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_playground.overrides.json +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_rails_default.md +3 -4
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_rails_extensions.md +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_rails_markdown_support.md +1 -1
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.html.erb +0 -6
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor_rails.js +26 -21
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor_rails.test.js +85 -1
- data/app/pb_kits/playbook/pb_selectable_card_icon/_selectable_card_icon.scss +0 -9
- data/app/pb_kits/playbook/pb_selectable_card_icon/docs/_selectable_card_icon_custom.jsx +1 -1
- data/app/pb_kits/playbook/pb_selectable_icon/_selectable_icon.scss +0 -7
- data/app/pb_kits/playbook/pb_source/source.rb +1 -1
- data/app/pb_kits/playbook/pb_time_range_inline/_time_range_inline.tsx +3 -1
- data/app/pb_kits/playbook/pb_time_range_inline/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_time_stacked/_time_stacked.tsx +3 -1
- data/app/pb_kits/playbook/pb_time_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_timestamp/_timestamp.tsx +3 -1
- data/app/pb_kits/playbook/pb_timestamp/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +127 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +15 -10
- data/app/pb_kits/playbook/pb_user/_user.tsx +3 -1
- data/app/pb_kits/playbook/pb_user/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_user_badge/_user_badge.tsx +3 -1
- data/app/pb_kits/playbook/pb_user_badge/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_weekday_stacked/_weekday_stacked.tsx +3 -1
- data/app/pb_kits/playbook/pb_weekday_stacked/kit.schema.json +1 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/onClick.test.js +186 -0
- data/dist/ai/all-schemas.json +56 -2
- data/dist/ai/external-dependencies.json +1 -1
- data/dist/ai/forms.json +2 -2
- data/dist/ai/index.json +3 -3
- data/dist/ai/kits/avatar.schema.json +1 -0
- data/dist/ai/kits/contact.schema.json +1 -0
- data/dist/ai/kits/date.schema.json +1 -0
- data/dist/ai/kits/date_range_inline.schema.json +1 -0
- data/dist/ai/kits/date_range_stacked.schema.json +1 -0
- data/dist/ai/kits/date_stacked.schema.json +1 -0
- data/dist/ai/kits/date_time.schema.json +1 -0
- data/dist/ai/kits/date_time_stacked.schema.json +1 -0
- data/dist/ai/kits/date_year_stacked.schema.json +1 -0
- data/dist/ai/kits/dropdown.schema.json +38 -1
- data/dist/ai/kits/image.schema.json +1 -0
- data/dist/ai/kits/person.schema.json +1 -0
- data/dist/ai/kits/rich_text_editor.schema.json +1 -1
- data/dist/ai/kits/time_range_inline.schema.json +1 -0
- data/dist/ai/kits/time_stacked.schema.json +1 -0
- data/dist/ai/kits/timestamp.schema.json +1 -0
- data/dist/ai/kits/user.schema.json +1 -0
- data/dist/ai/kits/user_badge.schema.json +1 -0
- data/dist/ai/kits/weekday_stacked.schema.json +1 -0
- data/dist/ai/playgrounds/dropdown.json +1 -1
- data/dist/ai/playgrounds/rich_text_editor.json +1 -1
- data/dist/chunks/{_pagination-D0hcdUl3.js → _pagination-CARbC_IN.js} +1 -1
- data/dist/chunks/{_tooltip-DfZEKsnv.js → _tooltip-UkcgcThO.js} +1 -1
- data/dist/chunks/{_typeahead-CmJ8Ggzz.js → _typeahead-NYVJDWmJ.js} +1 -1
- data/dist/chunks/index-4jrZjexD.js +1 -0
- data/dist/chunks/index-BAy61y8S.js +1 -0
- data/dist/chunks/index-Cb_SDipk.js +1 -0
- data/dist/chunks/index-D3RdsDp7.js +1 -0
- data/dist/chunks/index-D8PZIesy.js +1 -0
- data/dist/chunks/index-DIoc-aua.js +1 -0
- data/dist/chunks/index-qex65UMn.js +1 -0
- data/dist/chunks/vendor.js +2 -2
- data/dist/menu.yml +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 +37 -13
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
"closeOnClick": "any",
|
|
14
14
|
"constrainHeight": false,
|
|
15
15
|
"disabled": false,
|
|
16
|
+
"enablePillReorder": false,
|
|
17
|
+
"externalDragHandle": false,
|
|
16
18
|
"multiSelect": false,
|
|
17
19
|
"separators": true,
|
|
20
|
+
"showPillIndex": false,
|
|
18
21
|
"variant": "default",
|
|
19
22
|
"rangeEndsToday": false,
|
|
20
23
|
"controlsStartId": "",
|
|
@@ -148,6 +151,9 @@
|
|
|
148
151
|
"props": [
|
|
149
152
|
"separators",
|
|
150
153
|
"formPillProps",
|
|
154
|
+
"enablePillReorder",
|
|
155
|
+
"externalDragHandle",
|
|
156
|
+
"showPillIndex",
|
|
151
157
|
"activeStyle",
|
|
152
158
|
"dark",
|
|
153
159
|
"disabled"
|
|
@@ -355,6 +361,15 @@
|
|
|
355
361
|
"formPillProps": {
|
|
356
362
|
"requires": "multiSelect"
|
|
357
363
|
},
|
|
364
|
+
"enablePillReorder": {
|
|
365
|
+
"requires": "multiSelect"
|
|
366
|
+
},
|
|
367
|
+
"externalDragHandle": {
|
|
368
|
+
"requires": "enablePillReorder"
|
|
369
|
+
},
|
|
370
|
+
"showPillIndex": {
|
|
371
|
+
"requires": "multiSelect"
|
|
372
|
+
},
|
|
358
373
|
"rangeEndsToday": {
|
|
359
374
|
"requires": {
|
|
360
375
|
"variant": "quickpick"
|
|
@@ -405,7 +420,7 @@
|
|
|
405
420
|
"when": {
|
|
406
421
|
"multiSelect": true
|
|
407
422
|
},
|
|
408
|
-
"message": "Multi-select returns arrays of selected options. Use formPillProps to adjust the selected-pill appearance and clearable to let users reset the selection.",
|
|
423
|
+
"message": "Multi-select returns arrays of selected options. Use formPillProps to adjust the selected-pill appearance and clearable to let users reset the selection. Opt into enablePillReorder to drag pills into a new priority order.",
|
|
409
424
|
"type": "info"
|
|
410
425
|
},
|
|
411
426
|
"autocomplete_info": {
|
|
@@ -219,6 +219,9 @@
|
|
|
219
219
|
"props": [
|
|
220
220
|
"separators",
|
|
221
221
|
"formPillProps",
|
|
222
|
+
"enablePillReorder",
|
|
223
|
+
"externalDragHandle",
|
|
224
|
+
"showPillIndex",
|
|
222
225
|
"activeStyle",
|
|
223
226
|
"dark",
|
|
224
227
|
"disabled"
|
|
@@ -386,6 +389,9 @@
|
|
|
386
389
|
"searchbar": { "structureMode": "async" },
|
|
387
390
|
"requiredIndicator": { "requires": "label" },
|
|
388
391
|
"formPillProps": { "requires": "multiSelect" },
|
|
392
|
+
"enablePillReorder": { "requires": "multiSelect" },
|
|
393
|
+
"externalDragHandle": { "requires": "enablePillReorder" },
|
|
394
|
+
"showPillIndex": { "requires": "multiSelect" },
|
|
389
395
|
"rangeEndsToday": { "requires": { "variant": "quickpick" } },
|
|
390
396
|
"controlsStartId": { "requires": { "variant": "quickpick" } },
|
|
391
397
|
"controlsEndId": { "requires": { "variant": "quickpick" } },
|
|
@@ -416,7 +422,7 @@
|
|
|
416
422
|
},
|
|
417
423
|
"multi_options": {
|
|
418
424
|
"when": { "multiSelect": true },
|
|
419
|
-
"message": "Multi-select returns arrays of selected options. Use formPillProps to adjust the selected-pill appearance and clearable to let users reset the selection.",
|
|
425
|
+
"message": "Multi-select returns arrays of selected options. Use formPillProps to adjust the selected-pill appearance and clearable to let users reset the selection. Opt into enablePillReorder to drag pills into a new priority order.",
|
|
420
426
|
"type": "info"
|
|
421
427
|
},
|
|
422
428
|
"autocomplete_info": {
|
|
@@ -48,6 +48,7 @@ examples:
|
|
|
48
48
|
- dropdown_async_multi_select_rails: Async Multi Select
|
|
49
49
|
- dropdown_async_custom_content: Async Search with Custom Content
|
|
50
50
|
- dropdown_option_creation: Allow Option Creation
|
|
51
|
+
- dropdown_draggable_pills: Draggable Pills
|
|
51
52
|
|
|
52
53
|
react:
|
|
53
54
|
- dropdown_default: Default
|
|
@@ -102,5 +103,6 @@ examples:
|
|
|
102
103
|
- dropdown_async_initial_options: Async Initial Results and Caching
|
|
103
104
|
- dropdown_external_search: External Search
|
|
104
105
|
- dropdown_option_creation: Allow Option Creation
|
|
106
|
+
- dropdown_draggable_pills: Draggable Pills
|
|
105
107
|
- dropdown_form: Enable Form Support
|
|
106
108
|
|
|
@@ -51,3 +51,4 @@ export { default as DropdownForm } from "./_dropdown_form.jsx"
|
|
|
51
51
|
export { default as DropdownOptionCreation } from "./_dropdown_option_creation.jsx"
|
|
52
52
|
export { default as DropdownQuickpickEnableTime } from './_dropdown_quickpick_enable_time.jsx'
|
|
53
53
|
export { default as DropdownWithHighlight } from './_dropdown_with_highlight.jsx'
|
|
54
|
+
export { default as DropdownDraggablePills } from './_dropdown_draggable_pills.jsx'
|
|
@@ -77,6 +77,12 @@ module Playbook
|
|
|
77
77
|
default: true
|
|
78
78
|
prop :options_event_type, type: Playbook::Props::String,
|
|
79
79
|
default: ""
|
|
80
|
+
prop :enable_pill_reorder, type: Playbook::Props::Boolean,
|
|
81
|
+
default: false
|
|
82
|
+
prop :external_drag_handle, type: Playbook::Props::Boolean,
|
|
83
|
+
default: false
|
|
84
|
+
prop :show_pill_index, type: Playbook::Props::Boolean,
|
|
85
|
+
default: false
|
|
80
86
|
|
|
81
87
|
def data
|
|
82
88
|
Hash(prop(:data)).merge(
|
|
@@ -102,7 +108,10 @@ module Playbook
|
|
|
102
108
|
pb_dropdown_options_by_context: options_by_context.present? ? options_by_context.to_json : nil,
|
|
103
109
|
pb_dropdown_context_selector: context_selector.presence,
|
|
104
110
|
pb_dropdown_clear_on_context_change: clear_on_context_change,
|
|
105
|
-
options_event_type: options_event_type.presence
|
|
111
|
+
options_event_type: options_event_type.presence,
|
|
112
|
+
pb_dropdown_enable_pill_reorder: multi_select && enable_pill_reorder ? true : nil,
|
|
113
|
+
pb_dropdown_external_drag_handle: multi_select && enable_pill_reorder && external_drag_handle ? true : nil,
|
|
114
|
+
pb_dropdown_show_pill_index: multi_select && show_pill_index ? true : nil
|
|
106
115
|
).compact
|
|
107
116
|
end
|
|
108
117
|
|
|
@@ -2582,3 +2582,197 @@ describe('autocomplete selection replacement', () => {
|
|
|
2582
2582
|
expect(onSelect).not.toHaveBeenCalled();
|
|
2583
2583
|
});
|
|
2584
2584
|
});
|
|
2585
|
+
|
|
2586
|
+
describe("enablePillReorder", () => {
|
|
2587
|
+
test("false does not render drag handles or draggable items", () => {
|
|
2588
|
+
render(
|
|
2589
|
+
<Dropdown
|
|
2590
|
+
data={{ testid: testId }}
|
|
2591
|
+
defaultValue={[options[0], options[1]]}
|
|
2592
|
+
enablePillReorder={false}
|
|
2593
|
+
multiSelect
|
|
2594
|
+
options={options}
|
|
2595
|
+
/>
|
|
2596
|
+
)
|
|
2597
|
+
|
|
2598
|
+
const kit = screen.getByTestId(testId)
|
|
2599
|
+
expect(kit.querySelector(".pb_dropdown_external_drag_handle")).not.toBeInTheDocument()
|
|
2600
|
+
expect(kit.querySelector(".pb_draggable_item")).not.toBeInTheDocument()
|
|
2601
|
+
})
|
|
2602
|
+
|
|
2603
|
+
test("renders in-pill grip icons and numbered pills", () => {
|
|
2604
|
+
render(
|
|
2605
|
+
<Dropdown
|
|
2606
|
+
data={{ testid: testId }}
|
|
2607
|
+
defaultValue={[options[0], options[1], options[2]]}
|
|
2608
|
+
enablePillReorder
|
|
2609
|
+
multiSelect
|
|
2610
|
+
options={options}
|
|
2611
|
+
showPillIndex
|
|
2612
|
+
/>
|
|
2613
|
+
)
|
|
2614
|
+
|
|
2615
|
+
const kit = screen.getByTestId(testId)
|
|
2616
|
+
const pills = kit.querySelectorAll(".pb_form_pill_kit_icon.pb_form_pill_primary")
|
|
2617
|
+
|
|
2618
|
+
expect(kit.querySelector(".pb_dropdown_external_drag_handle")).not.toBeInTheDocument()
|
|
2619
|
+
expect(kit.querySelectorAll(".pb_form_pill_kit_icon .pb_form_pill_icon").length).toBe(3)
|
|
2620
|
+
expect(pills.length).toBe(3)
|
|
2621
|
+
expect(pills[0]).toHaveTextContent("1. United States")
|
|
2622
|
+
expect(pills[1]).toHaveTextContent("2. Canada")
|
|
2623
|
+
expect(pills[2]).toHaveTextContent("3. Pakistan")
|
|
2624
|
+
})
|
|
2625
|
+
|
|
2626
|
+
test("keyboard reorder moves pill position", () => {
|
|
2627
|
+
const handleChange = jest.fn()
|
|
2628
|
+
|
|
2629
|
+
render(
|
|
2630
|
+
<Dropdown
|
|
2631
|
+
data={{ testid: testId }}
|
|
2632
|
+
enablePillReorder
|
|
2633
|
+
multiSelect
|
|
2634
|
+
onChange={handleChange}
|
|
2635
|
+
options={options}
|
|
2636
|
+
showPillIndex
|
|
2637
|
+
value={[options[0], options[1], options[2]]}
|
|
2638
|
+
/>
|
|
2639
|
+
)
|
|
2640
|
+
|
|
2641
|
+
const kit = screen.getByTestId(testId)
|
|
2642
|
+
const pills = kit.querySelectorAll(".pb_form_pill_kit_icon.pb_form_pill_primary")
|
|
2643
|
+
|
|
2644
|
+
pills[1].focus()
|
|
2645
|
+
fireEvent.keyDown(pills[1], { key: "ArrowLeft" })
|
|
2646
|
+
|
|
2647
|
+
expect(handleChange).toHaveBeenCalled()
|
|
2648
|
+
const reorderedValue = handleChange.mock.calls[0][0].target.value
|
|
2649
|
+
expect(reorderedValue[0].label).toBe("Canada")
|
|
2650
|
+
expect(reorderedValue[1].label).toBe("United States")
|
|
2651
|
+
})
|
|
2652
|
+
|
|
2653
|
+
test("remove still works when enablePillReorder is true", () => {
|
|
2654
|
+
const handleChange = jest.fn()
|
|
2655
|
+
|
|
2656
|
+
render(
|
|
2657
|
+
<Dropdown
|
|
2658
|
+
data={{ testid: testId }}
|
|
2659
|
+
enablePillReorder
|
|
2660
|
+
multiSelect
|
|
2661
|
+
onChange={handleChange}
|
|
2662
|
+
options={options}
|
|
2663
|
+
value={[options[0], options[1]]}
|
|
2664
|
+
/>
|
|
2665
|
+
)
|
|
2666
|
+
|
|
2667
|
+
const kit = screen.getByTestId(testId)
|
|
2668
|
+
const removeButton = kit.querySelector(".pb_form_pill_close")
|
|
2669
|
+
|
|
2670
|
+
fireEvent.click(removeButton)
|
|
2671
|
+
|
|
2672
|
+
expect(handleChange).toHaveBeenCalled()
|
|
2673
|
+
expect(handleChange.mock.calls[0][0].target.value.length).toBe(1)
|
|
2674
|
+
})
|
|
2675
|
+
|
|
2676
|
+
test("externalDragHandle true renders external grip handles", () => {
|
|
2677
|
+
render(
|
|
2678
|
+
<Dropdown
|
|
2679
|
+
data={{ testid: testId }}
|
|
2680
|
+
enablePillReorder
|
|
2681
|
+
externalDragHandle
|
|
2682
|
+
multiSelect
|
|
2683
|
+
options={options}
|
|
2684
|
+
value={[options[0], options[1]]}
|
|
2685
|
+
/>
|
|
2686
|
+
)
|
|
2687
|
+
|
|
2688
|
+
const kit = screen.getByTestId(testId)
|
|
2689
|
+
expect(kit.querySelectorAll(".pb_dropdown_external_drag_handle").length).toBe(2)
|
|
2690
|
+
expect(kit.querySelectorAll(".pb_form_pill_kit_icon .pb_form_pill_icon").length).toBe(0)
|
|
2691
|
+
})
|
|
2692
|
+
|
|
2693
|
+
test("dragging a pill shows a ghost and drop line, then commits on drop", () => {
|
|
2694
|
+
const handleChange = jest.fn()
|
|
2695
|
+
const originalElementFromPoint = document.elementFromPoint
|
|
2696
|
+
|
|
2697
|
+
render(
|
|
2698
|
+
<Dropdown
|
|
2699
|
+
data={{ testid: testId }}
|
|
2700
|
+
enablePillReorder
|
|
2701
|
+
multiSelect
|
|
2702
|
+
onChange={handleChange}
|
|
2703
|
+
options={options}
|
|
2704
|
+
value={[options[0], options[1], options[2]]}
|
|
2705
|
+
/>
|
|
2706
|
+
)
|
|
2707
|
+
|
|
2708
|
+
const kit = screen.getByTestId(testId)
|
|
2709
|
+
const draggableItems = kit.querySelectorAll(".pb_draggable_item")
|
|
2710
|
+
draggableItems.forEach((item, index) => {
|
|
2711
|
+
item.getBoundingClientRect = () => ({
|
|
2712
|
+
left: index * 100,
|
|
2713
|
+
right: index * 100 + 100,
|
|
2714
|
+
width: 100,
|
|
2715
|
+
top: 0,
|
|
2716
|
+
bottom: 30,
|
|
2717
|
+
height: 30,
|
|
2718
|
+
})
|
|
2719
|
+
})
|
|
2720
|
+
document.elementFromPoint = (x) => (
|
|
2721
|
+
draggableItems[Math.min(Math.floor(x / 100), draggableItems.length - 1)] || null
|
|
2722
|
+
)
|
|
2723
|
+
|
|
2724
|
+
fireEvent.mouseDown(draggableItems[0], { button: 0, clientX: 10, clientY: 10 })
|
|
2725
|
+
fireEvent.mouseMove(document, { clientX: 30, clientY: 10 })
|
|
2726
|
+
fireEvent.mouseMove(document, { clientX: 280, clientY: 10 })
|
|
2727
|
+
|
|
2728
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).toBeInTheDocument()
|
|
2729
|
+
expect(draggableItems[2]).toHaveClass("pb_dropdown_drop_after")
|
|
2730
|
+
|
|
2731
|
+
fireEvent.mouseUp(document, { clientX: 280, clientY: 10 })
|
|
2732
|
+
|
|
2733
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).not.toBeInTheDocument()
|
|
2734
|
+
expect(handleChange).toHaveBeenCalled()
|
|
2735
|
+
expect(handleChange.mock.calls[0][0].target.value.map((item) => item.label)).toEqual([
|
|
2736
|
+
"Canada",
|
|
2737
|
+
"Pakistan",
|
|
2738
|
+
"United States",
|
|
2739
|
+
])
|
|
2740
|
+
|
|
2741
|
+
document.elementFromPoint = originalElementFromPoint
|
|
2742
|
+
})
|
|
2743
|
+
|
|
2744
|
+
test("single-select is unaffected by enablePillReorder", () => {
|
|
2745
|
+
render(
|
|
2746
|
+
<Dropdown
|
|
2747
|
+
data={{ testid: testId }}
|
|
2748
|
+
defaultValue={options[0]}
|
|
2749
|
+
enablePillReorder
|
|
2750
|
+
options={options}
|
|
2751
|
+
showPillIndex
|
|
2752
|
+
/>
|
|
2753
|
+
)
|
|
2754
|
+
|
|
2755
|
+
const kit = screen.getByTestId(testId)
|
|
2756
|
+
expect(kit.querySelector(".pb_draggable_item")).not.toBeInTheDocument()
|
|
2757
|
+
expect(kit.querySelector(".pb_form_pill_kit")).not.toBeInTheDocument()
|
|
2758
|
+
})
|
|
2759
|
+
|
|
2760
|
+
test("works with multiSelect and autocomplete", () => {
|
|
2761
|
+
render(
|
|
2762
|
+
<Dropdown
|
|
2763
|
+
autocomplete
|
|
2764
|
+
data={{ testid: testId }}
|
|
2765
|
+
enablePillReorder
|
|
2766
|
+
multiSelect
|
|
2767
|
+
options={options}
|
|
2768
|
+
showPillIndex
|
|
2769
|
+
value={[options[0], options[1]]}
|
|
2770
|
+
/>
|
|
2771
|
+
)
|
|
2772
|
+
|
|
2773
|
+
const kit = screen.getByTestId(testId)
|
|
2774
|
+
expect(kit.querySelector(".dropdown_input")).toBeInTheDocument()
|
|
2775
|
+
expect(kit.querySelectorAll(".pb_draggable_item").length).toBe(2)
|
|
2776
|
+
expect(kit.querySelectorAll(".pb_form_pill_kit_icon")[0]).toHaveTextContent("1. United States")
|
|
2777
|
+
})
|
|
2778
|
+
})
|
|
@@ -1814,3 +1814,257 @@ describe("PbDropdown option creation", () => {
|
|
|
1814
1814
|
expect(getCreationRow()).toBeNull();
|
|
1815
1815
|
});
|
|
1816
1816
|
});
|
|
1817
|
+
|
|
1818
|
+
describe("PbDropdown pill reorder", () => {
|
|
1819
|
+
let root;
|
|
1820
|
+
let instance;
|
|
1821
|
+
|
|
1822
|
+
const mountReorder = ({
|
|
1823
|
+
externalDragHandle = false,
|
|
1824
|
+
showPillIndex = true,
|
|
1825
|
+
} = {}) => {
|
|
1826
|
+
root = buildDropdownElement({
|
|
1827
|
+
options: [
|
|
1828
|
+
{ id: "year", label: "Year", value: "year" },
|
|
1829
|
+
{ id: "territory", label: "Territory", value: "territory" },
|
|
1830
|
+
{ id: "branch", label: "Branch", value: "branch" },
|
|
1831
|
+
],
|
|
1832
|
+
});
|
|
1833
|
+
root.dataset.pbDropdownMultiSelect = "true";
|
|
1834
|
+
root.dataset.pbDropdownEnablePillReorder = "true";
|
|
1835
|
+
root.dataset.pbDropdownShowPillIndex = showPillIndex ? "true" : "false";
|
|
1836
|
+
if (externalDragHandle) root.dataset.pbDropdownExternalDragHandle = "true";
|
|
1837
|
+
root.innerHTML = `
|
|
1838
|
+
<div class="dropdown_wrapper">
|
|
1839
|
+
<input data-dropdown-selected-option name="services[]" style="display: none" />
|
|
1840
|
+
<div class="pb_dropdown_trigger">
|
|
1841
|
+
<div data-dropdown-pills-wrapper></div>
|
|
1842
|
+
<span data-dropdown-trigger-display-multi-select>Choose one</span>
|
|
1843
|
+
</div>
|
|
1844
|
+
<div class="pb_dropdown_container close" data-dropdown-container="true">
|
|
1845
|
+
<div class="pb_list_kit"></div>
|
|
1846
|
+
</div>
|
|
1847
|
+
</div>
|
|
1848
|
+
`;
|
|
1849
|
+
const list = root.querySelector(".pb_list_kit");
|
|
1850
|
+
[
|
|
1851
|
+
{ id: "year", label: "Year", value: "year" },
|
|
1852
|
+
{ id: "territory", label: "Territory", value: "territory" },
|
|
1853
|
+
{ id: "branch", label: "Branch", value: "branch" },
|
|
1854
|
+
].forEach((option) => {
|
|
1855
|
+
list.appendChild(new PbDropdown(root).buildOptionElement(option));
|
|
1856
|
+
});
|
|
1857
|
+
instance = new PbDropdown(root);
|
|
1858
|
+
instance.connect();
|
|
1859
|
+
instance.setSelectionByOptionIds(["year", "territory", "branch"]);
|
|
1860
|
+
};
|
|
1861
|
+
|
|
1862
|
+
afterEach(() => {
|
|
1863
|
+
instance?.disconnect();
|
|
1864
|
+
document.body.innerHTML = "";
|
|
1865
|
+
});
|
|
1866
|
+
|
|
1867
|
+
test("enable_pill_reorder renders numbered draggable pills", () => {
|
|
1868
|
+
mountReorder();
|
|
1869
|
+
const pills = root.querySelectorAll(".pb_form_pill_kit_icon");
|
|
1870
|
+
expect(pills.length).toBe(3);
|
|
1871
|
+
expect(pills[0]).toHaveTextContent("1. Year");
|
|
1872
|
+
expect(pills[1]).toHaveTextContent("2. Territory");
|
|
1873
|
+
expect(pills[2]).toHaveTextContent("3. Branch");
|
|
1874
|
+
expect(root.querySelectorAll(".pb_draggable_item").length).toBe(3);
|
|
1875
|
+
expect(root.querySelector(".pb_dropdown_external_drag_handle")).toBeNull();
|
|
1876
|
+
});
|
|
1877
|
+
|
|
1878
|
+
test("keyboard reorder updates selection, form values, and reordered event", () => {
|
|
1879
|
+
mountReorder();
|
|
1880
|
+
const reordered = jest.fn();
|
|
1881
|
+
root.addEventListener("pb:dropdown:reordered", reordered);
|
|
1882
|
+
const pills = root.querySelectorAll(".pb_form_pill_kit_icon");
|
|
1883
|
+
|
|
1884
|
+
pills[1].dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true }));
|
|
1885
|
+
|
|
1886
|
+
expect(Array.from(instance.selectedOptions).map((raw) => JSON.parse(raw).label)).toEqual([
|
|
1887
|
+
"Territory",
|
|
1888
|
+
"Year",
|
|
1889
|
+
"Branch",
|
|
1890
|
+
]);
|
|
1891
|
+
expect(Array.from(root.querySelectorAll("input[data-generated]")).map((input) => input.value)).toEqual([
|
|
1892
|
+
"territory",
|
|
1893
|
+
"year",
|
|
1894
|
+
"branch",
|
|
1895
|
+
]);
|
|
1896
|
+
expect(reordered).toHaveBeenCalled();
|
|
1897
|
+
expect(reordered.mock.calls[0][0].detail.map((item) => item.label)).toEqual([
|
|
1898
|
+
"Territory",
|
|
1899
|
+
"Year",
|
|
1900
|
+
"Branch",
|
|
1901
|
+
]);
|
|
1902
|
+
});
|
|
1903
|
+
|
|
1904
|
+
test("external_drag_handle renders external handles", () => {
|
|
1905
|
+
mountReorder({ externalDragHandle: true });
|
|
1906
|
+
const handles = root.querySelectorAll(".pb_dropdown_external_drag_handle");
|
|
1907
|
+
expect(handles.length).toBe(3);
|
|
1908
|
+
expect(root.querySelectorAll(".pb_form_pill_kit_icon").length).toBe(0);
|
|
1909
|
+
handles.forEach((handle) => {
|
|
1910
|
+
expect(handle.querySelector(".pb_dropdown_pill_grip_icon")).not.toBeNull();
|
|
1911
|
+
});
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
test("grip icon uses the playbook-icons grip-dots-vertical path", () => {
|
|
1915
|
+
mountReorder();
|
|
1916
|
+
const grip = root.querySelector(".pb_dropdown_pill_grip_icon");
|
|
1917
|
+
expect(grip).not.toBeNull();
|
|
1918
|
+
expect(grip).toHaveClass("pb_custom_icon");
|
|
1919
|
+
expect(grip.getAttribute("viewBox")).toBe("0 0 31 25");
|
|
1920
|
+
expect(grip.querySelector("path").getAttribute("d")).toContain("12.9043 6.35547");
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
test("dragging a pill commits order on drop", () => {
|
|
1924
|
+
mountReorder();
|
|
1925
|
+
const reordered = jest.fn();
|
|
1926
|
+
root.addEventListener("pb:dropdown:reordered", reordered);
|
|
1927
|
+
|
|
1928
|
+
const draggableItems = root.querySelectorAll(".pb_draggable_item");
|
|
1929
|
+
draggableItems.forEach((item, index) => {
|
|
1930
|
+
item.getBoundingClientRect = () => ({
|
|
1931
|
+
left: index * 100,
|
|
1932
|
+
right: index * 100 + 100,
|
|
1933
|
+
width: 100,
|
|
1934
|
+
top: 0,
|
|
1935
|
+
bottom: 30,
|
|
1936
|
+
height: 30,
|
|
1937
|
+
});
|
|
1938
|
+
});
|
|
1939
|
+
|
|
1940
|
+
draggableItems[0].dispatchEvent(new MouseEvent("mousedown", {
|
|
1941
|
+
button: 0,
|
|
1942
|
+
clientX: 10,
|
|
1943
|
+
clientY: 10,
|
|
1944
|
+
bubbles: true,
|
|
1945
|
+
}));
|
|
1946
|
+
document.dispatchEvent(new MouseEvent("mousemove", {
|
|
1947
|
+
clientX: 280,
|
|
1948
|
+
clientY: 10,
|
|
1949
|
+
bubbles: true,
|
|
1950
|
+
}));
|
|
1951
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).not.toBeNull();
|
|
1952
|
+
expect(draggableItems[2].classList.contains("pb_dropdown_drop_after")).toBe(true);
|
|
1953
|
+
|
|
1954
|
+
document.dispatchEvent(new MouseEvent("mouseup", {
|
|
1955
|
+
clientX: 280,
|
|
1956
|
+
clientY: 10,
|
|
1957
|
+
bubbles: true,
|
|
1958
|
+
}));
|
|
1959
|
+
|
|
1960
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).toBeNull();
|
|
1961
|
+
expect(reordered).toHaveBeenCalled();
|
|
1962
|
+
expect(reordered.mock.calls[0][0].detail.map((item) => item.label)).toEqual([
|
|
1963
|
+
"Territory",
|
|
1964
|
+
"Branch",
|
|
1965
|
+
"Year",
|
|
1966
|
+
]);
|
|
1967
|
+
expect(Array.from(root.querySelectorAll("input[data-generated]")).map((input) => input.value)).toEqual([
|
|
1968
|
+
"territory",
|
|
1969
|
+
"branch",
|
|
1970
|
+
"year",
|
|
1971
|
+
]);
|
|
1972
|
+
});
|
|
1973
|
+
|
|
1974
|
+
test("removing a pill still works with reorder enabled", () => {
|
|
1975
|
+
mountReorder();
|
|
1976
|
+
root.querySelector(".pb_form_pill_close").click();
|
|
1977
|
+
expect(Array.from(instance.selectedOptions).map((raw) => JSON.parse(raw).label)).toEqual([
|
|
1978
|
+
"Territory",
|
|
1979
|
+
"Branch",
|
|
1980
|
+
]);
|
|
1981
|
+
expect(root.querySelectorAll(".pb_form_pill_kit_icon")[0]).toHaveTextContent("1. Territory");
|
|
1982
|
+
});
|
|
1983
|
+
|
|
1984
|
+
test("mousedown focuses a pill for keyboard reorder", () => {
|
|
1985
|
+
mountReorder();
|
|
1986
|
+
const pills = root.querySelectorAll(".pb_form_pill_kit_icon");
|
|
1987
|
+
const draggableItems = root.querySelectorAll(".pb_draggable_item");
|
|
1988
|
+
|
|
1989
|
+
draggableItems[1].dispatchEvent(new MouseEvent("mousedown", {
|
|
1990
|
+
button: 0,
|
|
1991
|
+
clientX: 110,
|
|
1992
|
+
clientY: 10,
|
|
1993
|
+
bubbles: true,
|
|
1994
|
+
}));
|
|
1995
|
+
document.dispatchEvent(new MouseEvent("mouseup", {
|
|
1996
|
+
clientX: 110,
|
|
1997
|
+
clientY: 10,
|
|
1998
|
+
bubbles: true,
|
|
1999
|
+
}));
|
|
2000
|
+
|
|
2001
|
+
expect(document.activeElement).toBe(pills[1]);
|
|
2002
|
+
|
|
2003
|
+
const reordered = jest.fn();
|
|
2004
|
+
root.addEventListener("pb:dropdown:reordered", reordered);
|
|
2005
|
+
pills[1].dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true }));
|
|
2006
|
+
expect(reordered).toHaveBeenCalled();
|
|
2007
|
+
expect(reordered.mock.calls[0][0].detail.map((item) => item.label)).toEqual([
|
|
2008
|
+
"Territory",
|
|
2009
|
+
"Year",
|
|
2010
|
+
"Branch",
|
|
2011
|
+
]);
|
|
2012
|
+
});
|
|
2013
|
+
|
|
2014
|
+
test("touch dragging a pill commits order on drop", () => {
|
|
2015
|
+
mountReorder();
|
|
2016
|
+
const reordered = jest.fn();
|
|
2017
|
+
root.addEventListener("pb:dropdown:reordered", reordered);
|
|
2018
|
+
|
|
2019
|
+
const draggableItems = root.querySelectorAll(".pb_draggable_item");
|
|
2020
|
+
draggableItems.forEach((item, index) => {
|
|
2021
|
+
item.getBoundingClientRect = () => ({
|
|
2022
|
+
left: index * 100,
|
|
2023
|
+
right: index * 100 + 100,
|
|
2024
|
+
width: 100,
|
|
2025
|
+
top: 0,
|
|
2026
|
+
bottom: 30,
|
|
2027
|
+
height: 30,
|
|
2028
|
+
});
|
|
2029
|
+
});
|
|
2030
|
+
|
|
2031
|
+
const touch = (clientX, clientY, identifier = 1) => ({
|
|
2032
|
+
identifier,
|
|
2033
|
+
clientX,
|
|
2034
|
+
clientY,
|
|
2035
|
+
target: draggableItems[0],
|
|
2036
|
+
});
|
|
2037
|
+
|
|
2038
|
+
draggableItems[0].dispatchEvent(new TouchEvent("touchstart", {
|
|
2039
|
+
bubbles: true,
|
|
2040
|
+
cancelable: true,
|
|
2041
|
+
touches: [touch(10, 10)],
|
|
2042
|
+
targetTouches: [touch(10, 10)],
|
|
2043
|
+
changedTouches: [touch(10, 10)],
|
|
2044
|
+
}));
|
|
2045
|
+
document.dispatchEvent(new TouchEvent("touchmove", {
|
|
2046
|
+
bubbles: true,
|
|
2047
|
+
cancelable: true,
|
|
2048
|
+
touches: [touch(280, 10)],
|
|
2049
|
+
targetTouches: [touch(280, 10)],
|
|
2050
|
+
changedTouches: [touch(280, 10)],
|
|
2051
|
+
}));
|
|
2052
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).not.toBeNull();
|
|
2053
|
+
|
|
2054
|
+
document.dispatchEvent(new TouchEvent("touchend", {
|
|
2055
|
+
bubbles: true,
|
|
2056
|
+
cancelable: true,
|
|
2057
|
+
touches: [],
|
|
2058
|
+
targetTouches: [],
|
|
2059
|
+
changedTouches: [touch(280, 10)],
|
|
2060
|
+
}));
|
|
2061
|
+
|
|
2062
|
+
expect(document.querySelector(".pb_dropdown_pill_drag_preview")).toBeNull();
|
|
2063
|
+
expect(reordered).toHaveBeenCalled();
|
|
2064
|
+
expect(reordered.mock.calls[0][0].detail.map((item) => item.label)).toEqual([
|
|
2065
|
+
"Territory",
|
|
2066
|
+
"Branch",
|
|
2067
|
+
"Year",
|
|
2068
|
+
]);
|
|
2069
|
+
});
|
|
2070
|
+
});
|