playbook_ui 18.2.0 → 18.3.0.pre.alpha.forwardrefwarnings20879
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_collapsible/collapsible.test.js +1 -2
- 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/date.test.js +1 -1
- data/app/pb_kits/playbook/pb_date/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_date_picker/date_picker.test.js +4 -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/date_stacked.test.js +1 -0
- 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/dateTime.test.js +1 -0
- 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/date_year_stacked.test.js +1 -0
- 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 +121 -15
- 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/_dropdown_form.jsx +50 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_form_react.md +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_option_creation.html.erb +16 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_option_creation.jsx +27 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_option_creation_rails.md +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_option_creation_react.md +9 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/_playground.json +33 -2
- data/app/pb_kits/playbook/pb_dropdown/docs/_playground.overrides.json +13 -2
- data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +5 -0
- data/app/pb_kits/playbook/pb_dropdown/docs/index.js +4 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +2 -2
- data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +24 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +235 -1
- data/app/pb_kits/playbook/pb_dropdown/dropdown_creation.test.jsx +414 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown_form.test.jsx +173 -0
- data/app/pb_kits/playbook/pb_dropdown/dropdown_index.test.js +545 -0
- data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +22 -5
- data/app/pb_kits/playbook/pb_dropdown/index.js +260 -37
- data/app/pb_kits/playbook/pb_dropdown/keyboard_accessibility.js +3 -1
- data/app/pb_kits/playbook/pb_dropdown/kit.schema.json +42 -2
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +43 -25
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownFormFields.tsx +83 -0
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +13 -5
- data/app/pb_kits/playbook/pb_dropdown/subcomponents/MultiSelectTriggerDisplay.tsx +336 -31
- data/app/pb_kits/playbook/pb_dropdown/utilities/optionCreation.ts +21 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/pillReorder.js +281 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/quickpickDateSync.test.ts +24 -0
- data/app/pb_kits/playbook/pb_dropdown/utilities/usePillDropIndicator.ts +144 -0
- data/app/pb_kits/playbook/pb_filter/Filter/SortMenu.tsx +8 -1
- data/app/pb_kits/playbook/pb_filter/docs/_filter_one_click.html.erb +38 -0
- data/app/pb_kits/playbook/pb_filter/docs/_filter_one_click.jsx +69 -0
- data/app/pb_kits/playbook/pb_filter/docs/_filter_one_click.md +1 -0
- data/app/pb_kits/playbook/pb_filter/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_filter/docs/index.js +2 -1
- data/app/pb_kits/playbook/pb_filter/filter.html.erb +4 -4
- data/app/pb_kits/playbook/pb_filter/filter.rb +28 -0
- data/app/pb_kits/playbook/pb_filter/filter.test.js +41 -0
- data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.test.js +1 -2
- data/app/pb_kits/playbook/pb_form/docs/_description_react.md +3 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_default_values.jsx +898 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_default_values_react.md +3 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_defaults.jsx +879 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_defaults_react.md +29 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_loading.jsx +75 -0
- data/app/pb_kits/playbook/pb_form/docs/{_form_loading.md → _form_loading_rails.md} +1 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_loading_react.md +1 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_model_values.jsx +147 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_model_values_react.md +16 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_multi_column.jsx +164 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_multi_column_react.md +3 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_validation.jsx +1057 -0
- data/app/pb_kits/playbook/pb_form/docs/_form_validation_react.md +26 -0
- data/app/pb_kits/playbook/pb_form/docs/example.yml +7 -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_full_screen/_full_screen.scss +6 -0
- data/app/pb_kits/playbook/pb_full_screen/_full_screen.tsx +11 -2
- data/app/pb_kits/playbook/pb_full_screen/docs/_full_screen_advanced_table_sticky_header.jsx +73 -0
- data/app/pb_kits/playbook/pb_full_screen/docs/_full_screen_advanced_table_sticky_header.md +1 -0
- data/app/pb_kits/playbook/pb_full_screen/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_full_screen/docs/index.js +1 -0
- data/app/pb_kits/playbook/pb_full_screen/full_screen.test.jsx +4 -2
- 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_label_pill/_label_pill.tsx +3 -1
- data/app/pb_kits/playbook/pb_label_pill/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_legend/_legend.tsx +3 -1
- data/app/pb_kits/playbook/pb_legend/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_multi_level_select/_multi_level_select.tsx +4 -1
- data/app/pb_kits/playbook/pb_online_status/_online_status.tsx +3 -1
- data/app/pb_kits/playbook/pb_online_status/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_pb_bar_graph/pbbargraph.test.jsx +1 -2
- data/app/pb_kits/playbook/pb_pb_circle_chart/pb_circle_chart.test.jsx +1 -2
- data/app/pb_kits/playbook/pb_pb_gauge_chart/pb_gauge_chart.test.jsx +1 -2
- data/app/pb_kits/playbook/pb_pb_line_graph/pb_line_graph.test.jsx +1 -2
- 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_pill/_pill.tsx +3 -1
- data/app/pb_kits/playbook/pb_pill/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_progress_step/_progress_step_item.tsx +3 -1
- 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_advanced_required_indicator.md +2 -2
- 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/docs/_rich_text_editor_rails_required_indicator.html.erb +9 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/_rich_text_editor_rails_required_indicator.md +3 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/docs/example.yml +1 -0
- data/app/pb_kits/playbook/pb_rich_text_editor/rich_text_editor.html.erb +3 -7
- 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.tsx +3 -1
- data/app/pb_kits/playbook/pb_source/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_source/source.rb +1 -1
- data/app/pb_kits/playbook/pb_stat_change/_stat_change.tsx +3 -1
- data/app/pb_kits/playbook/pb_stat_change/kit.schema.json +1 -0
- data/app/pb_kits/playbook/pb_textarea/_textarea.tsx +4 -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_timeline/_item.tsx +3 -1
- 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_timestamp/timestamp.test.js +1 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.scss +73 -0
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.test.jsx +285 -12
- data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +22 -14
- data/app/pb_kits/playbook/pb_typeahead/components/PillRenderer.tsx +15 -11
- data/app/pb_kits/playbook/pb_typeahead/components/ValueContainer.tsx +29 -30
- data/app/pb_kits/playbook/pb_typeahead/components/usePillDropIndicator.ts +155 -0
- data/app/pb_kits/playbook/pb_typeahead/docs/_playground.json +5 -5
- data/app/pb_kits/playbook/pb_typeahead/docs/_playground.overrides.json +2 -2
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_draggable_pills.html.erb +0 -1
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_draggable_pills.jsx +0 -1
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_draggable_pills_rails.md +3 -3
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_draggable_pills_react.md +7 -0
- data/app/pb_kits/playbook/pb_typeahead/kit.schema.json +3 -3
- data/app/pb_kits/playbook/pb_typeahead/typeahead.rb +3 -3
- 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/pb_weekday_stacked/weekday_stacked.test.jsx +1 -0
- data/app/pb_kits/playbook/utilities/test/globalProps/onClick.test.js +302 -0
- data/app/pb_kits/playbook/utilities/test-utils.js +0 -1
- data/dist/ai/all-schemas.json +108 -15
- 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 +81 -11
- data/dist/ai/kits/image.schema.json +1 -0
- data/dist/ai/kits/label_pill.schema.json +1 -0
- data/dist/ai/kits/legend.schema.json +1 -0
- data/dist/ai/kits/online_status.schema.json +1 -0
- data/dist/ai/kits/person.schema.json +1 -0
- data/dist/ai/kits/pill.schema.json +1 -0
- data/dist/ai/kits/rich_text_editor.schema.json +1 -1
- data/dist/ai/kits/source.schema.json +1 -0
- data/dist/ai/kits/stat_change.schema.json +1 -0
- 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/typeahead.schema.json +3 -3
- 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/index.json +1 -1
- data/dist/ai/playgrounds/rich_text_editor.json +1 -1
- data/dist/ai/playgrounds/typeahead.json +1 -1
- data/dist/chunks/_pagination-CARbC_IN.js +1 -0
- data/dist/chunks/{_pb_line_graph-Du7xE9vl.js → _pb_line_graph-BKwbOeqo.js} +1 -1
- data/dist/chunks/{_detail-Bsvl694i.js → _tooltip-UkcgcThO.js} +2 -2
- data/dist/chunks/_typeahead-D_li2Zx8.js +1 -0
- data/dist/chunks/{globalProps-B120NbSJ.js → globalProps-BivjwRew.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/lib-C50eCpoN.js +29 -0
- data/dist/chunks/{time_picker_helper-CYGg0UQ0.js → time_picker_helper-DfKvHCJu.js} +1 -1
- 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 +2 -2
- metadata +80 -21
- data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_draggable_pills.md +0 -7
- data/dist/chunks/_table-Bf6LGyL9.js +0 -1
- data/dist/chunks/_typeahead-w6S5Vx4b.js +0 -1
- data/dist/chunks/lib-Buo6zHEw.js +0 -29
- /data/app/pb_kits/playbook/pb_form/docs/{_description.md → _description_rails.md} +0 -0
- /data/app/pb_kits/playbook/pb_form/docs/{_form_default_values.md → _form_default_values_rails.md} +0 -0
- /data/app/pb_kits/playbook/pb_form/docs/{_form_defaults.md → _form_defaults_rails.md} +0 -0
- /data/app/pb_kits/playbook/pb_form/docs/{_form_model_values.md → _form_model_values_rails.md} +0 -0
- /data/app/pb_kits/playbook/pb_form/docs/{_form_multi_column.md → _form_multi_column_rails.md} +0 -0
- /data/app/pb_kits/playbook/pb_form/docs/{_form_validation.md → _form_validation_rails.md} +0 -0
|
@@ -1523,3 +1523,548 @@ describe("PbDropdown multi-select identity", () => {
|
|
|
1523
1523
|
jest.useRealTimers();
|
|
1524
1524
|
});
|
|
1525
1525
|
});
|
|
1526
|
+
|
|
1527
|
+
describe("PbDropdown option creation", () => {
|
|
1528
|
+
let root;
|
|
1529
|
+
let instance;
|
|
1530
|
+
let input;
|
|
1531
|
+
|
|
1532
|
+
const mount = ({ multi = false, async = false, creation = true, required = false, disabled = false, defaultValue = "" } = {}) => {
|
|
1533
|
+
root = buildDropdownElement({ options: [{ id: "existing", label: "Existing", value: "existing" }] });
|
|
1534
|
+
root.dataset.pbDropdownAllowOptionCreation = String(creation);
|
|
1535
|
+
root.dataset.pbDropdownDisabled = String(disabled);
|
|
1536
|
+
const baseInput = root.querySelector("[data-dropdown-selected-option]");
|
|
1537
|
+
baseInput.required = required;
|
|
1538
|
+
baseInput.dataset.defaultValue = defaultValue;
|
|
1539
|
+
root.dataset.pbDropdownMultiSelect = String(multi);
|
|
1540
|
+
if (async) root.dataset.pbDropdownAsync = "true";
|
|
1541
|
+
root.dataset.pbDropdownSearchTermMinimumLength = "1";
|
|
1542
|
+
root.dataset.pbDropdownSearchDebounceTimeout = "0";
|
|
1543
|
+
input = document.createElement("input");
|
|
1544
|
+
input.dataset.dropdownAutocomplete = "true";
|
|
1545
|
+
root.querySelector(".pb_dropdown_trigger").appendChild(input);
|
|
1546
|
+
if (multi) root.querySelector("[data-dropdown-selected-option]").name = "tags[]";
|
|
1547
|
+
const form = document.createElement("form");
|
|
1548
|
+
root.replaceWith(form);
|
|
1549
|
+
form.appendChild(root);
|
|
1550
|
+
instance = new PbDropdown(root);
|
|
1551
|
+
instance.connect();
|
|
1552
|
+
return form;
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
const typeQuery = value => {
|
|
1556
|
+
input.value = value;
|
|
1557
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1558
|
+
};
|
|
1559
|
+
const getCreationRow = () => root.querySelector("[data-dropdown-create-option]");
|
|
1560
|
+
|
|
1561
|
+
afterEach(() => {
|
|
1562
|
+
instance?.disconnect();
|
|
1563
|
+
document.body.innerHTML = "";
|
|
1564
|
+
jest.useRealTimers();
|
|
1565
|
+
});
|
|
1566
|
+
|
|
1567
|
+
test("Enter on a partial query creates the value instead of selecting the first match", () => {
|
|
1568
|
+
mount();
|
|
1569
|
+
const onSelect = jest.fn();
|
|
1570
|
+
root.addEventListener("pb:dropdown:selected", event => onSelect(event.detail));
|
|
1571
|
+
typeQuery("Ex");
|
|
1572
|
+
|
|
1573
|
+
const createRow = getCreationRow();
|
|
1574
|
+
expect(createRow).toHaveClass("pb_dropdown_option_focused");
|
|
1575
|
+
expect(instance.queryAllOptions()[0]).not.toHaveClass("pb_dropdown_option_focused");
|
|
1576
|
+
|
|
1577
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
|
|
1578
|
+
expect(onSelect).toHaveBeenCalledWith({ id: "Ex", label: "Ex", value: "Ex", __isNew__: true });
|
|
1579
|
+
|
|
1580
|
+
typeQuery("Ex");
|
|
1581
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));
|
|
1582
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
1583
|
+
expect(JSON.parse(instance.selectedOptionJson)).toEqual({ id: "existing", label: "Existing", value: "existing" });
|
|
1584
|
+
});
|
|
1585
|
+
|
|
1586
|
+
test("Enter creates a trimmed value through the selection event and form input", () => {
|
|
1587
|
+
jest.useFakeTimers();
|
|
1588
|
+
const form = mount();
|
|
1589
|
+
const onSelect = jest.fn();
|
|
1590
|
+
root.addEventListener("pb:dropdown:selected", event => onSelect(event.detail));
|
|
1591
|
+
typeQuery(" New tag ");
|
|
1592
|
+
expect(getCreationRow().textContent).toBe('Create "New tag"');
|
|
1593
|
+
input.dispatchEvent(new KeyboardEvent("keydown", {
|
|
1594
|
+
key: "Enter",
|
|
1595
|
+
bubbles: true,
|
|
1596
|
+
cancelable: true,
|
|
1597
|
+
}));
|
|
1598
|
+
expect(onSelect).toHaveBeenCalledWith({
|
|
1599
|
+
id: "New tag",
|
|
1600
|
+
label: "New tag",
|
|
1601
|
+
value: "New tag",
|
|
1602
|
+
__isNew__: true,
|
|
1603
|
+
});
|
|
1604
|
+
expect(new FormData(form).get("country")).toBe("New tag");
|
|
1605
|
+
expect(getCreationRow()).toBeNull();
|
|
1606
|
+
jest.runOnlyPendingTimers();
|
|
1607
|
+
expect(instance.target).toHaveClass("close");
|
|
1608
|
+
});
|
|
1609
|
+
|
|
1610
|
+
test("multi-select submits separate values and suppresses selected duplicates", () => {
|
|
1611
|
+
const form = mount({ multi: true });
|
|
1612
|
+
for (const value of ["First", "Second"]) {
|
|
1613
|
+
typeQuery(value);
|
|
1614
|
+
instance.handleOptionClick({ target: getCreationRow() });
|
|
1615
|
+
}
|
|
1616
|
+
expect(new FormData(form).getAll("tags[]")).toEqual(["First", "Second"]);
|
|
1617
|
+
typeQuery(" first ");
|
|
1618
|
+
expect(getCreationRow()).toBeNull();
|
|
1619
|
+
});
|
|
1620
|
+
|
|
1621
|
+
test("whitespace, existing labels and values cannot be created", () => {
|
|
1622
|
+
mount();
|
|
1623
|
+
for (const value of [" ", " EXISTING ", "existing"]) {
|
|
1624
|
+
typeQuery(value);
|
|
1625
|
+
expect(getCreationRow()).toBeNull();
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
test("clear and reset remove the creation row", () => {
|
|
1630
|
+
mount();
|
|
1631
|
+
typeQuery("New");
|
|
1632
|
+
instance.clearSelection();
|
|
1633
|
+
expect(getCreationRow()).toBeNull();
|
|
1634
|
+
typeQuery("Another");
|
|
1635
|
+
instance.resetDropdownValue();
|
|
1636
|
+
expect(getCreationRow()).toBeNull();
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
test("async results resolve before creation and stale callbacks are ignored", () => {
|
|
1640
|
+
jest.useFakeTimers();
|
|
1641
|
+
mount({ async: true });
|
|
1642
|
+
const searches = [];
|
|
1643
|
+
root.addEventListener("pb:dropdown:search", event => searches.push(event.detail));
|
|
1644
|
+
typeQuery("Old");
|
|
1645
|
+
jest.runOnlyPendingTimers();
|
|
1646
|
+
expect(getCreationRow()).toBeNull();
|
|
1647
|
+
typeQuery("New");
|
|
1648
|
+
jest.runOnlyPendingTimers();
|
|
1649
|
+
searches[1].setResults([]);
|
|
1650
|
+
expect(getCreationRow().textContent).toBe('Create "New"');
|
|
1651
|
+
searches[0].setResults([{ id: "old", label: "Old" }]);
|
|
1652
|
+
expect(getCreationRow().textContent).toBe('Create "New"');
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
test("async existing results and errors do not offer creation", () => {
|
|
1656
|
+
jest.useFakeTimers();
|
|
1657
|
+
mount({ async: true });
|
|
1658
|
+
let search;
|
|
1659
|
+
root.addEventListener("pb:dropdown:search", event => { search = event.detail });
|
|
1660
|
+
typeQuery("Existing");
|
|
1661
|
+
jest.runOnlyPendingTimers();
|
|
1662
|
+
search.setResults([{ id: "server", label: "Existing" }]);
|
|
1663
|
+
expect(getCreationRow()).toBeNull();
|
|
1664
|
+
typeQuery("New");
|
|
1665
|
+
jest.runOnlyPendingTimers();
|
|
1666
|
+
search.setError();
|
|
1667
|
+
expect(getCreationRow()).toBeNull();
|
|
1668
|
+
});
|
|
1669
|
+
|
|
1670
|
+
test.each([undefined, false])("creation %s submits individual multi-select values in selection order", (creation) => {
|
|
1671
|
+
const form = mount({ multi: true, creation });
|
|
1672
|
+
if (creation === undefined) delete root.dataset.pbDropdownAllowOptionCreation;
|
|
1673
|
+
instance.replaceOptions([
|
|
1674
|
+
{ id: "first", label: "First", value: "first" },
|
|
1675
|
+
{ id: "second", label: "Second", value: "second" },
|
|
1676
|
+
]);
|
|
1677
|
+
const rows = Array.from(instance.queryAllOptions());
|
|
1678
|
+
rows.forEach((row) => instance.handleOptionClick({ target: row }));
|
|
1679
|
+
expect(instance.baseInput.value).toBe("");
|
|
1680
|
+
expect(new FormData(form).getAll("tags[]")).toEqual(["first", "second"]);
|
|
1681
|
+
typeQuery("New");
|
|
1682
|
+
expect(getCreationRow()).toBeNull();
|
|
1683
|
+
});
|
|
1684
|
+
|
|
1685
|
+
test.each(["ny", " NY ", "empire"])("keeps the existing option selectable for query %s", (query) => {
|
|
1686
|
+
mount();
|
|
1687
|
+
const newYork = { id: "ny", label: "New York", value: "empire" };
|
|
1688
|
+
instance.replaceOptions([newYork]);
|
|
1689
|
+
typeQuery(query);
|
|
1690
|
+
|
|
1691
|
+
const optionRow = instance.queryAllOptions()[0];
|
|
1692
|
+
expect(optionRow.style.display).toBe("");
|
|
1693
|
+
expect(getCreationRow()).toBeNull();
|
|
1694
|
+
expect(instance.target.querySelector(".dropdown_no_options")).toBeNull();
|
|
1695
|
+
|
|
1696
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));
|
|
1697
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
1698
|
+
expect(instance.baseInput.value).toBe("ny");
|
|
1699
|
+
expect(JSON.parse(instance.selectedOptionJson)).toEqual(newYork);
|
|
1700
|
+
});
|
|
1701
|
+
|
|
1702
|
+
const reopen = () => {
|
|
1703
|
+
if (!instance.target.classList.contains("open")) instance.showElement(instance.target);
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
test("reopening a single-select after choosing an existing option keeps that option", () => {
|
|
1707
|
+
mount();
|
|
1708
|
+
const option = instance.queryAllOptions()[0];
|
|
1709
|
+
option.click();
|
|
1710
|
+
reopen();
|
|
1711
|
+
expect(instance.target).toHaveClass("open");
|
|
1712
|
+
expect(option.style.display).not.toBe("none");
|
|
1713
|
+
expect(input.value).toBe("Existing");
|
|
1714
|
+
expect(instance.target.querySelector(".dropdown_no_options")).toBeNull();
|
|
1715
|
+
});
|
|
1716
|
+
|
|
1717
|
+
test("reopening a multi-select after its only option is chosen shows the empty message", () => {
|
|
1718
|
+
mount({ multi: true });
|
|
1719
|
+
const option = instance.queryAllOptions()[0];
|
|
1720
|
+
option.click();
|
|
1721
|
+
reopen();
|
|
1722
|
+
expect(instance.target).toHaveClass("open");
|
|
1723
|
+
expect(option.style.display).toBe("none");
|
|
1724
|
+
expect(instance.target.querySelector(".dropdown_no_options")).toHaveTextContent("no option");
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
test("reopening a multi-select keeps the options that are still available", () => {
|
|
1728
|
+
mount({ multi: true });
|
|
1729
|
+
instance.replaceOptions([
|
|
1730
|
+
{ id: "existing", label: "Existing", value: "existing" },
|
|
1731
|
+
{ id: "other", label: "Other", value: "other" },
|
|
1732
|
+
]);
|
|
1733
|
+
const [selected, remaining] = instance.queryAllOptions();
|
|
1734
|
+
selected.click();
|
|
1735
|
+
reopen();
|
|
1736
|
+
expect(selected.style.display).toBe("none");
|
|
1737
|
+
expect(remaining.style.display).toBe("");
|
|
1738
|
+
expect(instance.target.querySelector(".dropdown_no_options")).toBeNull();
|
|
1739
|
+
});
|
|
1740
|
+
|
|
1741
|
+
test("static filtering stays label-only when option creation is disabled", () => {
|
|
1742
|
+
mount({ creation: false });
|
|
1743
|
+
instance.replaceOptions([{ id: "ny", label: "New York", value: "empire" }]);
|
|
1744
|
+
typeQuery("ny");
|
|
1745
|
+
expect(instance.queryAllOptions()[0].style.display).toBe("none");
|
|
1746
|
+
expect(getCreationRow()).toBeNull();
|
|
1747
|
+
typeQuery("New");
|
|
1748
|
+
expect(instance.queryAllOptions()[0].style.display).toBe("");
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
test.each([false, true])("clearing selections restores required validation with creation=%s", (creation) => {
|
|
1752
|
+
const form = mount({ multi: true, creation, required: true });
|
|
1753
|
+
expect(instance.baseInput.disabled).toBe(false);
|
|
1754
|
+
expect(form.checkValidity()).toBe(false);
|
|
1755
|
+
|
|
1756
|
+
instance.handleOptionClick({ target: instance.queryAllOptions()[0] });
|
|
1757
|
+
expect(instance.baseInput.hasAttribute("name")).toBe(false);
|
|
1758
|
+
expect(instance.baseInput.disabled).toBe(false);
|
|
1759
|
+
expect(new FormData(form).getAll("tags[]")).toEqual(["existing"]);
|
|
1760
|
+
expect(form.checkValidity()).toBe(true);
|
|
1761
|
+
|
|
1762
|
+
instance.clearSelection();
|
|
1763
|
+
expect(instance.baseInput.disabled).toBe(false);
|
|
1764
|
+
expect(instance.baseInput.required).toBe(true);
|
|
1765
|
+
expect(root.querySelectorAll("input[data-generated]")).toHaveLength(0);
|
|
1766
|
+
expect(form.checkValidity()).toBe(false);
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
test("default selections submit without a blank entry and reset restores validation", () => {
|
|
1770
|
+
const form = mount({ multi: true, required: true, defaultValue: "existing" });
|
|
1771
|
+
expect(instance.baseInput.hasAttribute("name")).toBe(false);
|
|
1772
|
+
expect(instance.baseInput.disabled).toBe(false);
|
|
1773
|
+
expect(new FormData(form).getAll("tags[]")).toEqual(["existing"]);
|
|
1774
|
+
|
|
1775
|
+
form.reset();
|
|
1776
|
+
expect(instance.baseInput.disabled).toBe(false);
|
|
1777
|
+
expect(instance.baseInput.required).toBe(true);
|
|
1778
|
+
expect(form.checkValidity()).toBe(false);
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
test("disabled multi-select defaults remain excluded from submission after reset", () => {
|
|
1782
|
+
const form = mount({ multi: true, disabled: true, defaultValue: "existing" });
|
|
1783
|
+
expect(new FormData(form).getAll("tags[]")).toEqual([]);
|
|
1784
|
+
form.reset();
|
|
1785
|
+
expect(instance.baseInput.disabled).toBe(true);
|
|
1786
|
+
expect(new FormData(form).getAll("tags[]")).toEqual([]);
|
|
1787
|
+
});
|
|
1788
|
+
|
|
1789
|
+
test("Turbo reconnect preserves submission order and restores required validation", () => {
|
|
1790
|
+
const form = mount({ multi: true, required: true, defaultValue: "existing" });
|
|
1791
|
+
instance.disconnect();
|
|
1792
|
+
instance = new PbDropdown(root);
|
|
1793
|
+
instance.connect();
|
|
1794
|
+
|
|
1795
|
+
typeQuery("Second");
|
|
1796
|
+
instance.handleOptionClick({ target: getCreationRow() });
|
|
1797
|
+
expect(new FormData(form).getAll("tags[]")).toEqual(["existing", "Second"]);
|
|
1798
|
+
expect(instance.baseInput.hasAttribute("name")).toBe(false);
|
|
1799
|
+
expect(form.checkValidity()).toBe(true);
|
|
1800
|
+
|
|
1801
|
+
instance.clearSelection();
|
|
1802
|
+
expect(instance.baseInput.name).toBe("tags[]");
|
|
1803
|
+
expect(instance.baseInput.required).toBe(true);
|
|
1804
|
+
expect(form.checkValidity()).toBe(false);
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
test("composition and disabled controls do not create", () => {
|
|
1808
|
+
mount();
|
|
1809
|
+
typeQuery("New");
|
|
1810
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", isComposing: true, bubbles: true }));
|
|
1811
|
+
expect(instance.baseInput.value).toBe("");
|
|
1812
|
+
instance.isDisabled = true;
|
|
1813
|
+
instance.updateCreationOption("Another");
|
|
1814
|
+
expect(getCreationRow()).toBeNull();
|
|
1815
|
+
});
|
|
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
|
+
});
|
|
@@ -7,11 +7,14 @@ export const useHandleOnKeyDown = () => {
|
|
|
7
7
|
const {
|
|
8
8
|
asyncEnabled,
|
|
9
9
|
autocomplete,
|
|
10
|
+
creationEnabled,
|
|
11
|
+
creationOption,
|
|
10
12
|
filterItem,
|
|
11
13
|
filteredOptions,
|
|
12
14
|
focusedOptionIndex,
|
|
13
15
|
handleChange,
|
|
14
16
|
handleOptionClick,
|
|
17
|
+
isDropDownClosed,
|
|
15
18
|
multiSelect,
|
|
16
19
|
selected,
|
|
17
20
|
setFocusedOptionIndex,
|
|
@@ -42,6 +45,8 @@ const {
|
|
|
42
45
|
|
|
43
46
|
return (e: React.KeyboardEvent) => {
|
|
44
47
|
if (e.defaultPrevented) return;
|
|
48
|
+
const isComposing = e.nativeEvent.isComposing || e.keyCode === 229;
|
|
49
|
+
if (creationEnabled && isComposing) return;
|
|
45
50
|
|
|
46
51
|
const printableKey = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey;
|
|
47
52
|
const replacingSelectedLabel = filterItem === selected?.label;
|
|
@@ -58,7 +63,7 @@ const {
|
|
|
58
63
|
|
|
59
64
|
switch (e.key) {
|
|
60
65
|
case "Escape":
|
|
61
|
-
if (asyncEnabled) {
|
|
66
|
+
if (asyncEnabled || creationEnabled) {
|
|
62
67
|
setIsDropDownClosed(true);
|
|
63
68
|
setFocusedOptionIndex(-1);
|
|
64
69
|
}
|
|
@@ -76,15 +81,27 @@ const {
|
|
|
76
81
|
setFocusedOptionIndex(nextIndexUp);
|
|
77
82
|
break;
|
|
78
83
|
}
|
|
79
|
-
case "Enter":
|
|
80
|
-
|
|
84
|
+
case "Enter": {
|
|
85
|
+
const focusedOption = filteredOptions[focusedOptionIndex];
|
|
86
|
+
const canSelectFocused = focusedOptionIndex !== -1 &&
|
|
87
|
+
(!asyncEnabled || focusedOption) &&
|
|
88
|
+
!focusedOption?.disabled;
|
|
89
|
+
// A closed menu or blank query stays available for form submission unless an option is highlighted.
|
|
90
|
+
if (creationEnabled && (isDropDownClosed || (!filterItem.trim() && !canSelectFocused))) return;
|
|
91
|
+
if (canSelectFocused) {
|
|
81
92
|
e.preventDefault();
|
|
82
|
-
handleOptionClick(
|
|
93
|
+
handleOptionClick(focusedOption);
|
|
83
94
|
setFocusedOptionIndex(-1)
|
|
84
95
|
} else if (focusedOptionIndex === -1) {
|
|
85
|
-
|
|
96
|
+
if (creationEnabled && creationOption) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
handleOptionClick(creationOption);
|
|
99
|
+
} else {
|
|
100
|
+
setIsDropDownClosed(false)
|
|
101
|
+
}
|
|
86
102
|
}
|
|
87
103
|
break;
|
|
104
|
+
}
|
|
88
105
|
case "Tab":
|
|
89
106
|
setIsDropDownClosed(true);
|
|
90
107
|
setFocusedOptionIndex(-1)
|