@kerkhoff-ict/solora 2.1.2 → 2.1.4

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.
package/dist/index.css CHANGED
@@ -7,13 +7,20 @@
7
7
  cursor: pointer;
8
8
  transition: background 0.2s, filter 0.2s;
9
9
  }
10
- .btn-rounded {
11
- padding: 0 !important;
12
- display: flex;
10
+ .btn-rounded-sm {
11
+ display: inline-flex;
13
12
  align-items: center;
14
13
  justify-content: center;
15
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
14
+ width: 2.2rem;
15
+ height: 2.2rem;
16
+ border-radius: 50%;
17
+ padding: 0;
16
18
  cursor: pointer;
19
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
20
+ overflow: hidden;
21
+ background: var(--color-primary, #0071e3);
22
+ color: var(--color-text-light, #fff);
23
+ transition: background 0.2s, transform 0.2s;
17
24
  }
18
25
  .btn-sm {
19
26
  padding: 0.1875rem 1rem;
package/dist/index.js CHANGED
@@ -1851,6 +1851,8 @@ function initMaximizeButton(block, maximizeBtn) {
1851
1851
  function initDropdowns() {
1852
1852
  if (typeof window === "undefined") return;
1853
1853
  document.querySelectorAll(".dropdown").forEach((drop) => {
1854
+ if (drop.dataset.initialized) return;
1855
+ drop.dataset.initialized = "true";
1854
1856
  const btn = drop.querySelector(".dropdown-btn");
1855
1857
  const content = drop.querySelector(".dropdown-content");
1856
1858
  if (!btn || !content) return;
@@ -1861,59 +1863,58 @@ function initDropdowns() {
1861
1863
  hiddenInput.name = drop.dataset.name || "dropdown";
1862
1864
  drop.appendChild(hiddenInput);
1863
1865
  }
1866
+ const getItems = () => Array.from(content.querySelectorAll('.dropdown-item:not([aria-disabled="true"])'));
1864
1867
  const setValue = (item) => {
1865
1868
  if (item.getAttribute("aria-disabled") === "true") return;
1866
- btn.textContent = item.textContent;
1869
+ btn.innerHTML = item.innerHTML;
1867
1870
  content.querySelectorAll(".dropdown-item").forEach((i) => i.classList.remove("active"));
1868
1871
  item.classList.add("active");
1869
- hiddenInput.value = item.dataset.value ?? item.textContent;
1872
+ hiddenInput.value = item.dataset.value ?? item.textContent.trim();
1873
+ drop.dispatchEvent(new CustomEvent("change", { detail: hiddenInput.value }));
1870
1874
  };
1871
1875
  const initialItem = content.querySelector(".dropdown-item.active") || content.querySelector('.dropdown-item:not([aria-disabled="true"])');
1872
1876
  if (initialItem) setValue(initialItem);
1873
- const openDropdown = () => drop.classList.add("open");
1874
- const closeDropdown = () => drop.classList.remove("open");
1877
+ const toggle = () => drop.classList.toggle("open");
1878
+ const close = () => drop.classList.remove("open");
1875
1879
  btn.addEventListener("click", (e) => {
1876
- if (drop.getAttribute("aria-disabled") === "true") return;
1877
1880
  e.stopPropagation();
1878
- drop.classList.toggle("open");
1881
+ toggle();
1879
1882
  });
1880
1883
  document.addEventListener("click", (e) => {
1881
- if (!drop.contains(e.target)) closeDropdown();
1884
+ if (!drop.contains(e.target)) close();
1882
1885
  });
1883
- content.querySelectorAll(".dropdown-item").forEach((item) => {
1884
- item.addEventListener("click", () => {
1885
- setValue(item);
1886
- closeDropdown();
1887
- });
1888
- });
1889
- let items = Array.from(content.querySelectorAll('.dropdown-item:not([aria-disabled="true"])'));
1890
- let index = items.findIndex((i) => i.classList.contains("active"));
1891
1886
  btn.addEventListener("keydown", (e) => {
1892
- if (drop.getAttribute("aria-disabled") === "true") return;
1893
1887
  if (!["ArrowDown", "ArrowUp", "Enter", "Escape"].includes(e.key)) return;
1888
+ const items = getItems();
1889
+ let currentIndex = items.findIndex((i) => i.classList.contains("active"));
1894
1890
  e.preventDefault();
1895
- openDropdown();
1891
+ drop.classList.add("open");
1896
1892
  if (e.key === "ArrowDown") {
1897
- index = (index + 1) % items.length;
1898
- items.forEach((i) => i.classList.remove("active"));
1899
- items[index].classList.add("active");
1900
- items[index].scrollIntoView({ block: "nearest" });
1901
- }
1902
- if (e.key === "ArrowUp") {
1903
- index = (index - 1 + items.length) % items.length;
1904
- items.forEach((i) => i.classList.remove("active"));
1905
- items[index].classList.add("active");
1906
- items[index].scrollIntoView({ block: "nearest" });
1907
- }
1908
- if (e.key === "Enter") {
1909
- setValue(items[index]);
1910
- closeDropdown();
1893
+ currentIndex = (currentIndex + 1) % items.length;
1894
+ } else if (e.key === "ArrowUp") {
1895
+ currentIndex = (currentIndex - 1 + items.length) % items.length;
1896
+ } else if (e.key === "Enter") {
1897
+ if (currentIndex >= 0) setValue(items[currentIndex]);
1898
+ close();
1899
+ return;
1900
+ } else if (e.key === "Escape") {
1901
+ close();
1902
+ return;
1911
1903
  }
1912
- if (e.key === "Escape") {
1913
- closeDropdown();
1904
+ items.forEach((i) => i.classList.remove("active"));
1905
+ items[currentIndex].classList.add("active");
1906
+ items[currentIndex].scrollIntoView({ block: "nearest" });
1907
+ });
1908
+ content.addEventListener("click", (e) => {
1909
+ const item = e.target.closest(".dropdown-item");
1910
+ if (item) {
1911
+ setValue(item);
1912
+ close();
1914
1913
  }
1915
1914
  });
1916
1915
  btn.setAttribute("tabindex", "0");
1916
+ btn.setAttribute("role", "combobox");
1917
+ btn.setAttribute("aria-haspopup", "listbox");
1917
1918
  });
1918
1919
  }
1919
1920
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerkhoff-ict/solora",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Simple CSS component library",
5
5
  "main": "dist/index.js",
6
6
  "style": "dist/index.css",