playbook_ui 14.19.0.pre.alpha.PLAY21377811 → 14.19.0.pre.alpha.borderfixadvancedtable7816

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +1 -3
  3. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +16 -8
  4. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +9 -0
  5. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.html.erb +137 -0
  6. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.md +3 -0
  7. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.html.erb +40 -0
  8. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.md +1 -0
  9. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -0
  10. data/app/pb_kits/playbook/pb_advanced_table/index.js +355 -52
  11. data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.html.erb +23 -0
  12. data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.rb +19 -0
  13. data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +4 -0
  14. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +1 -1
  15. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +19 -77
  16. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.html.erb +10 -0
  17. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +1 -11
  18. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +0 -5
  19. data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +3 -3
  20. data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +2 -16
  21. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.html.erb +13 -34
  22. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.rb +1 -3
  23. data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +6 -0
  24. data/app/pb_kits/playbook/pb_dropdown/index.js +41 -334
  25. data/app/pb_kits/playbook/pb_dropdown/keyboard_accessibility.js +12 -39
  26. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +12 -16
  27. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +12 -78
  28. data/app/pb_kits/playbook/pb_form/docs/_form_form_with.html.erb +0 -1
  29. data/app/pb_kits/playbook/pb_form/docs/_form_form_with_validate.html.erb +0 -1
  30. data/dist/chunks/_typeahead-B9-s4j4U.js +22 -0
  31. data/dist/chunks/_weekday_stacked-CvzpmXD5.js +45 -0
  32. data/dist/chunks/{lib-BB_ZEriO.js → lib-B20MXZcW.js} +2 -2
  33. data/dist/chunks/{pb_form_validation-C0la9CZR.js → pb_form_validation-WWvUXPKD.js} +1 -1
  34. data/dist/chunks/vendor.js +1 -1
  35. data/dist/playbook-doc.js +1 -1
  36. data/dist/playbook-rails-react-bindings.js +1 -1
  37. data/dist/playbook-rails.js +1 -1
  38. data/dist/playbook.css +1 -1
  39. data/lib/playbook/version.rb +1 -1
  40. metadata +12 -23
  41. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default_rails.html.erb +0 -31
  42. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default_rails.md +0 -5
  43. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select.jsx +0 -56
  44. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select.md +0 -3
  45. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display.jsx +0 -58
  46. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display.md +0 -3
  47. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display_rails.html.erb +0 -20
  48. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_display_rails.md +0 -1
  49. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_rails.html.erb +0 -19
  50. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_rails.md +0 -3
  51. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_autocomplete.html.erb +0 -20
  52. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_autocomplete.jsx +0 -57
  53. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_autocomplete.md +0 -1
  54. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_custom_options.html.erb +0 -50
  55. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_custom_options.jsx +0 -105
  56. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_default.html.erb +0 -22
  57. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_multi_select_with_default.jsx +0 -67
  58. data/app/pb_kits/playbook/pb_dropdown/subcomponents/MultiSelectTriggerDisplay.tsx +0 -58
  59. data/dist/chunks/_typeahead-CLGxsWj4.js +0 -22
  60. data/dist/chunks/_weekday_stacked-BrJMDrKs.js +0 -45
@@ -13,7 +13,6 @@ const DROPDOWN_PLACEHOLDER = "[data-dropdown-placeholder]";
13
13
  const DROPDOWN_INPUT = "#dropdown-selected-option";
14
14
  const SEARCH_INPUT_SELECTOR = "[data-dropdown-autocomplete]";
15
15
  const SEARCH_BAR_SELECTOR = "[data-dropdown-search]";
16
- const CLEAR_ICON_SELECTOR = "#dropdown_clear_icon";
17
16
 
18
17
  export default class PbDropdown extends PbEnhancedElement {
19
18
  static get selector() {
@@ -21,18 +20,11 @@ export default class PbDropdown extends PbEnhancedElement {
21
20
  }
22
21
 
23
22
  get target() {
24
- return this.element.querySelector(CONTAINER_SELECTOR);
23
+ return this.element.parentNode.querySelector(CONTAINER_SELECTOR);
25
24
  }
26
25
 
27
- selectedOptions = new Set();
28
- clearBtn = null;
29
-
30
26
  connect() {
31
27
  this.keyboardHandler = new PbDropdownKeyboard(this);
32
- this.isMultiSelect = this.element.dataset.pbDropdownMultiSelect === "true";
33
- this.formPillProps = this.element.dataset.formPillProps
34
- ? JSON.parse(this.element.dataset.formPillProps)
35
- : {};
36
28
  this.setDefaultValue();
37
29
  this.bindEventListeners();
38
30
  this.bindSearchInput();
@@ -40,26 +32,6 @@ export default class PbDropdown extends PbEnhancedElement {
40
32
  this.handleFormValidation();
41
33
  this.handleFormReset();
42
34
  this.bindSearchBar();
43
- this.updatePills();
44
-
45
- this.clearBtn = this.element.querySelector(CLEAR_ICON_SELECTOR);
46
- if (this.clearBtn) {
47
- this.clearBtn.style.display = "none";
48
- this.clearBtn.addEventListener("click", (e) => {
49
- e.stopPropagation();
50
- this.clearSelection();
51
- });
52
- }
53
- this.updateClearButton();
54
- }
55
-
56
- updateClearButton() {
57
- if (!this.clearBtn) return;
58
- const hasSelection = this.isMultiSelect
59
- ? this.selectedOptions.size > 0
60
- : Boolean(this.element.querySelector(DROPDOWN_INPUT).value);
61
-
62
- this.clearBtn.style.display = hasSelection ? "" : "none";
63
35
  }
64
36
 
65
37
  bindEventListeners() {
@@ -80,7 +52,7 @@ export default class PbDropdown extends PbEnhancedElement {
80
52
  bindSearchBar() {
81
53
  this.searchBar = this.element.querySelector(SEARCH_BAR_SELECTOR);
82
54
  if (!this.searchBar) return;
83
-
55
+
84
56
  this.searchBar.addEventListener("input", (e) =>
85
57
  this.handleSearch(e.target.value)
86
58
  );
@@ -101,28 +73,11 @@ export default class PbDropdown extends PbEnhancedElement {
101
73
  );
102
74
  }
103
75
 
104
- adjustDropdownHeight() {
105
- if (this.target.classList.contains("open")) {
106
- const el = this.target;
107
- el.style.height = "auto";
108
- requestAnimationFrame(() => {
109
- const newHeight = el.scrollHeight + "px";
110
- el.offsetHeight; // force reflow
111
- el.style.height = newHeight;
112
- });
113
- }
114
- }
115
-
116
76
  handleSearch(term = "") {
117
77
  const lcTerm = term.toLowerCase();
118
78
  this.element.querySelectorAll(OPTION_SELECTOR).forEach((opt) => {
119
- //make it so that if the option is selected, it will not show up in the search results
120
- if (this.isMultiSelect && this.selectedOptions.has(opt.dataset.dropdownOptionLabel)) {
121
- opt.style.display = "none";
122
- return;
123
- }
124
- const label = JSON.parse(opt.dataset.dropdownOptionLabel)
125
- .label.toString()
79
+ const label = JSON.parse(opt.dataset.dropdownOptionLabel).label
80
+ .toString()
126
81
  .toLowerCase();
127
82
 
128
83
  // hide or show option
@@ -130,7 +85,15 @@ export default class PbDropdown extends PbEnhancedElement {
130
85
  opt.style.display = match ? "" : "none";
131
86
  });
132
87
 
133
- this.adjustDropdownHeight();
88
+ if (this.target.classList.contains("open")) {
89
+ const el = this.target;
90
+ el.style.height = "auto";
91
+ requestAnimationFrame(() => {
92
+ const newHeight = el.scrollHeight + "px";
93
+ el.offsetHeight; // force reflow
94
+ el.style.height = newHeight;
95
+ });
96
+ }
134
97
  }
135
98
 
136
99
  handleOptionClick(event) {
@@ -139,26 +102,10 @@ export default class PbDropdown extends PbEnhancedElement {
139
102
 
140
103
  if (option) {
141
104
  const value = option.dataset.dropdownOptionLabel;
142
- if (this.isMultiSelect) {
143
- const alreadySelected = this.selectedOptions.has(value);
144
- if (alreadySelected) {
145
- this.selectedOptions.delete(value);
146
- } else {
147
- this.selectedOptions.add(value);
148
- }
149
- this.updatePills();
150
- this.syncHiddenInputs();
151
- if (this.searchInput && this.isMultiSelect) {
152
- this.searchInput.value = "";
153
- this.handleBackspaceClear();
154
- }
155
- } else {
156
- hiddenInput.value = JSON.parse(value).id;
157
- }
158
-
105
+ hiddenInput.value = JSON.parse(value).id;
159
106
  this.clearFormValidation(hiddenInput);
107
+
160
108
  this.onOptionSelected(value, option);
161
- this.updateClearButton();
162
109
  }
163
110
  }
164
111
 
@@ -190,31 +137,6 @@ export default class PbDropdown extends PbEnhancedElement {
190
137
  }
191
138
  }
192
139
 
193
- emitSelectionChange() {
194
- let detail;
195
-
196
- if (this.isMultiSelect) {
197
- detail = Array.from(this.selectedOptions).map(JSON.parse);
198
- } else {
199
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
200
- detail = hiddenInput.value
201
- ? JSON.parse(
202
- this.element.querySelector(
203
- OPTION_SELECTOR +
204
- `[data-dropdown-option-label*='"id":"${hiddenInput.value}"']`
205
- ).dataset.dropdownOptionLabel
206
- )
207
- : null;
208
- }
209
- this.element.setAttribute("data-option-selected", JSON.stringify(detail));
210
- this.element.dispatchEvent(
211
- new CustomEvent("pb:dropdown:selected", {
212
- detail,
213
- bubbles: true,
214
- })
215
- );
216
- }
217
-
218
140
  onOptionSelected(value, selectedOption) {
219
141
  const triggerElement = this.element.querySelector(DROPDOWN_TRIGGER_DISPLAY);
220
142
  const customDisplayElement = this.element.querySelector(
@@ -222,22 +144,29 @@ export default class PbDropdown extends PbEnhancedElement {
222
144
  );
223
145
 
224
146
  if (triggerElement) {
225
- if (!this.isMultiSelect) {
226
- const selectedLabel = JSON.parse(value).label;
227
- triggerElement.textContent = selectedLabel;
228
- this.emitSelectionChange();
147
+ const selectedLabel = JSON.parse(value).label;
148
+ if (customDisplayElement) {
149
+ triggerElement.textContent = ""
150
+ this.element.setAttribute("data-option-selected", value);
151
+ const selectedObj = JSON.parse(value);
152
+ this.element.dispatchEvent(
153
+ new CustomEvent("pb:dropdown:selected", {
154
+ detail: selectedObj,
155
+ bubbles: true,
156
+ })
157
+ );
158
+ } else {
159
+ triggerElement.textContent = selectedLabel
229
160
  }
230
161
  if (customDisplayElement) {
231
- triggerElement.textContent = "";
232
162
  customDisplayElement.style.display = "block";
233
163
  customDisplayElement.style.paddingRight = "8px";
234
164
  }
235
165
  }
236
166
 
237
167
  const autocompleteInput = this.element.querySelector(SEARCH_INPUT_SELECTOR);
238
- if (autocompleteInput && !this.isMultiSelect) {
168
+ if (autocompleteInput){
239
169
  autocompleteInput.value = JSON.parse(value).label;
240
- this.emitSelectionChange();
241
170
  }
242
171
 
243
172
  const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
@@ -249,24 +178,10 @@ export default class PbDropdown extends PbEnhancedElement {
249
178
  }
250
179
 
251
180
  const options = this.element.querySelectorAll(OPTION_SELECTOR);
252
- if (this.isMultiSelect) {
253
- this.emitSelectionChange();
254
- Array.from(this.selectedOptions).map((option) => {
255
- if (
256
- JSON.parse(option).id ===
257
- JSON.parse(selectedOption.dataset.dropdownOptionLabel).id
258
- ) {
259
- selectedOption.style.display = "none";
260
- this.adjustDropdownHeight();
261
- }
262
- });
263
- } else {
264
- options.forEach((option) => {
265
- option.classList.remove("pb_dropdown_option_selected");
266
- });
267
- selectedOption.classList.add("pb_dropdown_option_selected");
268
- }
269
- this.updateClearButton();
181
+ options.forEach((option) => {
182
+ option.classList.remove("pb_dropdown_option_selected");
183
+ });
184
+ selectedOption.classList.add("pb_dropdown_option_selected");
270
185
  }
271
186
 
272
187
  showElement(elem) {
@@ -340,66 +255,21 @@ export default class PbDropdown extends PbEnhancedElement {
340
255
  errorLabelElement.remove();
341
256
  }
342
257
  }
343
- if (this.isMultiSelect) {
344
- if (this.selectedOptions.size > 0) {
345
- const dropdownWrapperElement = input.closest(".dropdown_wrapper");
346
- dropdownWrapperElement.classList.remove("error");
347
- const errorLabelElement = dropdownWrapperElement.querySelector(
348
- ".pb_body_kit_negative"
349
- );
350
- if (errorLabelElement) {
351
- errorLabelElement.remove();
352
- }
353
- }
354
- }
355
258
  }
356
259
 
357
260
  setDefaultValue() {
358
261
  const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
359
- const optionEls = Array.from(
360
- this.element.querySelectorAll(OPTION_SELECTOR)
361
- );
362
- const defaultValue = hiddenInput.dataset.defaultValue || "";
363
- if (!defaultValue) return;
364
-
365
- if (this.isMultiSelect) {
366
- const ids = defaultValue.split(",");
367
- ids.forEach((id) => {
368
- const selectedOption = optionEls.find((opt) => {
369
- try {
370
- return JSON.parse(opt.dataset.dropdownOptionLabel).id === id;
371
- } catch {
372
- return false;
373
- }
374
- });
375
- if (!selectedOption) {
376
- console.warn(`Dropdown default ID ${id} not found`);
377
- return;
378
- }
379
-
380
- const raw = selectedOption.dataset.dropdownOptionLabel;
381
- this.selectedOptions.add(raw);
262
+ const options = this.element.querySelectorAll(OPTION_SELECTOR);
382
263
 
383
- selectedOption.style.display = "none";
384
- });
264
+ const defaultValue = hiddenInput.dataset.defaultValue || "";
265
+ hiddenInput.value = defaultValue;
385
266
 
386
- this.updatePills();
387
- this.updateClearButton();
388
- this.adjustDropdownHeight();
389
- this.syncHiddenInputs();
390
- } else {
391
- hiddenInput.value = defaultValue;
392
- const selectedOption = optionEls.find((opt) => {
393
- try {
394
- return (
395
- JSON.parse(opt.dataset.dropdownOptionLabel).id === defaultValue
396
- );
397
- } catch {
398
- return false;
399
- }
267
+ if (defaultValue) {
268
+ const selectedOption = Array.from(options).find((option) => {
269
+ return (
270
+ JSON.parse(option.dataset.dropdownOptionLabel).id === defaultValue
271
+ );
400
272
  });
401
- if (!selectedOption) return;
402
-
403
273
  selectedOption.classList.add("pb_dropdown_option_selected");
404
274
  this.setTriggerElementText(
405
275
  JSON.parse(selectedOption.dataset.dropdownOptionLabel).label
@@ -422,32 +292,12 @@ export default class PbDropdown extends PbEnhancedElement {
422
292
  const options = this.element.querySelectorAll(OPTION_SELECTOR);
423
293
  options.forEach((option) => {
424
294
  option.classList.remove("pb_dropdown_option_selected");
425
- option.style.display = "";
426
295
  });
427
296
 
428
297
  hiddenInput.value = "";
429
298
 
430
299
  const defaultPlaceholder = this.element.querySelector(DROPDOWN_PLACEHOLDER);
431
300
  this.setTriggerElementText(defaultPlaceholder.dataset.dropdownPlaceholder);
432
-
433
- if (this.searchInput) {
434
- this.searchInput.value = "";
435
- if (this.target.classList.contains("open")) {
436
- const el = this.target;
437
- el.style.height = "auto";
438
- requestAnimationFrame(() => {
439
- const newHeight = el.scrollHeight + "px";
440
- el.offsetHeight; // force reflow
441
- el.style.height = newHeight;
442
- });
443
- }
444
- }
445
- if (this.isMultiSelect) {
446
- this.selectedOptions.clear();
447
- this.updatePills();
448
- this.updateClearButton();
449
- this.syncHiddenInputs();
450
- }
451
301
  }
452
302
 
453
303
  setTriggerElementText(text) {
@@ -456,147 +306,4 @@ export default class PbDropdown extends PbEnhancedElement {
456
306
  triggerElement.textContent = text;
457
307
  }
458
308
  }
459
-
460
- updatePills() {
461
- if (!this.isMultiSelect) return;
462
-
463
- const wrapper = this.element.querySelector("#dropdown_pills_wrapper");
464
- const placeholder = this.element.querySelector(
465
- "#dropdown_trigger_display_multi_select"
466
- );
467
- if (!wrapper) return;
468
-
469
- wrapper.innerHTML = "";
470
- // Show or hide the placeholder based on selected options
471
- if (placeholder) {
472
- if (this.selectedOptions.size > 0) {
473
- placeholder.style.display = "none";
474
- } else {
475
- placeholder.style.display = "";
476
- }
477
- }
478
-
479
- Array.from(this.selectedOptions).map((option) => {
480
- // Create a form pill for each selected option
481
- const pill = document.createElement("div");
482
- const color = this.formPillProps.color || "primary";
483
- pill.classList.add(`pb_form_pill_kit_${color}`, "mr_xs");
484
- if (this.formPillProps.size === "small") {
485
- pill.classList.add("small");
486
- }
487
- pill.tabIndex = 0;
488
- pill.dataset.pillId = JSON.parse(option).id;
489
- const innerDiv = document.createElement("h3");
490
- innerDiv.className = "pb_title_kit_size_4 pb_form_pill_text";
491
- innerDiv.textContent = JSON.parse(option).label;
492
- pill.appendChild(innerDiv);
493
-
494
- const closeIcon = document.createElement("div");
495
- closeIcon.className = "pb_form_pill_close";
496
- closeIcon.innerHTML = `<svg class="pb_custom_icon svg-inline--fa svg_${
497
- this.formPillProps.size === "small" ? "xs" : "sm"
498
- } svg_fw" xmlns="http://www.w3.org/2000/svg" width="auto" height="auto" viewBox="0 0 31 25"><path fill="currentColor" d="M23.0762 6.77734L17.4512 12.4023L23.0293 17.9805C23.498 18.4023 23.498 19.1055 23.0293 19.5273C22.6074 19.9961 21.9043 19.9961 21.4824 19.5273L15.8574 13.9492L10.2793 19.5273C9.85742 19.9961 9.1543 19.9961 8.73242 19.5273C8.26367 19.1055 8.26367 18.4023 8.73242 17.9336L14.3105 12.3555L8.73242 6.77734C8.26367 6.35547 8.26367 5.65234 8.73242 5.18359C9.1543 4.76172 9.85742 4.76172 10.3262 5.18359L15.9043 10.8086L21.4824 5.23047C21.9043 4.76172 22.6074 4.76172 23.0762 5.23047C23.498 5.65234 23.498 6.35547 23.0762 6.77734Z"/></svg>`;
499
- pill.appendChild(closeIcon);
500
-
501
- closeIcon.addEventListener("click", (e) => {
502
- e.stopPropagation();
503
- const id = pill.dataset.pillId;
504
- this.selectedOptions.delete(option);
505
-
506
- const optEl = this.element.querySelector(
507
- `${OPTION_SELECTOR}[data-dropdown-option-label*='"id":${JSON.stringify(
508
- id
509
- )}']`
510
- );
511
- if (optEl) {
512
- optEl.style.display = "";
513
- if (this.target.classList.contains("open")) {
514
- this.showElement(this.target);
515
- }
516
- }
517
-
518
- this.updatePills();
519
- this.updateClearButton();
520
- this.emitSelectionChange();
521
- this.syncHiddenInputs();
522
- });
523
- wrapper.appendChild(pill);
524
- });
525
- }
526
-
527
- clearSelection() {
528
- if (this.isMultiSelect) {
529
- this.selectedOptions.clear();
530
- this.element.querySelectorAll(OPTION_SELECTOR).forEach((opt) => {
531
- opt.style.display = "";
532
- });
533
- if (this.target.classList.contains("open")) {
534
- this.showElement(this.target);
535
- }
536
- }
537
- const customDisplay = this.element.querySelector(
538
- "#dropdown_trigger_custom_display"
539
- );
540
- if (customDisplay) {
541
- customDisplay.style.display = "none";
542
- }
543
- this.resetDropdownValue();
544
- this.updatePills();
545
- this.updateClearButton();
546
- this.syncHiddenInputs();
547
- this.emitSelectionChange();
548
- }
549
-
550
- syncHiddenInputs() {
551
- if (!this.isMultiSelect) return;
552
- this.element
553
- .querySelectorAll('input[data-generated="true"]')
554
- .forEach((n) => n.remove());
555
-
556
- const baseInput = this.element.querySelector(DROPDOWN_INPUT);
557
- if (!baseInput) return;
558
- // for multi_select, for each selectedOption, create a hidden input
559
- const name = baseInput.getAttribute("name");
560
- this.selectedOptions.forEach((raw) => {
561
- const id = JSON.parse(raw).id;
562
- const inp = document.createElement("input");
563
- inp.type = "hidden";
564
- inp.name = name;
565
- inp.value = id;
566
- inp.dataset.generated = "true";
567
- baseInput.insertAdjacentElement("afterend", inp);
568
- });
569
- baseInput.value = "";
570
- }
571
-
572
- handleBackspaceClear() {
573
- if (!this.isMultiSelect) {
574
- this.element.querySelectorAll(OPTION_SELECTOR).forEach((opt) => {
575
- opt.classList.remove("pb_dropdown_option_selected");
576
- opt.style.display = "";
577
- this.adjustDropdownHeight();
578
- });
579
-
580
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
581
- if (hiddenInput) hiddenInput.value = "";
582
-
583
- const placeholder = this.element.querySelector(DROPDOWN_PLACEHOLDER);
584
- if (placeholder)
585
- this.setTriggerElementText(placeholder.dataset.dropdownPlaceholder);
586
- }
587
- if (this.isMultiSelect) {
588
- this.element.querySelectorAll(OPTION_SELECTOR).forEach((opt) => {
589
- const optValue = opt.dataset.dropdownOptionLabel;
590
- if (
591
- this.selectedOptions.size > 0 &&
592
- this.selectedOptions.has(optValue)
593
- ) {
594
- opt.style.display = "none";
595
- } else {
596
- opt.style.display = "";
597
- }
598
- this.adjustDropdownHeight();
599
- });
600
- }
601
- }
602
309
  }
@@ -27,13 +27,6 @@ export class PbDropdownKeyboard {
27
27
  }
28
28
  }
29
29
 
30
- getVisibleOptions() {
31
- // We only want to return the options that are visible
32
- return Array.from(
33
- this.dropdownElement.querySelectorAll(OPTION_SELECTOR)
34
- ).filter((opt) => opt.style.display !== "none");
35
- }
36
-
37
30
  openDropdownIfClosed() {
38
31
  if (!this.dropdown.target.classList.contains("open")) {
39
32
  this.dropdown.showElement(this.dropdown.target);
@@ -78,7 +71,7 @@ export class PbDropdownKeyboard {
78
71
  if (this.searchInput) {
79
72
  setTimeout(() => {
80
73
  if (this.searchInput.value.trim() === "") {
81
- this.dropdown.handleBackspaceClear();
74
+ this.dropdown.resetDropdownValue();
82
75
  }
83
76
  }, 0);
84
77
  }
@@ -88,43 +81,23 @@ export class PbDropdownKeyboard {
88
81
  }
89
82
  }
90
83
 
91
- moveFocus(direction) {
92
- const allOptions = Array.from(
93
- this.dropdownElement.querySelectorAll(OPTION_SELECTOR)
94
- );
95
- const visible = this.getVisibleOptions();
96
- if (!visible.length) return;
97
-
84
+ moveFocus(direction) {
98
85
  if (this.focusedOptionIndex !== -1) {
99
- allOptions[this.focusedOptionIndex].classList.remove(
86
+ this.options[this.focusedOptionIndex].classList.remove(
100
87
  "pb_dropdown_option_focused"
101
88
  );
102
89
  }
103
-
104
- const prevVisibleIndex =
105
- this.focusedOptionIndex === -1
106
- ? -1
107
- : visible.indexOf(allOptions[this.focusedOptionIndex]);
108
-
109
- const nextVisibleIndex =
110
- (prevVisibleIndex + direction + visible.length) % visible.length;
111
-
112
- const nextEl = visible[nextVisibleIndex];
113
- nextEl.classList.add("pb_dropdown_option_focused");
114
-
115
- this.focusedOptionIndex = allOptions.indexOf(nextEl);
90
+ this.focusedOptionIndex =
91
+ (this.focusedOptionIndex + direction + this.options.length) %
92
+ this.options.length;
93
+ this.options[this.focusedOptionIndex].classList.add(
94
+ "pb_dropdown_option_focused"
95
+ );
116
96
  }
117
97
 
118
-
119
98
  selectOption() {
120
- const allOptions = Array.from(
121
- this.dropdownElement.querySelectorAll(OPTION_SELECTOR)
122
- );
123
- if (this.focusedOptionIndex < 0) return;
124
-
125
- const optionEl = allOptions[this.focusedOptionIndex];
126
- this.dropdown.handleOptionClick({ target: optionEl });
127
- this.dropdown.toggleElement(this.dropdown.target);
128
- this.dropdown.updateClearButton();
99
+ const option = this.options[this.focusedOptionIndex];
100
+ this.dropdown.onOptionSelected(option.dataset.dropdownOptionLabel, option);
101
+ this.dropdown.hideElement(this.dropdown.target);
129
102
  }
130
103
  }
@@ -45,31 +45,27 @@ const DropdownOption = (props: DropdownOptionProps) => {
45
45
  filterItem,
46
46
  focusedOptionIndex,
47
47
  handleOptionClick,
48
- multiSelect,
49
48
  selected,
50
49
  } = useContext(DropdownContext);
51
50
 
52
- const isItemMatchingFilter = (option: GenericObject | undefined) => {
53
- const label = typeof option?.label === 'string' ? option.label.toLowerCase() : option?.label;
51
+ const isItemMatchingFilter = (option: GenericObject) => {
52
+ const label = typeof option.label === 'string' ? option.label.toLowerCase() : option.label;
54
53
  return String(label).toLowerCase().includes(filterItem.toLowerCase());
55
54
  }
56
55
 
57
- // When multiSelect, then if an option is selected, remove from dropdown
58
- const isSelected = Array.isArray(selected)
59
- ? selected.some((item) => item.label === option?.label)
60
- : (selected as GenericObject)?.label === option?.label;
61
-
62
-
63
- if (!isItemMatchingFilter(option) || (multiSelect && isSelected)) {
56
+ if (!isItemMatchingFilter(option)) {
64
57
  return null;
65
58
  }
66
59
  const isFocused =
67
60
  focusedOptionIndex >= 0 &&
68
- filteredOptions[focusedOptionIndex].label === option?.label;
61
+ filteredOptions[focusedOptionIndex].label === option.label;
69
62
  const focusedClass = isFocused && "focused";
70
63
 
71
- const selectedClass = isSelected ? "selected" : "list";
72
-
64
+ const selectedClass = `${
65
+ selected?.label === option.label
66
+ ? "selected"
67
+ : "list"
68
+ }`;
73
69
  const ariaProps = buildAriaProps(aria);
74
70
  const dataProps = buildDataProps(data);
75
71
  const htmlProps = buildHtmlProps(htmlOptions);
@@ -96,14 +92,14 @@ const DropdownOption = (props: DropdownOptionProps) => {
96
92
  <ListItem
97
93
  cursor="pointer"
98
94
  dark={dark}
99
- data-name={option?.value}
100
- key={option?.label}
95
+ data-name={option.value}
96
+ key={option.label}
101
97
  padding="none"
102
98
  >
103
99
  {children ?
104
100
  <div className="dropdown_option_wrapper">{children}</div> :
105
101
  <Body dark={dark}
106
- text={option?.label}
102
+ text={option.label}
107
103
  />
108
104
  }
109
105
  </ListItem>