basecoat-css 1.0.0-beta.4 → 1.0.0-beta.6

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 (53) hide show
  1. package/dist/base/base.css +1 -1
  2. package/dist/basecoat-base.cdn.css +275 -27
  3. package/dist/basecoat-base.cdn.min.css +1 -1
  4. package/dist/basecoat-components.css +2 -0
  5. package/dist/basecoat-luma.cdn.css +494 -56
  6. package/dist/basecoat-luma.cdn.min.css +1 -1
  7. package/dist/basecoat-lyra.cdn.css +491 -53
  8. package/dist/basecoat-lyra.cdn.min.css +1 -1
  9. package/dist/basecoat-maia.cdn.css +483 -56
  10. package/dist/basecoat-maia.cdn.min.css +1 -1
  11. package/dist/basecoat-mira.cdn.css +480 -56
  12. package/dist/basecoat-mira.cdn.min.css +1 -1
  13. package/dist/basecoat-nova.cdn.css +499 -56
  14. package/dist/basecoat-nova.cdn.min.css +1 -1
  15. package/dist/basecoat-rhea.cdn.css +504 -67
  16. package/dist/basecoat-rhea.cdn.min.css +1 -1
  17. package/dist/basecoat-sera.cdn.css +484 -54
  18. package/dist/basecoat-sera.cdn.min.css +1 -1
  19. package/dist/basecoat-vega.cdn.css +488 -55
  20. package/dist/basecoat-vega.cdn.min.css +1 -1
  21. package/dist/basecoat.cdn.css +488 -55
  22. package/dist/basecoat.cdn.min.css +1 -1
  23. package/dist/components/accordion.css +27 -0
  24. package/dist/components/alert.css +12 -0
  25. package/dist/components/avatar.css +6 -6
  26. package/dist/components/breadcrumb.css +30 -0
  27. package/dist/components/card.css +4 -0
  28. package/dist/components/combobox.css +23 -2
  29. package/dist/components/command.css +19 -12
  30. package/dist/components/dialog.css +30 -1
  31. package/dist/components/dropdown-menu.css +1 -1
  32. package/dist/components/popover.css +27 -1
  33. package/dist/js/accordion.js +68 -0
  34. package/dist/js/accordion.min.js +1 -0
  35. package/dist/js/all.js +245 -41
  36. package/dist/js/all.min.js +1 -1
  37. package/dist/js/combobox.js +115 -26
  38. package/dist/js/combobox.min.js +1 -1
  39. package/dist/js/command.js +3 -1
  40. package/dist/js/command.min.js +1 -1
  41. package/dist/js/dropdown-menu.js +12 -1
  42. package/dist/js/dropdown-menu.min.js +1 -1
  43. package/dist/js/select.js +46 -13
  44. package/dist/js/select.min.js +1 -1
  45. package/dist/styles/luma.css +105 -15
  46. package/dist/styles/lyra.css +96 -14
  47. package/dist/styles/maia.css +105 -15
  48. package/dist/styles/mira.css +105 -15
  49. package/dist/styles/nova.css +103 -17
  50. package/dist/styles/rhea.css +109 -19
  51. package/dist/styles/sera.css +100 -14
  52. package/dist/styles/vega.css +102 -16
  53. package/package.json +1 -1
package/dist/js/all.js CHANGED
@@ -154,11 +154,82 @@
154
154
  });
155
155
  })();
156
156
 
157
+ (() => {
158
+ const states = new WeakMap();
159
+
160
+ const isDisabled = (details) => {
161
+ const summary = details.querySelector(':scope > summary');
162
+ return details.getAttribute('aria-disabled') === 'true'
163
+ || details.dataset.disabled === 'true'
164
+ || summary?.getAttribute('aria-disabled') === 'true';
165
+ };
166
+
167
+ const isMultiple = (root) => root.hasAttribute('data-multiple');
168
+
169
+ const closeSiblings = (root, activeDetails) => {
170
+ if (isMultiple(root) || !activeDetails.open) return;
171
+ root.querySelectorAll(':scope > details[open]').forEach((details) => {
172
+ if (details !== activeDetails) details.open = false;
173
+ });
174
+ };
175
+
176
+ const initAccordion = (root) => {
177
+ if (root.dataset.accordionInitialized) return;
178
+
179
+ const handleClick = (event) => {
180
+ const summary = event.target.closest('summary');
181
+ const details = summary?.closest('details');
182
+ if (!details || details.parentElement !== root || !isDisabled(details)) return;
183
+ event.preventDefault();
184
+ };
185
+
186
+ const handleKeydown = (event) => {
187
+ if (event.key !== 'Enter' && event.key !== ' ') return;
188
+ const summary = event.target.closest('summary');
189
+ const details = summary?.closest('details');
190
+ if (!details || details.parentElement !== root || !isDisabled(details)) return;
191
+ event.preventDefault();
192
+ };
193
+
194
+ const handleToggle = (event) => {
195
+ const details = event.target;
196
+ if (details.parentElement !== root) return;
197
+ if (isDisabled(details)) {
198
+ details.open = false;
199
+ return;
200
+ }
201
+ closeSiblings(root, details);
202
+ };
203
+
204
+ root.addEventListener('click', handleClick);
205
+ root.addEventListener('keydown', handleKeydown);
206
+ root.addEventListener('toggle', handleToggle, true);
207
+ root.querySelectorAll(':scope > details[open]').forEach((details) => closeSiblings(root, details));
208
+
209
+ states.set(root, { handleClick, handleToggle });
210
+ root._destroy = () => {
211
+ root.removeEventListener('click', handleClick);
212
+ root.removeEventListener('keydown', handleKeydown);
213
+ root.removeEventListener('toggle', handleToggle, true);
214
+ states.delete(root);
215
+ };
216
+
217
+ root.dataset.accordionInitialized = 'true';
218
+ root.dispatchEvent(new CustomEvent('basecoat:initialized'));
219
+ };
220
+
221
+ if (window.basecoat) {
222
+ window.basecoat.register('accordion', '.accordion:not([data-accordion-initialized])', initAccordion);
223
+ }
224
+ })();
225
+
157
226
  (() => {
158
227
  const states = new WeakMap();
159
228
 
160
229
  const isDisabled = (item) =>
161
- item.hasAttribute('disabled') || item.getAttribute('aria-disabled') === 'true';
230
+ item.hasAttribute('disabled') ||
231
+ item.getAttribute('aria-disabled') === 'true' ||
232
+ item.getAttribute('data-disabled') === 'true';
162
233
 
163
234
  const getElements = (container) => ({
164
235
  input: container.querySelector('header input'),
@@ -358,12 +429,29 @@
358
429
  const states = new WeakMap();
359
430
 
360
431
  const getElements = (root) => {
361
- const input = root.querySelector(':scope > input[role="combobox"], :scope > .combobox-chips input[role="combobox"]');
362
- const chips = root.querySelector(':scope > .combobox-chips');
363
432
  const popover = root.querySelector(':scope > [data-popover]');
433
+ const input = root.querySelector(':scope > input[role="combobox"], :scope > .input-group input[role="combobox"], :scope > .combobox-chips input[role="combobox"]')
434
+ || popover?.querySelector('input[role="combobox"]');
435
+ const chips = root.querySelector(':scope > .combobox-chips');
436
+ const popupTrigger = root.querySelector(':scope > button[aria-haspopup="listbox"]');
437
+ const trigger = popupTrigger || root.querySelector(':scope > .input-group button[aria-haspopup="listbox"]');
438
+ const clearButton = root.querySelector('[data-clear]');
439
+ const valueTarget = popupTrigger?.querySelector('[data-value]') || (popupTrigger?.matches('[data-value]') ? popupTrigger : null);
364
440
  const listbox = popover ? popover.querySelector('[role="listbox"]') : null;
365
441
  const hiddenInput = root.querySelector(':scope > input[type="hidden"]');
366
- return { input, chips, popover, listbox, hiddenInput };
442
+ return { input, chips, trigger, clearButton, valueTarget, popover, listbox, hiddenInput };
443
+ };
444
+
445
+ const ensureMultipleInputSurface = (root, elements) => {
446
+ if (elements.listbox?.getAttribute('aria-multiselectable') !== 'true' || elements.chips || !elements.input) return elements;
447
+ if (elements.input.parentElement !== root) return elements;
448
+
449
+ const chips = document.createElement('div');
450
+ chips.className = 'combobox-chips';
451
+ root.insertBefore(chips, elements.input);
452
+ chips.appendChild(elements.input);
453
+
454
+ return getElements(root);
367
455
  };
368
456
 
369
457
  const getValue = option => option.dataset.value ?? option.textContent.trim();
@@ -467,7 +555,7 @@
467
555
  state.popover.dataset.empty = String(state.visibleOptions.length === 0);
468
556
  };
469
557
 
470
- const filterOptions = (state, { preserveActive = false } = {}) => {
558
+ const filterOptions = (state, { preserveActive = false, search: forcedSearch } = {}) => {
471
559
  const previousActive = state.activeIndex > -1 ? state.options[state.activeIndex] : null;
472
560
  state.visibleOptions = [];
473
561
 
@@ -483,7 +571,7 @@
483
571
  return;
484
572
  }
485
573
 
486
- const search = state.input.value.trim().toLowerCase();
574
+ const search = (forcedSearch ?? state.input.value).trim().toLowerCase();
487
575
 
488
576
  state.allOptions.forEach(option => {
489
577
  if (option.hasAttribute('data-force')) {
@@ -517,20 +605,42 @@
517
605
  const chip = document.createElement('span');
518
606
  chip.className = 'combobox-chip';
519
607
  chip.dataset.value = entry.value;
520
- chip.textContent = entry.label;
608
+
609
+ const label = document.createElement('span');
610
+ label.textContent = entry.label;
521
611
 
522
612
  const remove = document.createElement('button');
523
613
  remove.type = 'button';
524
- remove.className = 'combobox-chip-remove';
614
+ remove.className = 'combobox-chip-remove btn';
615
+ remove.dataset.variant = 'ghost';
616
+ remove.dataset.size = 'icon-xs';
525
617
  remove.setAttribute('aria-label', `Remove ${entry.label}`);
526
618
  remove.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>';
527
- remove.addEventListener('click', () => root.deselect(entry.value));
619
+ remove.addEventListener('click', (event) => {
620
+ event.stopPropagation();
621
+ root.deselect(entry.value);
622
+ state.input.focus();
623
+ });
528
624
 
625
+ chip.appendChild(label);
529
626
  chip.appendChild(remove);
530
627
  state.chips.insertBefore(chip, state.input);
531
628
  });
532
629
  };
533
630
 
631
+ const syncTriggerValue = (state) => {
632
+ if (!state.valueTarget) return;
633
+ const selected = getSelection(state);
634
+ state.valueTarget.textContent = state.isMultiple
635
+ ? selected.map(entry => entry.label).join(', ')
636
+ : (selected[0]?.label || state.valueTarget.dataset.placeholder || '');
637
+ };
638
+
639
+ const syncClearButton = (state) => {
640
+ if (!state.clearButton) return;
641
+ state.clearButton.hidden = getSelection(state).length === 0 && state.input.value === '';
642
+ };
643
+
534
644
  const syncSelectedOptions = (state) => {
535
645
  state.options.forEach(option => {
536
646
  if (state.selected.has(getValue(option))) {
@@ -551,7 +661,7 @@
551
661
  state.input.value = '';
552
662
  } else if (normalized[0]) {
553
663
  state.selected.set(normalized[0].value, normalized[0]);
554
- state.input.value = normalized[0].label;
664
+ state.input.value = state.valueTarget ? '' : normalized[0].label;
555
665
  } else {
556
666
  state.input.value = '';
557
667
  }
@@ -562,6 +672,8 @@
562
672
  renderChips(root);
563
673
  filterOptions(state, { preserveActive: true });
564
674
  }
675
+ syncTriggerValue(state);
676
+ syncClearButton(state);
565
677
 
566
678
  if (triggerEvent) {
567
679
  root.dispatchEvent(new CustomEvent('change', {
@@ -575,15 +687,35 @@
575
687
  if (state.popover.getAttribute('aria-hidden') === 'true') return;
576
688
  state.popover.setAttribute('aria-hidden', 'true');
577
689
  state.input.setAttribute('aria-expanded', 'false');
690
+ state.trigger?.setAttribute('aria-expanded', 'false');
578
691
  setActiveOption(state, -1);
579
- if (focusInput) state.input.focus();
692
+ if (focusInput) {
693
+ state.skipOpenOnFocus = true;
694
+ state.input.focus();
695
+ requestAnimationFrame(() => { state.skipOpenOnFocus = false; });
696
+ }
697
+ };
698
+
699
+ const openPopover = (state) => {
700
+ const { root } = state;
701
+ if (state.popover.getAttribute('aria-hidden') === 'false') return;
702
+ document.dispatchEvent(new CustomEvent('basecoat:popover', { detail: { source: root } }));
703
+ root.refresh();
704
+ const selected = getSelection(state)[0];
705
+ if (state.valueTarget) state.input.value = '';
706
+ const search = !state.isMultiple && selected && state.input.value === selected.label ? '' : undefined;
707
+ filterOptions(state, { search });
708
+ state.popover.setAttribute('aria-hidden', 'false');
709
+ state.input.setAttribute('aria-expanded', 'true');
710
+ state.trigger?.setAttribute('aria-expanded', 'true');
711
+ if (state.trigger) state.input.focus();
580
712
  };
581
713
 
582
714
  const refreshCombobox = (root) => {
583
715
  const state = states.get(root);
584
716
  if (!state) return;
585
717
 
586
- const elements = getElements(root);
718
+ let elements = getElements(root);
587
719
  if (!elements.input || !elements.popover || !elements.listbox || !elements.hiddenInput) {
588
720
  const missing = [];
589
721
  if (!elements.input) missing.push('input');
@@ -594,6 +726,7 @@
594
726
  return;
595
727
  }
596
728
 
729
+ elements = ensureMultipleInputSurface(root, elements);
597
730
  const previousValue = elements.hiddenInput.value;
598
731
  const previousInputValue = elements.input.value;
599
732
  Object.assign(state, elements, getOptions(elements.listbox));
@@ -620,6 +753,8 @@
620
753
  filterOptions(state, { preserveActive: true });
621
754
  }
622
755
  }
756
+ syncTriggerValue(state);
757
+ syncClearButton(state);
623
758
  };
624
759
 
625
760
  const resolveEntry = (state, value) => {
@@ -646,7 +781,8 @@
646
781
  if (state.closeOnSelect) root.close(true);
647
782
  } else {
648
783
  setSelected(root, entry);
649
- root.close(true);
784
+ root.close(state.trigger ? false : true);
785
+ state.trigger?.focus();
650
786
  }
651
787
  };
652
788
 
@@ -658,6 +794,15 @@
658
794
  setSelected(root, getSelection(state).filter(item => item.value !== normalized));
659
795
  };
660
796
 
797
+ const clearValue = (root) => {
798
+ const state = states.get(root);
799
+ setSelected(root, [], true);
800
+ state.input.value = '';
801
+ filterOptions(state);
802
+ syncClearButton(state);
803
+ if (state.popover.getAttribute('aria-hidden') === 'false') state.input.focus();
804
+ };
805
+
661
806
  const handleKeydown = (event, root) => {
662
807
  const state = states.get(root);
663
808
  if (!['ArrowDown', 'ArrowUp', 'Enter', 'Home', 'End', 'Escape', 'Backspace'].includes(event.key)) return;
@@ -678,7 +823,7 @@
678
823
 
679
824
  if (!isOpen && ['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) {
680
825
  event.preventDefault();
681
- root.open();
826
+ openPopover(state);
682
827
  }
683
828
 
684
829
  if (state.popover.getAttribute('aria-hidden') === 'true') return;
@@ -711,7 +856,7 @@
711
856
  const initCombobox = (root) => {
712
857
  if (root.dataset.comboboxInitialized) return;
713
858
 
714
- const state = { root, activeIndex: -1, allOptions: [], options: [], visibleOptions: [], selected: new Map(), format: 'value', manualFilter: false };
859
+ const state = { root, activeIndex: -1, allOptions: [], options: [], visibleOptions: [], selected: new Map(), format: 'value', manualFilter: false, skipOpenOnFocus: false };
715
860
  states.set(root, state);
716
861
  root.refresh = () => refreshCombobox(root);
717
862
 
@@ -722,14 +867,6 @@
722
867
  return;
723
868
  }
724
869
 
725
- root.open = () => {
726
- if (state.popover.getAttribute('aria-hidden') === 'false') return;
727
- document.dispatchEvent(new CustomEvent('basecoat:popover', { detail: { source: root } }));
728
- root.refresh();
729
- filterOptions(state);
730
- state.popover.setAttribute('aria-hidden', 'false');
731
- state.input.setAttribute('aria-expanded', 'true');
732
- };
733
870
  root.close = (focusInput = false) => closePopover(state, focusInput);
734
871
 
735
872
  root.select = (value) => selectValue(root, value);
@@ -750,17 +887,34 @@
750
887
  root.selectNone = () => setSelected(root, []);
751
888
  }
752
889
 
753
- const handleInputFocus = root.open;
754
- const handleInputClick = root.open;
890
+ const handleInputFocus = () => {
891
+ if (state.skipOpenOnFocus) return;
892
+ openPopover(state);
893
+ };
894
+ const handleInputClick = () => openPopover(state);
755
895
  const handleInput = () => {
756
- root.open();
896
+ openPopover(state);
757
897
  filterOptions(state);
758
898
  if (!state.isMultiple) {
759
899
  state.hiddenInput.value = '';
760
900
  state.selected.clear();
761
901
  syncSelectedOptions(state);
902
+ syncTriggerValue(state);
903
+ syncClearButton(state);
762
904
  }
763
905
  };
906
+ const handleTriggerClick = () => {
907
+ if (state.popover.getAttribute('aria-hidden') === 'false') {
908
+ root.close(false);
909
+ } else {
910
+ openPopover(state);
911
+ }
912
+ };
913
+ const handleClearClick = (event) => {
914
+ event.preventDefault();
915
+ event.stopPropagation();
916
+ clearValue(root);
917
+ };
764
918
  const handleInputKeydown = (event) => handleKeydown(event, root);
765
919
  const handleListboxMousemove = (event) => {
766
920
  const option = event.target.closest('[role="option"]');
@@ -783,6 +937,8 @@
783
937
  state.input.addEventListener('click', handleInputClick);
784
938
  state.input.addEventListener('input', handleInput);
785
939
  state.input.addEventListener('keydown', handleInputKeydown);
940
+ state.trigger?.addEventListener('click', handleTriggerClick);
941
+ state.clearButton?.addEventListener('click', handleClearClick);
786
942
  state.listbox.addEventListener('mousemove', handleListboxMousemove);
787
943
  state.listbox.addEventListener('click', handleListboxClick);
788
944
  document.addEventListener('click', handleDocumentClick);
@@ -793,6 +949,8 @@
793
949
  state.input.removeEventListener('click', handleInputClick);
794
950
  state.input.removeEventListener('input', handleInput);
795
951
  state.input.removeEventListener('keydown', handleInputKeydown);
952
+ state.trigger?.removeEventListener('click', handleTriggerClick);
953
+ state.clearButton?.removeEventListener('click', handleClearClick);
796
954
  state.listbox.removeEventListener('mousemove', handleListboxMousemove);
797
955
  state.listbox.removeEventListener('click', handleListboxClick);
798
956
  document.removeEventListener('click', handleDocumentClick);
@@ -800,11 +958,11 @@
800
958
  state.chips?.querySelectorAll('.combobox-chip').forEach(chip => chip.remove());
801
959
  states.delete(root);
802
960
  delete root.refresh;
803
- delete root.open;
804
961
  delete root.close;
805
962
  delete root.select;
806
963
  delete root.selectByValue;
807
964
  delete root.setValue;
965
+ delete root.clear;
808
966
  delete root.deselect;
809
967
  delete root.toggle;
810
968
  delete root.selectAll;
@@ -813,6 +971,8 @@
813
971
 
814
972
  state.popover.setAttribute('aria-hidden', 'true');
815
973
  state.input.setAttribute('aria-expanded', 'false');
974
+ state.trigger?.setAttribute('aria-expanded', 'false');
975
+ root.clear = () => clearValue(root);
816
976
 
817
977
  Object.defineProperty(root, 'value', {
818
978
  configurable: true,
@@ -986,7 +1146,18 @@
986
1146
  const handleMenuMouseleave = () => setActiveItem(state, -1);
987
1147
  const handleMenuClick = (event) => {
988
1148
  const menuItem = event.target.closest('[role^="menuitem"]');
989
- if (menuItem && !isDisabled(menuItem)) root.close();
1149
+ if (!menuItem || isDisabled(menuItem)) return;
1150
+
1151
+ if (menuItem.getAttribute('role') === 'menuitemcheckbox') {
1152
+ menuItem.setAttribute('aria-checked', menuItem.getAttribute('aria-checked') !== 'true');
1153
+ } else if (menuItem.getAttribute('role') === 'menuitemradio') {
1154
+ const group = menuItem.closest('[role="group"], [role="menu"]');
1155
+ group?.querySelectorAll('[role="menuitemradio"]').forEach((item) => {
1156
+ if (!isDisabled(item)) item.setAttribute('aria-checked', item === menuItem ? 'true' : 'false');
1157
+ });
1158
+ }
1159
+
1160
+ root.close();
990
1161
  };
991
1162
 
992
1163
  const handleDocumentClick = (event) => {
@@ -1210,6 +1381,12 @@
1210
1381
  return state.isMultiple ? JSON.stringify(value) : (value[0] || '');
1211
1382
  };
1212
1383
 
1384
+ const showPlaceholder = (state) => {
1385
+ state.selectedLabel.textContent = state.placeholder || '';
1386
+ state.selectedLabel.classList.toggle('text-muted-foreground', Boolean(state.placeholder));
1387
+ state.input.value = state.isMultiple ? serializeSelection(state, []) : '';
1388
+ };
1389
+
1213
1390
  const scrollOptionIntoListbox = (state, option) => {
1214
1391
  const optionRect = option.getBoundingClientRect();
1215
1392
  const listboxRect = state.listbox.getBoundingClientRect();
@@ -1265,19 +1442,26 @@
1265
1442
  state.input.value = serializeSelection(state, selectedDetail);
1266
1443
  } else {
1267
1444
  const option = optionOrOptions;
1268
- if (!option) return;
1269
- if (option.dataset.label) {
1270
- state.selectedLabel.textContent = option.dataset.label;
1445
+ if (!option) {
1446
+ state.options.forEach(option => option.removeAttribute('aria-selected'));
1447
+ showPlaceholder(state);
1448
+ selectedDetail = null;
1449
+ value = '';
1271
1450
  } else {
1272
- state.selectedLabel.innerHTML = option.innerHTML;
1451
+ if (option.dataset.label) {
1452
+ state.selectedLabel.textContent = option.dataset.label;
1453
+ } else {
1454
+ state.selectedLabel.innerHTML = option.innerHTML;
1455
+ }
1456
+ state.selectedLabel.classList.remove('text-muted-foreground');
1457
+ selectedDetail = toSelected(option);
1458
+ value = selectedDetail.value;
1459
+ state.input.value = serializeSelection(state, [selectedDetail]);
1273
1460
  }
1274
- selectedDetail = toSelected(option);
1275
- value = selectedDetail.value;
1276
- state.input.value = serializeSelection(state, [selectedDetail]);
1277
1461
  }
1278
1462
 
1279
1463
  state.options.forEach(option => {
1280
- const isSelected = state.isMultiple ? state.selectedOptions.has(option) : option === optionOrOptions;
1464
+ const isSelected = state.isMultiple ? state.selectedOptions.has(option) : optionOrOptions && option === optionOrOptions;
1281
1465
  if (isSelected) {
1282
1466
  option.setAttribute('aria-selected', 'true');
1283
1467
  } else {
@@ -1322,7 +1506,7 @@
1322
1506
  state.visibleOptions = [...state.options];
1323
1507
  state.isMultiple = state.listbox.getAttribute('aria-multiselectable') === 'true';
1324
1508
  state.format = getFormat(root);
1325
- state.placeholder = state.isMultiple ? (root.dataset.placeholder || '') : null;
1509
+ state.placeholder = root.dataset.placeholder || '';
1326
1510
  state.closeOnSelect = root.dataset.closeOnSelect === 'true';
1327
1511
 
1328
1512
  if (state.isMultiple) {
@@ -1334,10 +1518,12 @@
1334
1518
  updateValue(root, selected, false);
1335
1519
  } else {
1336
1520
  const value = parseStoredValues(previousValue, state);
1337
- const selected = state.options.find(option => getValue(option) === value)
1521
+ const selected = value === '' && state.placeholder
1522
+ ? null
1523
+ : state.options.find(option => getValue(option) === value)
1338
1524
  || state.options.find(option => option.getAttribute('aria-selected') === 'true');
1339
1525
  state.options.forEach(option => option.removeAttribute('aria-selected'));
1340
- if (selected) updateValue(root, selected, false);
1526
+ updateValue(root, selected || null, false);
1341
1527
  }
1342
1528
 
1343
1529
  const selectedOption = state.listbox.querySelector('[role="option"][aria-selected="true"]');
@@ -1364,6 +1550,11 @@
1364
1550
  } else {
1365
1551
  const option = state.options.find(opt => getValue(opt) === value);
1366
1552
  if (!option) return;
1553
+ if (state.placeholder && getValue(option) === '') {
1554
+ updateValue(root, null);
1555
+ closePopover(state);
1556
+ return;
1557
+ }
1367
1558
  if (root.value !== value) updateValue(root, option);
1368
1559
  closePopover(state);
1369
1560
  }
@@ -1406,7 +1597,11 @@
1406
1597
  toggleMultipleValue(root, option);
1407
1598
  if (state.closeOnSelect) root.close();
1408
1599
  } else {
1409
- if (root.value !== getValue(option)) updateValue(root, option);
1600
+ if (state.placeholder && getValue(option) === '') {
1601
+ updateValue(root, null);
1602
+ } else if (root.value !== getValue(option)) {
1603
+ updateValue(root, option);
1604
+ }
1410
1605
  root.close();
1411
1606
  }
1412
1607
  }
@@ -1488,7 +1683,11 @@
1488
1683
  state.trigger.focus();
1489
1684
  }
1490
1685
  } else {
1491
- if (root.value !== getValue(option)) updateValue(root, option);
1686
+ if (state.placeholder && getValue(option) === '') {
1687
+ updateValue(root, null);
1688
+ } else if (root.value !== getValue(option)) {
1689
+ updateValue(root, option);
1690
+ }
1492
1691
  root.close();
1493
1692
  }
1494
1693
  };
@@ -1536,6 +1735,11 @@
1536
1735
  const values = Array.isArray(value) ? value : (value != null ? [value] : []);
1537
1736
  updateValue(root, values.map(v => state.options.find(option => getValue(option) === v)).filter(Boolean));
1538
1737
  } else {
1738
+ if (value == null || value === '') {
1739
+ updateValue(root, null);
1740
+ root.close();
1741
+ return;
1742
+ }
1539
1743
  const option = state.options.find(opt => getValue(opt) === value);
1540
1744
  if (option) {
1541
1745
  updateValue(root, option);