playbook_ui 16.3.0.pre.alpha.play284214748 → 16.3.0.pre.alpha.play284914702

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 791fad49e5fd8c5c144cbbd18e58035c12bf1d46557e21eeacd9f26e1322c4ba
4
- data.tar.gz: b3a105c74f8dd3366d4b286bd2fb1f23212c325b738b927649ddfc492d3415e0
3
+ metadata.gz: 4fe55987631151bf94d593a4ba964107a8d9a6f574777caea1985c45774ac05f
4
+ data.tar.gz: a8f5c270468d49e1f4ab9854610069c9ece935ca9f602f8040a1cd05be38525b
5
5
  SHA512:
6
- metadata.gz: f1504b82ec481292f7636fb0e750125926f6c2bdb3041ea6dc8ac410f45b942de27222635e64ba6f62bda605de8ae5cc590e11c41935b64948ebf342ef0ee410
7
- data.tar.gz: 9e01a49770efddb8de575ed2f3924029f80e84a3b796ec5619b6353c82bdd60cd33b3183a0c7763005fca8e9bc6333625e3c95d4551ba39dd4b0419ced36cdc2
6
+ metadata.gz: 44528ff333dd050da8f582643d3ea333dba82db57b552a2cd7b8cf17f57e949a973a687a3e06dcf2d5396f931b7af0fac956ca69ba8d0c679e1b7a271cbb7b11
7
+ data.tar.gz: bdba8e6587e6b7d960165cda7fb92bb6178e8e11aaf2e97e604451338d50f744b8429831a4c7189c6933a69924ae4e18baf1a86ce69007f75401dc2906a02de0
@@ -1,5 +1,6 @@
1
1
  import PbEnhancedElement from "../pb_enhanced_element";
2
2
  import { updateSelectionActionBar } from "./advanced_table_action_bar";
3
+ import { setArrowVisibility, toggleVisibility } from "../utilities/domHelpers";
3
4
 
4
5
  const ADVANCED_TABLE_SELECTOR = "[data-advanced-table]";
5
6
  const DOWN_ARROW_SELECTOR = "#advanced-table_open_icon";
@@ -20,10 +21,18 @@ export default class PbAdvancedTable extends PbEnhancedElement {
20
21
  this.childRowsMap = new Map();
21
22
  }
22
23
 
24
+ get table() {
25
+ return this.cachedTable || (this.cachedTable = this.element.closest("table"));
26
+ }
27
+
28
+ get mainTable() {
29
+ return this.cachedMainTable || (this.cachedMainTable = this.element.closest(".pb_advanced_table"));
30
+ }
31
+
23
32
  // Fetch and cache child rows for a given parent row ID
24
33
  childRowsFor(parentId) {
25
34
  if (!this.childRowsMap.has(parentId)) {
26
- const table = this.element.closest("table");
35
+ const table = this.table;
27
36
  const rows = Array.from(
28
37
  table.querySelectorAll(`tr[data-row-parent="${parentId}"]`)
29
38
  );
@@ -33,7 +42,8 @@ export default class PbAdvancedTable extends PbEnhancedElement {
33
42
  }
34
43
 
35
44
  updateTableSelectedRowsAttribute() {
36
- const mainTable = this.element.closest(".pb_advanced_table");
45
+ const mainTable = this.mainTable;
46
+ if (!mainTable) return;
37
47
  mainTable.dataset.selectedRows = JSON.stringify(
38
48
  Array.from(PbAdvancedTable.selectedRows)
39
49
  );
@@ -41,7 +51,8 @@ export default class PbAdvancedTable extends PbEnhancedElement {
41
51
 
42
52
  // Recalculate selected count based on all checked checkboxes
43
53
  recalculateSelectedCount() {
44
- const table = this.element.closest("table");
54
+ const table = this.table;
55
+ if (!table) return;
45
56
 
46
57
  // Get all checkboxes that could be part of the selection
47
58
  // This includes row checkboxes and any parent checkboxes that might be programmatically checked
@@ -95,7 +106,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
95
106
  });
96
107
 
97
108
  this.updateTableSelectedRowsAttribute();
98
- updateSelectionActionBar(table.closest(".pb_advanced_table"), PbAdvancedTable.selectedRows.size);
109
+ updateSelectionActionBar(this.mainTable, PbAdvancedTable.selectedRows.size);
99
110
 
100
111
  // Sync header select-all state
101
112
  if (selectAllCheckbox) {
@@ -139,7 +150,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
139
150
 
140
151
  this.updateTableSelectedRowsAttribute();
141
152
 
142
- const table = checkbox.closest("table");
153
+ const table = this.table;
143
154
  const selectAllCheckbox = table.querySelector("#select-all-rows");
144
155
 
145
156
  if (selectAllCheckbox) {
@@ -153,7 +164,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
153
164
  );
154
165
  selectAllInput.checked = allChecked;
155
166
  }
156
- updateSelectionActionBar(table.closest(".pb_advanced_table"), PbAdvancedTable.selectedRows.size);
167
+ updateSelectionActionBar(this.mainTable, PbAdvancedTable.selectedRows.size);
157
168
  }
158
169
 
159
170
  get target() {
@@ -161,10 +172,11 @@ export default class PbAdvancedTable extends PbEnhancedElement {
161
172
  }
162
173
 
163
174
  connect() {
164
- const table = this.element.closest("table");
175
+ const table = this.table;
176
+ if (!table) return;
165
177
 
166
178
  this.hideCloseIcon();
167
- const mainTable = this.element.closest(".pb_advanced_table");
179
+ const mainTable = this.mainTable;
168
180
 
169
181
  // This so it is hidden on first render
170
182
  if (mainTable) {
@@ -271,9 +283,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
271
283
  }
272
284
 
273
285
  // Find direct child rows
274
- const childRows = Array.from(
275
- table.querySelectorAll(`[data-row-parent="${toggleBtn.id}"]`)
276
- );
286
+ const childRows = this.childRowsFor(toggleBtn.id);
277
287
  this.toggleElement(childRows);
278
288
 
279
289
  // Restore original element context
@@ -284,7 +294,8 @@ export default class PbAdvancedTable extends PbEnhancedElement {
284
294
  }
285
295
 
286
296
  addBorderRadiusOnLastVisibleRow() {
287
- const parentElement = this.element.closest(".pb_advanced_table");
297
+ const parentElement = this.mainTable;
298
+ if (!parentElement) return;
288
299
 
289
300
  const table = document.getElementById(parentElement.id);
290
301
 
@@ -316,11 +327,9 @@ export default class PbAdvancedTable extends PbEnhancedElement {
316
327
  elements.forEach((elem) => {
317
328
  elem.style.display = "table-row";
318
329
  elem.classList.add("is-visible");
319
- const childRowsAll = this.element
320
- .closest("table")
321
- .querySelectorAll(
322
- `[data-advanced-table-content^="${elem.dataset.advancedTableContent}-"]`
323
- );
330
+ const childRowsAll = this.table.querySelectorAll(
331
+ `[data-advanced-table-content^="${elem.dataset.advancedTableContent}-"]`
332
+ );
324
333
 
325
334
  childRowsAll.forEach((childRow) => {
326
335
  const dataContent = childRow.dataset.advancedTableContent;
@@ -382,8 +391,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
382
391
  const currentDepth = parseInt(elem.dataset.rowDepth);
383
392
  if (childrenArray.length > currentDepth) {
384
393
  // Find the child rows corresponding to this parent row
385
- const childRows = this.element
386
- .closest("table")
394
+ const childRows = this.table
387
395
  .querySelectorAll(
388
396
  `[data-advanced-table-content^="${elem.dataset.advancedTableContent}-"]`
389
397
  );
@@ -401,28 +409,39 @@ export default class PbAdvancedTable extends PbEnhancedElement {
401
409
 
402
410
  const isVisible = elements[0].classList.contains("is-visible");
403
411
 
404
- isVisible ? this.hideElement(elements) : this.showElement(elements);
405
- isVisible ? this.displayDownArrow() : this.displayUpArrow();
412
+ const isExpanded = toggleVisibility({
413
+ isVisible,
414
+ onHide: () => this.hideElement(elements),
415
+ onShow: () => this.showElement(elements),
416
+ });
417
+
418
+ isExpanded ? this.displayUpArrow() : this.displayDownArrow();
406
419
 
407
420
  const row = this.element.closest("tr");
408
421
  if (row) {
409
- row.classList.toggle("bg-silver", !isVisible);
410
- row.classList.toggle("pb-bg-row-white", isVisible);
422
+ row.classList.toggle("bg-silver", isExpanded);
423
+ row.classList.toggle("pb-bg-row-white", !isExpanded);
411
424
  }
412
425
 
413
426
  this.addBorderRadiusOnLastVisibleRow();
414
427
  }
415
428
 
416
429
  displayDownArrow() {
417
- this.element.querySelector(DOWN_ARROW_SELECTOR).style.display =
418
- "inline-block";
419
- this.element.querySelector(UP_ARROW_SELECTOR).style.display = "none";
430
+ setArrowVisibility({
431
+ rootElement: this.element,
432
+ downSelector: DOWN_ARROW_SELECTOR,
433
+ upSelector: UP_ARROW_SELECTOR,
434
+ showDownArrow: true,
435
+ });
420
436
  }
421
437
 
422
438
  displayUpArrow() {
423
- this.element.querySelector(UP_ARROW_SELECTOR).style.display =
424
- "inline-block";
425
- this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = "none";
439
+ setArrowVisibility({
440
+ rootElement: this.element,
441
+ downSelector: DOWN_ARROW_SELECTOR,
442
+ upSelector: UP_ARROW_SELECTOR,
443
+ showDownArrow: false,
444
+ });
426
445
  }
427
446
 
428
447
  static handleToggleAllHeaders(element) {
@@ -1,4 +1,5 @@
1
1
  import PbEnhancedElement from '../pb_enhanced_element'
2
+ import { getElementHeight, setArrowVisibility, toggleVisibility } from '../utilities/domHelpers'
2
3
 
3
4
  const MAIN_SELECTOR = '[data-collapsible-main]'
4
5
  const CONTENT_SELECTOR = '[data-collapsible-content]'
@@ -43,15 +44,7 @@ export default class PbCollapsible extends PbEnhancedElement {
43
44
  }
44
45
 
45
46
  showElement(elem) {
46
- // Get the natural height of the element
47
- const getHeight = () => {
48
- elem.style.display = 'block'
49
- const height = elem.scrollHeight + 'px' // Get it's height
50
- elem.style.display = '' // Hide it again
51
- return height
52
- }
53
-
54
- const height = getHeight()
47
+ const height = getElementHeight(elem)
55
48
  elem.classList.add('is-visible')
56
49
  elem.style.height = height // Update the max-height
57
50
  elem.style.overflow = "hidden"
@@ -82,26 +75,22 @@ export default class PbCollapsible extends PbEnhancedElement {
82
75
  }
83
76
 
84
77
  toggleElement(elem) {
85
- if (elem.classList.contains('is-visible')) {
86
- this.hideElement(elem)
87
- this.displayDownArrow()
88
- return
89
- }
90
- // Otherwise, show it
91
- this.showElement(elem)
92
- this.displayUpArrow()
78
+ const isExpanded = toggleVisibility({
79
+ isVisible: elem.classList.contains('is-visible'),
80
+ onHide: () => this.hideElement(elem),
81
+ onShow: () => this.showElement(elem),
82
+ })
83
+
84
+ isExpanded ? this.displayUpArrow() : this.displayDownArrow()
93
85
  }
94
86
 
95
87
  toggleArrows(showDownArrow) {
96
- const downArrow = this.element.querySelector(DOWN_ARROW_SELECTOR);
97
- const upArrow = this.element.querySelector(UP_ARROW_SELECTOR);
98
-
99
- if (downArrow) {
100
- downArrow.style.display = showDownArrow ? 'inline-block' : 'none';
101
- }
102
- if (upArrow) {
103
- upArrow.style.display = showDownArrow ? 'none' : 'inline-block';
104
- }
88
+ setArrowVisibility({
89
+ rootElement: this.element,
90
+ downSelector: DOWN_ARROW_SELECTOR,
91
+ upSelector: UP_ARROW_SELECTOR,
92
+ showDownArrow,
93
+ })
105
94
  }
106
95
 
107
96
  displayDownArrow() {
@@ -1,5 +1,6 @@
1
1
  import PbEnhancedElement from "../pb_enhanced_element";
2
2
  import { PbDropdownKeyboard } from "./keyboard_accessibility";
3
+ import { setArrowVisibility, toggleVisibility } from "../utilities/domHelpers";
3
4
 
4
5
  const DROPDOWN_SELECTOR = "[data-pb-dropdown]";
5
6
  const TRIGGER_SELECTOR = "[data-dropdown-trigger]";
@@ -23,7 +24,38 @@ export default class PbDropdown extends PbEnhancedElement {
23
24
  }
24
25
 
25
26
  get target() {
26
- return this.element.querySelector(CONTAINER_SELECTOR);
27
+ return this.cachedElements?.target || this.element.querySelector(CONTAINER_SELECTOR);
28
+ }
29
+
30
+ get baseInput() {
31
+ return this.cachedElements?.baseInput || this.element.querySelector(DROPDOWN_INPUT);
32
+ }
33
+
34
+ get trigger() {
35
+ return this.cachedElements?.trigger || this.element.querySelector(TRIGGER_SELECTOR);
36
+ }
37
+
38
+ get customTrigger() {
39
+ return this.cachedElements?.customTrigger || this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
40
+ }
41
+
42
+ get dropdownWrapper() {
43
+ return this.cachedElements?.dropdownWrapper || this.element.querySelector(".dropdown_wrapper");
44
+ }
45
+
46
+ get placeholder() {
47
+ return this.cachedElements?.placeholder || this.element.querySelector(DROPDOWN_PLACEHOLDER);
48
+ }
49
+
50
+ cacheElements() {
51
+ this.cachedElements = {
52
+ target: this.element.querySelector(CONTAINER_SELECTOR),
53
+ baseInput: this.element.querySelector(DROPDOWN_INPUT),
54
+ trigger: this.element.querySelector(TRIGGER_SELECTOR),
55
+ customTrigger: this.element.querySelector(CUSTOM_DISPLAY_SELECTOR),
56
+ dropdownWrapper: this.element.querySelector(".dropdown_wrapper"),
57
+ placeholder: this.element.querySelector(DROPDOWN_PLACEHOLDER),
58
+ };
27
59
  }
28
60
 
29
61
  selectedOptions = new Set();
@@ -32,13 +64,14 @@ export default class PbDropdown extends PbEnhancedElement {
32
64
  connect() {
33
65
  // Store instance on element for DatePicker sync
34
66
  this.element._pbDropdownInstance = this;
67
+ this.cacheElements();
35
68
 
36
69
  this.keyboardHandler = new PbDropdownKeyboard(this);
37
70
  this.isMultiSelect = this.element.dataset.pbDropdownMultiSelect === "true";
38
71
  this.formPillProps = this.element.dataset.formPillProps
39
72
  ? JSON.parse(this.element.dataset.formPillProps)
40
73
  : {};
41
- const baseInput = this.element.querySelector(DROPDOWN_INPUT);
74
+ const baseInput = this.baseInput;
42
75
  this.wasOriginallyRequired =
43
76
  baseInput && baseInput.hasAttribute("required");
44
77
  this.setDefaultValue();
@@ -76,7 +109,7 @@ export default class PbDropdown extends PbEnhancedElement {
76
109
 
77
110
  // Clean up custom trigger click listener
78
111
  if (this.customTriggerClickHandler) {
79
- const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR) || this.element
112
+ const customTrigger = this.customTrigger || this.element
80
113
  customTrigger.removeEventListener('click', this.customTriggerClickHandler)
81
114
  }
82
115
 
@@ -98,7 +131,7 @@ export default class PbDropdown extends PbEnhancedElement {
98
131
  // Clean up search input listeners
99
132
  if (this.searchInput) {
100
133
  if (this.searchInputFocusHandler) {
101
- const trigger = this.element.querySelector(TRIGGER_SELECTOR)
134
+ const trigger = this.trigger
102
135
  if (trigger) {
103
136
  trigger.removeEventListener('click', this.searchInputFocusHandler)
104
137
  }
@@ -122,14 +155,13 @@ export default class PbDropdown extends PbEnhancedElement {
122
155
  }
123
156
  const hasSelection = this.isMultiSelect
124
157
  ? this.selectedOptions.size > 0
125
- : Boolean(this.element.querySelector(DROPDOWN_INPUT).value);
158
+ : Boolean(this.baseInput?.value);
126
159
 
127
160
  this.clearBtn.style.display = hasSelection ? "" : "none";
128
161
  }
129
162
 
130
163
  bindEventListeners() {
131
- const customTrigger =
132
- this.element.querySelector(CUSTOM_DISPLAY_SELECTOR) || this.element;
164
+ const customTrigger = this.customTrigger || this.element;
133
165
  this.customTriggerClickHandler = (e) => {
134
166
  const label = e.target.closest(LABEL_SELECTOR);
135
167
  if (label && label.htmlFor) {
@@ -169,9 +201,7 @@ export default class PbDropdown extends PbEnhancedElement {
169
201
 
170
202
  // Focus the input when anyone clicks the wrapper
171
203
  this.searchInputFocusHandler = () => this.searchInput.focus()
172
- this.element
173
- .querySelector(TRIGGER_SELECTOR)
174
- ?.addEventListener('click', this.searchInputFocusHandler);
204
+ this.trigger?.addEventListener('click', this.searchInputFocusHandler);
175
205
 
176
206
  // Live filter
177
207
  this.searchInputHandler = (e) => this.handleSearch(e.target.value)
@@ -203,7 +233,7 @@ export default class PbDropdown extends PbEnhancedElement {
203
233
  adjustDropdownPosition(container) {
204
234
  if (!container) return;
205
235
 
206
- const wrapper = this.element.querySelector(".dropdown_wrapper");
236
+ const wrapper = this.dropdownWrapper;
207
237
  if (!wrapper) return;
208
238
 
209
239
  const wrapperRect = wrapper.getBoundingClientRect();
@@ -276,7 +306,7 @@ export default class PbDropdown extends PbEnhancedElement {
276
306
 
277
307
  handleOptionClick(event) {
278
308
  const option = event.target.closest(OPTION_SELECTOR);
279
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
309
+ const hiddenInput = this.baseInput;
280
310
 
281
311
  if (option) {
282
312
  const value = option.dataset.dropdownOptionLabel;
@@ -314,11 +344,11 @@ export default class PbDropdown extends PbEnhancedElement {
314
344
  isClickOutside(event) {
315
345
  const label = event.target.closest(LABEL_SELECTOR);
316
346
  if (label && this.element.contains(label)) return false;
317
- const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
347
+ const customTrigger = this.customTrigger;
318
348
  if (customTrigger) {
319
349
  return !customTrigger.contains(event.target);
320
350
  } else {
321
- const triggerElement = this.element.querySelector(TRIGGER_SELECTOR);
351
+ const triggerElement = this.trigger;
322
352
  const containerElement =
323
353
  this.element.parentNode.querySelector(CONTAINER_SELECTOR);
324
354
 
@@ -339,7 +369,7 @@ export default class PbDropdown extends PbEnhancedElement {
339
369
  if (this.isMultiSelect) {
340
370
  detail = Array.from(this.selectedOptions).map(JSON.parse);
341
371
  } else {
342
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
372
+ const hiddenInput = this.baseInput;
343
373
  detail = hiddenInput.value
344
374
  ? JSON.parse(
345
375
  this.element.querySelector(
@@ -458,7 +488,7 @@ export default class PbDropdown extends PbEnhancedElement {
458
488
  this.emitSelectionChange();
459
489
  }
460
490
 
461
- const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
491
+ const customTrigger = this.customTrigger;
462
492
  if (customTrigger) {
463
493
  if (this.target.classList.contains("open")) {
464
494
  this.hideElement(this.target);
@@ -478,7 +508,7 @@ export default class PbDropdown extends PbEnhancedElement {
478
508
  this.adjustDropdownHeight();
479
509
  }
480
510
  });
481
- this.element.querySelector(DROPDOWN_INPUT).value = Array.from(
511
+ this.baseInput.value = Array.from(
482
512
  this.selectedOptions,
483
513
  )
484
514
  .map((opt) => JSON.parse(opt).id)
@@ -532,26 +562,26 @@ export default class PbDropdown extends PbEnhancedElement {
532
562
  }
533
563
 
534
564
  toggleElement(elem) {
535
- if (elem.classList.contains("open")) {
536
- this.hideElement(elem);
537
- this.updateArrowDisplay(false);
538
- return;
539
- }
540
- this.showElement(elem);
541
- this.updateArrowDisplay(true);
565
+ const isOpen = toggleVisibility({
566
+ isVisible: elem.classList.contains("open"),
567
+ onHide: () => this.hideElement(elem),
568
+ onShow: () => this.showElement(elem),
569
+ });
570
+
571
+ this.updateArrowDisplay(isOpen);
542
572
  }
543
573
 
544
574
  updateArrowDisplay(isOpen) {
545
- const downArrow = this.element.querySelector(DOWN_ARROW_SELECTOR);
546
- const upArrow = this.element.querySelector(UP_ARROW_SELECTOR);
547
- if (downArrow && upArrow) {
548
- downArrow.style.display = isOpen ? "none" : "inline-block";
549
- upArrow.style.display = isOpen ? "inline-block" : "none";
550
- }
575
+ setArrowVisibility({
576
+ rootElement: this.element,
577
+ downSelector: DOWN_ARROW_SELECTOR,
578
+ upSelector: UP_ARROW_SELECTOR,
579
+ showDownArrow: !isOpen,
580
+ });
551
581
  }
552
582
 
553
583
  handleFormValidation() {
554
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
584
+ const hiddenInput = this.baseInput;
555
585
 
556
586
  hiddenInput.addEventListener(
557
587
  "invalid",
@@ -594,7 +624,7 @@ export default class PbDropdown extends PbEnhancedElement {
594
624
  }
595
625
 
596
626
  setDefaultValue() {
597
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
627
+ const hiddenInput = this.baseInput;
598
628
  const optionEls = Array.from(
599
629
  this.element.querySelectorAll(OPTION_SELECTOR),
600
630
  );
@@ -707,7 +737,7 @@ export default class PbDropdown extends PbEnhancedElement {
707
737
  }
708
738
 
709
739
  resetDropdownValue() {
710
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
740
+ const hiddenInput = this.baseInput;
711
741
  const options = this.element.querySelectorAll(OPTION_SELECTOR);
712
742
  options.forEach((option) => {
713
743
  option.classList.remove("pb_dropdown_option_selected");
@@ -716,7 +746,7 @@ export default class PbDropdown extends PbEnhancedElement {
716
746
 
717
747
  hiddenInput.value = "";
718
748
 
719
- const defaultPlaceholder = this.element.querySelector(DROPDOWN_PLACEHOLDER);
749
+ const defaultPlaceholder = this.placeholder;
720
750
  this.setTriggerElementText(defaultPlaceholder.dataset.dropdownPlaceholder);
721
751
 
722
752
  if (this.searchInput) {
@@ -915,7 +945,7 @@ export default class PbDropdown extends PbEnhancedElement {
915
945
  .querySelectorAll('input[data-generated="true"]')
916
946
  .forEach((n) => n.remove());
917
947
 
918
- const baseInput = this.element.querySelector(DROPDOWN_INPUT);
948
+ const baseInput = this.baseInput;
919
949
  if (!baseInput) return;
920
950
  // for multi_select, for each selectedOption, create a hidden input
921
951
  const name = baseInput.getAttribute("name");
@@ -953,10 +983,10 @@ export default class PbDropdown extends PbEnhancedElement {
953
983
  this.adjustDropdownHeight();
954
984
  });
955
985
 
956
- const hiddenInput = this.element.querySelector(DROPDOWN_INPUT);
986
+ const hiddenInput = this.baseInput;
957
987
  if (hiddenInput) hiddenInput.value = "";
958
988
 
959
- const placeholder = this.element.querySelector(DROPDOWN_PLACEHOLDER);
989
+ const placeholder = this.placeholder;
960
990
  if (placeholder)
961
991
  this.setTriggerElementText(placeholder.dataset.dropdownPlaceholder);
962
992
  }
@@ -102,7 +102,7 @@ export const getDefaultCheckedItems = (
102
102
  } else {
103
103
  const parent = items.find(
104
104
  (parentItem: { [key: string]: any }) =>
105
- parentItem.id === item.parent_id
105
+ parentItem.id === item.parentId
106
106
  );
107
107
  if (!parent || !parent.checked) {
108
108
  checkedDefault.push(item);
@@ -179,7 +179,6 @@ const MultiLevelSelect = forwardRef<HTMLInputElement, MultiLevelSelectProps>(
179
179
  parent_id: string | null = null,
180
180
  depth = 0,
181
181
  parentDisabled = false,
182
- ancestorChecked = false
183
182
  ) => {
184
183
  if (!Array.isArray(treeData)) {
185
184
  return;
@@ -189,36 +188,28 @@ const MultiLevelSelect = forwardRef<HTMLInputElement, MultiLevelSelectProps>(
189
188
  const isDisabled =
190
189
  item.disabled || (parentDisabled && !returnAllSelected);
191
190
 
192
- const explicitlySelected = Boolean(
193
- selectedIds && selectedIds?.length && selectedIds.includes(item.id)
194
- );
195
-
196
- const checked =
197
- !isDisabled &&
198
- (explicitlySelected || (ancestorChecked && !returnAllSelected && variant !== "single"))
199
-
200
191
  const newItem = {
201
192
  ...item,
202
- checked: checked,
193
+ checked: Boolean(
194
+ selectedIds && selectedIds.length && selectedIds.includes(item.id),
195
+ ),
203
196
  parent_id,
204
197
  depth,
205
198
  disabled: isDisabled,
206
199
  };
207
200
  if (newItem.children && newItem.children.length > 0) {
208
- // if this node is checked (by explicit selection or ancestor cascade),
209
- // and we're in default, cascade to descendants
210
- const cascadeToChildren =
211
- checked && !returnAllSelected && variant !== "single"
212
-
213
- newItem.children = addCheckedAndParentProperty(
214
- newItem.children,
215
- selectedIds,
216
- newItem.id,
217
- depth + 1,
218
- isDisabled,
219
- cascadeToChildren
220
- )
221
- }
201
+ const children =
202
+ item.checked && !returnAllSelected
203
+ ? modifyRecursive(item.children, true)
204
+ : item.children;
205
+ newItem.children = addCheckedAndParentProperty(
206
+ children,
207
+ selectedIds,
208
+ newItem.id,
209
+ depth + 1,
210
+ isDisabled,
211
+ );
212
+ }
222
213
  return newItem;
223
214
  });
224
215
  };
@@ -0,0 +1,50 @@
1
+ type ToggleVisibilityOptions = {
2
+ isVisible: boolean,
3
+ onHide: () => void,
4
+ onShow: () => void,
5
+ }
6
+
7
+ type ArrowVisibilityOptions = {
8
+ rootElement: ParentNode,
9
+ downSelector: string,
10
+ upSelector: string,
11
+ showDownArrow: boolean,
12
+ displayValue?: string,
13
+ }
14
+
15
+ export const toggleVisibility = ({ isVisible, onHide, onShow }: ToggleVisibilityOptions): boolean => {
16
+ if (isVisible) {
17
+ onHide()
18
+ return false
19
+ }
20
+
21
+ onShow()
22
+ return true
23
+ }
24
+
25
+ export const getElementHeight = (element: HTMLElement, displayValue = 'block'): string => {
26
+ const originalDisplay = element.style.display
27
+ element.style.display = displayValue
28
+ const height = `${element.scrollHeight}px`
29
+ element.style.display = originalDisplay
30
+ return height
31
+ }
32
+
33
+ export const setArrowVisibility = ({
34
+ rootElement,
35
+ downSelector,
36
+ upSelector,
37
+ showDownArrow,
38
+ displayValue = 'inline-block',
39
+ }: ArrowVisibilityOptions): void => {
40
+ const downArrow = rootElement.querySelector<HTMLElement>(downSelector)
41
+ const upArrow = rootElement.querySelector<HTMLElement>(upSelector)
42
+
43
+ if (downArrow) {
44
+ downArrow.style.display = showDownArrow ? displayValue : 'none'
45
+ }
46
+
47
+ if (upArrow) {
48
+ upArrow.style.display = showDownArrow ? 'none' : displayValue
49
+ }
50
+ }