@mirror-physics/fractal-ui 0.2.0-next.83 → 0.2.0-next.84
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.cjs +11 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +38 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1732,6 +1732,7 @@ function Dropdown({
|
|
|
1732
1732
|
emptyMessage = "No matching options.",
|
|
1733
1733
|
triggerLabel,
|
|
1734
1734
|
fieldLabel,
|
|
1735
|
+
clearable = Boolean(fieldLabel),
|
|
1735
1736
|
direction = "down",
|
|
1736
1737
|
align = "left",
|
|
1737
1738
|
maxHeight = 320,
|
|
@@ -1755,6 +1756,7 @@ function Dropdown({
|
|
|
1755
1756
|
const searchRef = React12.useRef(null);
|
|
1756
1757
|
const accessibleLabel = triggerLabel ?? fieldLabel ?? "Options";
|
|
1757
1758
|
const size = controlSize ?? sizeAlias;
|
|
1759
|
+
const canClear = clearable && !disabled && (multiple ? selectedValues.length > 0 && Boolean(onSelectionChange) : Boolean(selectedValue) && Boolean(onSelect));
|
|
1758
1760
|
const [open, setOpen] = React12.useState(false);
|
|
1759
1761
|
React12.useEffect(() => {
|
|
1760
1762
|
if (!open) setQuery("");
|
|
@@ -1783,7 +1785,7 @@ function Dropdown({
|
|
|
1783
1785
|
return renderableItems.slice(index + 1, nextHeader < 0 ? void 0 : nextHeader).some((next) => matching.has(next.value));
|
|
1784
1786
|
});
|
|
1785
1787
|
const selectableItems = visibleItems.filter((i) => i.kind !== "header");
|
|
1786
|
-
const selected = items.find((i) => i.value === selectedValue && i.kind !== "header") ?? selectableItems[0] ?? visibleItems[0];
|
|
1788
|
+
const selected = items.find((i) => i.value === selectedValue && i.kind !== "header") ?? (fieldLabel && !selectedValue && !multiple ? void 0 : selectableItems[0] ?? visibleItems[0]);
|
|
1787
1789
|
const ChevronIcon = direction === "up" ? import_fractal_icons10.ChevronUp : direction === "left" ? import_fractal_icons10.ChevronLeft : direction === "right" ? import_fractal_icons10.ChevronRight : import_fractal_icons10.ChevronDown;
|
|
1788
1790
|
useEscapeDismiss(100, () => {
|
|
1789
1791
|
setOpen(false);
|
|
@@ -1877,7 +1879,7 @@ function Dropdown({
|
|
|
1877
1879
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
1878
1880
|
}, [open]);
|
|
1879
1881
|
if (renderableItems.length === 0) return null;
|
|
1880
|
-
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { ref: rootRef, "data-control-size": size, "data-filled": multiple ? selectedValues.length > 0 : Boolean(selectedValue), "data-open": open, className: cn("fractal-dropdown", fieldLabel && "fractal-floating-field fractal-floating-field--dropdown", className), children: [
|
|
1882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { ref: rootRef, "data-control-size": size, "data-filled": multiple ? selectedValues.length > 0 : Boolean(selectedValue), "data-open": open, "data-clearable": canClear || void 0, className: cn("fractal-dropdown", fieldLabel && "fractal-floating-field fractal-floating-field--dropdown", className), children: [
|
|
1881
1883
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
1882
1884
|
"button",
|
|
1883
1885
|
{
|
|
@@ -1922,6 +1924,13 @@ function Dropdown({
|
|
|
1922
1924
|
]
|
|
1923
1925
|
}
|
|
1924
1926
|
),
|
|
1927
|
+
canClear && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("button", { type: "button", className: "fractal-dropdown-clear", "aria-label": `Clear ${accessibleLabel}`, onClick: () => {
|
|
1928
|
+
if (multiple) onSelectionChange?.([]);
|
|
1929
|
+
else onSelect?.("");
|
|
1930
|
+
setOpen(false);
|
|
1931
|
+
setQuery("");
|
|
1932
|
+
triggerRef.current?.focus();
|
|
1933
|
+
}, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_fractal_icons10.Close, { "aria-hidden": "true" }) }),
|
|
1925
1934
|
fieldLabel ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("label", { className: "fractal-floating-field__label", htmlFor: triggerId ?? `${menuId}-trigger`, children: fieldLabel }) : null,
|
|
1926
1935
|
open && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
1927
1936
|
"div",
|