menhir 0.1.4 → 0.1.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.
- package/README.md +2 -2
- package/dist/combobox/clear/ComboboxClear.js +39 -0
- package/dist/combobox/filter/includesText.js +24 -0
- package/dist/combobox/group/ComboboxGroup.js +32 -0
- package/dist/combobox/group/ComboboxGroupContext.js +10 -0
- package/dist/combobox/group-label/ComboboxGroupLabel.js +26 -0
- package/dist/combobox/index.js +3 -0
- package/dist/combobox/index.parts.js +12 -0
- package/dist/combobox/input/ComboboxInput.js +160 -0
- package/dist/combobox/item/ComboboxItem.js +98 -0
- package/dist/combobox/item/ComboboxItemContext.js +10 -0
- package/dist/combobox/item-indicator/ComboboxItemIndicator.js +22 -0
- package/dist/combobox/list/ComboboxList.js +26 -0
- package/dist/combobox/popup/ComboboxPopup.js +78 -0
- package/dist/combobox/root/ComboboxContext.js +137 -0
- package/dist/combobox/root/ComboboxRoot.js +21 -0
- package/dist/combobox/status/ComboboxStatus.js +31 -0
- package/dist/combobox/trigger/ComboboxTrigger.js +47 -0
- package/dist/context-menu/index.js +2 -0
- package/dist/context-menu/index.parts.js +13 -0
- package/dist/context-menu/popup/ContextMenuPopup.js +30 -0
- package/dist/context-menu/root/ContextMenuContext.js +11 -0
- package/dist/context-menu/root/ContextMenuRoot.js +23 -0
- package/dist/context-menu/trigger/ContextMenuTrigger.js +47 -0
- package/dist/core/mergeElementProps.js +7 -1
- package/dist/menu/checkbox-item/MenuCheckboxItem.js +28 -0
- package/dist/menu/group/MenuGroup.js +40 -0
- package/dist/menu/group/MenuGroupContext.js +10 -0
- package/dist/menu/group-label/MenuGroupLabel.js +27 -0
- package/dist/menu/index.js +2 -0
- package/dist/menu/index.parts.js +13 -0
- package/dist/menu/item/MenuItem.js +30 -0
- package/dist/menu/item/menuItemProps.js +77 -0
- package/dist/menu/item/renderCheckedItem.js +52 -0
- package/dist/menu/item-indicator/MenuItemIndicator.js +23 -0
- package/dist/menu/item-indicator/MenuItemIndicatorContext.js +10 -0
- package/dist/menu/popup/MenuPopup.js +123 -0
- package/dist/menu/radio-group/MenuRadioGroup.js +39 -0
- package/dist/menu/radio-item/MenuRadioItem.js +21 -0
- package/dist/menu/root/MenuContext.js +114 -0
- package/dist/menu/root/MenuRoot.js +19 -0
- package/dist/menu/submenu/MenuSubmenu.js +18 -0
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +114 -0
- package/dist/menu/trigger/MenuTrigger.js +67 -0
- package/dist/menubar/index.js +2 -0
- package/dist/menubar/index.parts.js +14 -0
- package/dist/menubar/menu/MenubarMenu.js +30 -0
- package/dist/menubar/root/MenubarContext.js +10 -0
- package/dist/menubar/root/MenubarRoot.js +68 -0
- package/dist/menubar/trigger/MenubarTrigger.js +73 -0
- package/dist/select/group/SelectGroup.js +32 -0
- package/dist/select/group/SelectGroupContext.js +10 -0
- package/dist/select/group-label/SelectGroupLabel.js +26 -0
- package/dist/select/index.js +2 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/SelectItem.js +97 -0
- package/dist/select/item/SelectItemContext.js +10 -0
- package/dist/select/item-indicator/SelectItemIndicator.js +22 -0
- package/dist/select/popup/SelectPopup.js +92 -0
- package/dist/select/root/SelectContext.js +99 -0
- package/dist/select/root/SelectRoot.js +21 -0
- package/dist/select/trigger/SelectTrigger.js +163 -0
- package/dist/select/value/SelectValue.js +32 -0
- package/dist/source/combobox/clear/ComboboxClear.d.ts +12 -0
- package/dist/source/combobox/clear/ComboboxClear.jsx +36 -0
- package/dist/source/combobox/filter/includesText.d.ts +12 -0
- package/dist/source/combobox/filter/includesText.js +26 -0
- package/dist/source/combobox/group/ComboboxGroup.d.ts +10 -0
- package/dist/source/combobox/group/ComboboxGroup.jsx +23 -0
- package/dist/source/combobox/group/ComboboxGroupContext.d.ts +10 -0
- package/dist/source/combobox/group/ComboboxGroupContext.js +12 -0
- package/dist/source/combobox/group-label/ComboboxGroupLabel.d.ts +10 -0
- package/dist/source/combobox/group-label/ComboboxGroupLabel.jsx +24 -0
- package/dist/source/combobox/index.d.ts +2 -0
- package/dist/source/combobox/index.js +4 -0
- package/dist/source/combobox/index.parts.d.ts +11 -0
- package/dist/source/combobox/index.parts.js +11 -0
- package/dist/source/combobox/input/ComboboxInput.d.ts +19 -0
- package/dist/source/combobox/input/ComboboxInput.jsx +174 -0
- package/dist/source/combobox/item/ComboboxItem.d.ts +25 -0
- package/dist/source/combobox/item/ComboboxItem.jsx +93 -0
- package/dist/source/combobox/item/ComboboxItemContext.d.ts +11 -0
- package/dist/source/combobox/item/ComboboxItemContext.js +12 -0
- package/dist/source/combobox/item-indicator/ComboboxItemIndicator.d.ts +11 -0
- package/dist/source/combobox/item-indicator/ComboboxItemIndicator.jsx +16 -0
- package/dist/source/combobox/list/ComboboxList.d.ts +12 -0
- package/dist/source/combobox/list/ComboboxList.jsx +17 -0
- package/dist/source/combobox/popup/ComboboxPopup.d.ts +34 -0
- package/dist/source/combobox/popup/ComboboxPopup.jsx +76 -0
- package/dist/source/combobox/root/ComboboxContext.d.ts +132 -0
- package/dist/source/combobox/root/ComboboxContext.js +156 -0
- package/dist/source/combobox/root/ComboboxRoot.d.ts +13 -0
- package/dist/source/combobox/root/ComboboxRoot.jsx +13 -0
- package/dist/source/combobox/status/ComboboxStatus.d.ts +19 -0
- package/dist/source/combobox/status/ComboboxStatus.jsx +27 -0
- package/dist/source/combobox/trigger/ComboboxTrigger.d.ts +13 -0
- package/dist/source/combobox/trigger/ComboboxTrigger.jsx +40 -0
- package/dist/source/context-menu/index.d.ts +1 -0
- package/dist/source/context-menu/index.js +1 -0
- package/dist/source/context-menu/index.parts.d.ts +12 -0
- package/dist/source/context-menu/index.parts.js +13 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.d.ts +12 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.jsx +36 -0
- package/dist/source/context-menu/root/ContextMenuContext.d.ts +18 -0
- package/dist/source/context-menu/root/ContextMenuContext.js +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.d.ts +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +16 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.d.ts +15 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +46 -0
- package/dist/source/core/mergeElementProps.d.ts +8 -0
- package/dist/source/core/mergeElementProps.js +7 -1
- package/dist/source/floating/dismissal/reason.d.ts +12 -2
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.d.ts +20 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.jsx +26 -0
- package/dist/source/menu/group/MenuGroup.d.ts +16 -0
- package/dist/source/menu/group/MenuGroup.jsx +31 -0
- package/dist/source/menu/group/MenuGroupContext.d.ts +10 -0
- package/dist/source/menu/group/MenuGroupContext.js +12 -0
- package/dist/source/menu/group-label/MenuGroupLabel.d.ts +11 -0
- package/dist/source/menu/group-label/MenuGroupLabel.jsx +25 -0
- package/dist/source/menu/index.d.ts +1 -0
- package/dist/source/menu/index.js +1 -0
- package/dist/source/menu/index.parts.d.ts +12 -0
- package/dist/source/menu/index.parts.js +12 -0
- package/dist/source/menu/item/MenuItem.d.ts +11 -0
- package/dist/source/menu/item/MenuItem.jsx +21 -0
- package/dist/source/menu/item/menuItemProps.d.ts +35 -0
- package/dist/source/menu/item/menuItemProps.js +78 -0
- package/dist/source/menu/item/renderCheckedItem.d.ts +22 -0
- package/dist/source/menu/item/renderCheckedItem.jsx +41 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.d.ts +12 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.jsx +17 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.d.ts +11 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.js +12 -0
- package/dist/source/menu/popup/MenuPopup.d.ts +41 -0
- package/dist/source/menu/popup/MenuPopup.jsx +156 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.d.ts +27 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.jsx +36 -0
- package/dist/source/menu/radio-item/MenuRadioItem.d.ts +14 -0
- package/dist/source/menu/radio-item/MenuRadioItem.jsx +19 -0
- package/dist/source/menu/root/MenuContext.d.ts +114 -0
- package/dist/source/menu/root/MenuContext.js +123 -0
- package/dist/source/menu/root/MenuRoot.d.ts +11 -0
- package/dist/source/menu/root/MenuRoot.jsx +9 -0
- package/dist/source/menu/submenu/MenuSubmenu.d.ts +22 -0
- package/dist/source/menu/submenu/MenuSubmenu.jsx +10 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.d.ts +14 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +121 -0
- package/dist/source/menu/trigger/MenuTrigger.d.ts +13 -0
- package/dist/source/menu/trigger/MenuTrigger.jsx +73 -0
- package/dist/source/menubar/index.d.ts +1 -0
- package/dist/source/menubar/index.js +1 -0
- package/dist/source/menubar/index.parts.d.ts +13 -0
- package/dist/source/menubar/index.parts.js +14 -0
- package/dist/source/menubar/menu/MenubarMenu.d.ts +11 -0
- package/dist/source/menubar/menu/MenubarMenu.jsx +24 -0
- package/dist/source/menubar/root/MenubarContext.d.ts +30 -0
- package/dist/source/menubar/root/MenubarContext.js +12 -0
- package/dist/source/menubar/root/MenubarRoot.d.ts +11 -0
- package/dist/source/menubar/root/MenubarRoot.jsx +77 -0
- package/dist/source/menubar/trigger/MenubarTrigger.d.ts +11 -0
- package/dist/source/menubar/trigger/MenubarTrigger.jsx +78 -0
- package/dist/source/select/group/SelectGroup.d.ts +10 -0
- package/dist/source/select/group/SelectGroup.jsx +23 -0
- package/dist/source/select/group/SelectGroupContext.d.ts +10 -0
- package/dist/source/select/group/SelectGroupContext.js +12 -0
- package/dist/source/select/group-label/SelectGroupLabel.d.ts +10 -0
- package/dist/source/select/group-label/SelectGroupLabel.jsx +24 -0
- package/dist/source/select/index.d.ts +1 -0
- package/dist/source/select/index.js +1 -0
- package/dist/source/select/index.parts.d.ts +8 -0
- package/dist/source/select/index.parts.js +8 -0
- package/dist/source/select/item/SelectItem.d.ts +24 -0
- package/dist/source/select/item/SelectItem.jsx +92 -0
- package/dist/source/select/item/SelectItemContext.d.ts +11 -0
- package/dist/source/select/item/SelectItemContext.js +12 -0
- package/dist/source/select/item-indicator/SelectItemIndicator.d.ts +11 -0
- package/dist/source/select/item-indicator/SelectItemIndicator.jsx +16 -0
- package/dist/source/select/popup/SelectPopup.d.ts +32 -0
- package/dist/source/select/popup/SelectPopup.jsx +97 -0
- package/dist/source/select/root/SelectContext.d.ts +106 -0
- package/dist/source/select/root/SelectContext.js +119 -0
- package/dist/source/select/root/SelectRoot.d.ts +13 -0
- package/dist/source/select/root/SelectRoot.jsx +11 -0
- package/dist/source/select/trigger/SelectTrigger.d.ts +15 -0
- package/dist/source/select/trigger/SelectTrigger.jsx +181 -0
- package/dist/source/select/value/SelectValue.d.ts +20 -0
- package/dist/source/select/value/SelectValue.jsx +27 -0
- package/package.json +26 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
4
|
+
import { useSelectContext } from "../root/SelectContext.js";
|
|
5
|
+
import { effect, heldRead, isDev, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
+
import { createUniqueId, merge, omit, onFlush, onSettled, untrack } from "solid-js";
|
|
7
|
+
// src/select/trigger/SelectTrigger.tsx
|
|
8
|
+
var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 style=position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none>`);
|
|
9
|
+
var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
|
|
10
|
+
/**
|
|
11
|
+
* The button that shows the value and opens the list: a `<button
|
|
12
|
+
* type="button" role="combobox" aria-haspopup="listbox">` with
|
|
13
|
+
* `aria-expanded`, naming the Popup in `popovertarget` and `aria-controls`
|
|
14
|
+
* and the active item in `aria-activedescendant`. It keeps focus while the
|
|
15
|
+
* list is open and takes every key. A visually hidden `<input>` follows
|
|
16
|
+
* it, the form's view of the value. Name it with a `<label>`. Place it
|
|
17
|
+
* inside `Select.Root`, right before `Select.Popup`.
|
|
18
|
+
*/
|
|
19
|
+
function SelectTrigger(props) {
|
|
20
|
+
const select = useSelectContext();
|
|
21
|
+
const { list } = select;
|
|
22
|
+
const generated = createUniqueId();
|
|
23
|
+
const id = () => props.id ?? generated;
|
|
24
|
+
select.triggerId = id;
|
|
25
|
+
let input;
|
|
26
|
+
const press = (event) => ({
|
|
27
|
+
reason: "trigger-press",
|
|
28
|
+
event
|
|
29
|
+
});
|
|
30
|
+
const openList = (event, edge) => {
|
|
31
|
+
select.setOpen(true, press(event));
|
|
32
|
+
const items = list.items();
|
|
33
|
+
if (edge) list.move(edge === "last" ? items[items.length - 1] : items[0]);
|
|
34
|
+
};
|
|
35
|
+
const selectActive = (event, reason) => {
|
|
36
|
+
if (select.select(select.active()) || reason === "focus-out") select.setOpen(false, {
|
|
37
|
+
reason,
|
|
38
|
+
event
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
const ownProps = merge(select.attributes, {
|
|
42
|
+
type: "button",
|
|
43
|
+
role: "combobox",
|
|
44
|
+
get id() {
|
|
45
|
+
return id();
|
|
46
|
+
},
|
|
47
|
+
get disabled() {
|
|
48
|
+
return select.props.disabled;
|
|
49
|
+
},
|
|
50
|
+
popovertarget: select.popupId,
|
|
51
|
+
"aria-haspopup": "listbox",
|
|
52
|
+
get "aria-expanded"() {
|
|
53
|
+
return select.open() ? "true" : "false";
|
|
54
|
+
},
|
|
55
|
+
"aria-controls": select.popupId,
|
|
56
|
+
get "aria-activedescendant"() {
|
|
57
|
+
return select.open() ? select.active()?.id : void 0;
|
|
58
|
+
},
|
|
59
|
+
get "aria-required"() {
|
|
60
|
+
return select.props.required ? "true" : void 0;
|
|
61
|
+
},
|
|
62
|
+
onClick: (event) => {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
select.setOpen(!select.open(), press(event));
|
|
65
|
+
},
|
|
66
|
+
onKeyDown: (event) => {
|
|
67
|
+
const isOpen = select.open();
|
|
68
|
+
if (select.typeahead.onKeyDown(event)) {
|
|
69
|
+
if (!isOpen) select.setOpen(true, press(event));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { key, altKey } = event;
|
|
73
|
+
if (event.ctrlKey || event.metaKey) return;
|
|
74
|
+
if (key === "Tab") {
|
|
75
|
+
if (isOpen) selectActive(event, "focus-out");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (event.shiftKey) return;
|
|
79
|
+
const enterOrSpace = key === "Enter" || key === " ";
|
|
80
|
+
if (!isOpen) {
|
|
81
|
+
if (enterOrSpace || key === "ArrowDown") openList(event);
|
|
82
|
+
else if (altKey) return;
|
|
83
|
+
else if (key === "ArrowUp" || key === "Home") openList(event, "first");
|
|
84
|
+
else if (key === "End") openList(event, "last");
|
|
85
|
+
else return;
|
|
86
|
+
} else if (enterOrSpace || altKey && key === "ArrowUp") selectActive(event, "item-press");
|
|
87
|
+
else {
|
|
88
|
+
const active = select.active();
|
|
89
|
+
if (!list.active()) list.move(active);
|
|
90
|
+
if (key === "PageDown" || key === "PageUp") {
|
|
91
|
+
const items = list.items();
|
|
92
|
+
const index = items.indexOf(active) + (key === "PageUp" ? -10 : 10);
|
|
93
|
+
list.move(items[Math.min(Math.max(index, 0), items.length - 1)]);
|
|
94
|
+
} else if (!list.onKeyDown(event)) return;
|
|
95
|
+
}
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
},
|
|
98
|
+
ref: (element) => {
|
|
99
|
+
select.trigger = element;
|
|
100
|
+
if (isDev) warnUnlessButton(element, "Select.Trigger");
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const syncInput = () => {
|
|
104
|
+
if (input) input.value = untrack(select.value) ?? "";
|
|
105
|
+
};
|
|
106
|
+
const onInputChange = () => {
|
|
107
|
+
const filled = input.value;
|
|
108
|
+
const items = list.items();
|
|
109
|
+
const label = filled.toLowerCase();
|
|
110
|
+
const item = items.find((item) => item.value === filled) ?? items.find((item) => (item.text ?? item.element.textContent ?? "").trim().toLowerCase() === label);
|
|
111
|
+
if (item) select.setValue(item.value);
|
|
112
|
+
else if (!filled) select.setValue(null);
|
|
113
|
+
onFlush(syncInput);
|
|
114
|
+
};
|
|
115
|
+
onSettled(() => {
|
|
116
|
+
const form = input?.form;
|
|
117
|
+
if (!form) return;
|
|
118
|
+
const onReset = () => {
|
|
119
|
+
select.setValue(select.props.defaultValue ?? null);
|
|
120
|
+
onFlush(syncInput);
|
|
121
|
+
};
|
|
122
|
+
form.addEventListener("reset", onReset);
|
|
123
|
+
return () => form.removeEventListener("reset", onReset);
|
|
124
|
+
});
|
|
125
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
126
|
+
return [memo(() => {
|
|
127
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
128
|
+
var _el$2 = _tmpl$2();
|
|
129
|
+
spread(_el$2, p, false);
|
|
130
|
+
return _el$2;
|
|
131
|
+
})());
|
|
132
|
+
}), (() => {
|
|
133
|
+
var _el$ = _tmpl$();
|
|
134
|
+
_el$.addEventListener("focus", () => select.trigger?.focus());
|
|
135
|
+
_el$.addEventListener("change", onInputChange);
|
|
136
|
+
ref(() => {
|
|
137
|
+
return (element) => {
|
|
138
|
+
input = element;
|
|
139
|
+
select.input = element;
|
|
140
|
+
};
|
|
141
|
+
}, _el$);
|
|
142
|
+
effect(() => {
|
|
143
|
+
return {
|
|
144
|
+
e: select.props.name,
|
|
145
|
+
t: select.props.form,
|
|
146
|
+
a: select.props.required,
|
|
147
|
+
o: select.props.disabled,
|
|
148
|
+
i: select.props.autocomplete,
|
|
149
|
+
n: select.value() ?? "",
|
|
150
|
+
s: heldRead()
|
|
151
|
+
};
|
|
152
|
+
}, ({ e, t, a, o, i, n, s }, _p$) => {
|
|
153
|
+
e !== _p$?.e && setAttribute(_el$, "name", e);
|
|
154
|
+
t !== _p$?.t && setAttribute(_el$, "form", t);
|
|
155
|
+
a !== _p$?.a && setAttribute(_el$, "required", a);
|
|
156
|
+
o !== _p$?.o && setAttribute(_el$, "disabled", o);
|
|
157
|
+
i !== _p$?.i && setAttribute(_el$, "autocomplete", i);
|
|
158
|
+
(n !== _p$?.n || !s) && (_el$.value = n ?? "");
|
|
159
|
+
});
|
|
160
|
+
return _el$;
|
|
161
|
+
})()];
|
|
162
|
+
}
|
|
163
|
+
export { SelectTrigger };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
|
+
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
+
import { useSelectContext } from "../root/SelectContext.js";
|
|
4
|
+
import { spread, template } from "@solidjs/web";
|
|
5
|
+
import { omit } from "solid-js";
|
|
6
|
+
// src/select/value/SelectValue.tsx
|
|
7
|
+
var _tmpl$ = /* @__PURE__ */ template(`<span>`);
|
|
8
|
+
/**
|
|
9
|
+
* The selected item's label: a `<span>`, with the `placeholder` and
|
|
10
|
+
* `data-placeholder` while no item is selected. Place it inside
|
|
11
|
+
* `Select.Trigger`.
|
|
12
|
+
*/
|
|
13
|
+
function SelectValue(props) {
|
|
14
|
+
const select = useSelectContext();
|
|
15
|
+
const elementProps = mergeElementProps({
|
|
16
|
+
get "data-placeholder"() {
|
|
17
|
+
return select.value() === null ? "" : void 0;
|
|
18
|
+
},
|
|
19
|
+
get children() {
|
|
20
|
+
const value = select.value();
|
|
21
|
+
if (value === null) return props.placeholder;
|
|
22
|
+
if (props.children) return props.children(value);
|
|
23
|
+
return select.selectedItem()?.text.trim() ?? value;
|
|
24
|
+
}
|
|
25
|
+
}, omit(props, "render", "placeholder", "children"));
|
|
26
|
+
return renderElement(props, elementProps, (p) => (() => {
|
|
27
|
+
var _el$ = _tmpl$();
|
|
28
|
+
spread(_el$, p, false);
|
|
29
|
+
return _el$;
|
|
30
|
+
})());
|
|
31
|
+
}
|
|
32
|
+
export { SelectValue };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ComboboxClearProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
render?: RenderProp;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The button that empties the text and the value, for the pointer, as
|
|
8
|
+
* Escape on a closed list does from the keyboard: a `<button type="button"
|
|
9
|
+
* tabindex="-1">` that then focuses the input. Name it with `aria-label`.
|
|
10
|
+
* Place it inside `Combobox.Root`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ComboboxClear(props: ComboboxClearProps): JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { merge, omit } from "solid-js";
|
|
3
|
+
import { warnUnlessButton } from "../../core/button.js";
|
|
4
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
5
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
6
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* The button that empties the text and the value, for the pointer, as
|
|
9
|
+
* Escape on a closed list does from the keyboard: a `<button type="button"
|
|
10
|
+
* tabindex="-1">` that then focuses the input. Name it with `aria-label`.
|
|
11
|
+
* Place it inside `Combobox.Root`.
|
|
12
|
+
*/
|
|
13
|
+
export function ComboboxClear(props) {
|
|
14
|
+
const combobox = useComboboxContext();
|
|
15
|
+
const ownProps = merge(combobox.attributes, {
|
|
16
|
+
type: "button",
|
|
17
|
+
tabindex: -1,
|
|
18
|
+
get disabled() {
|
|
19
|
+
return combobox.props.disabled;
|
|
20
|
+
},
|
|
21
|
+
// Focus stays in the input, so that leaving it does not put the text
|
|
22
|
+
// back before the click empties it.
|
|
23
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
24
|
+
onClick: (event) => {
|
|
25
|
+
combobox.clear(event, "clear-press");
|
|
26
|
+
combobox.input?.focus();
|
|
27
|
+
},
|
|
28
|
+
ref: (element) => {
|
|
29
|
+
// Production builds drop the check with `isDev`.
|
|
30
|
+
if (isDev)
|
|
31
|
+
warnUnlessButton(element, "Combobox.Clear");
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
35
|
+
return renderElement(props, elementProps, (p) => <button {...p}/>);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `text` contains `query`, case and accents ignored, with the
|
|
3
|
+
* built-in `Intl.Collator`; an empty query matches everything. The filter
|
|
4
|
+
* for a Combobox whose items match what the user types:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const shown = createMemo(() =>
|
|
8
|
+
* countries.filter((country) => includesText(country.name, query())),
|
|
9
|
+
* );
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function includesText(text: string, query: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Made on the first call, never at import time (PLAN.md section 6, rule 2),
|
|
2
|
+
// and kept for the page: it holds no state.
|
|
3
|
+
let collator;
|
|
4
|
+
/**
|
|
5
|
+
* Whether `text` contains `query`, case and accents ignored, with the
|
|
6
|
+
* built-in `Intl.Collator`; an empty query matches everything. The filter
|
|
7
|
+
* for a Combobox whose items match what the user types:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const shown = createMemo(() =>
|
|
11
|
+
* countries.filter((country) => includesText(country.name, query())),
|
|
12
|
+
* );
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function includesText(text, query) {
|
|
16
|
+
// Composed, so that a letter and its accent are one character in both.
|
|
17
|
+
const haystack = text.normalize();
|
|
18
|
+
const needle = query.normalize();
|
|
19
|
+
collator ??= new Intl.Collator(undefined, { sensitivity: "base" });
|
|
20
|
+
for (let start = 0; start + needle.length <= haystack.length; start++) {
|
|
21
|
+
const slice = haystack.slice(start, start + needle.length);
|
|
22
|
+
if (!collator.compare(slice, needle))
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ComboboxGroupProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
render?: RenderProp;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Items that belong together: a `<div role="group">` named by its
|
|
8
|
+
* `Combobox.GroupLabel`. Place it inside `Combobox.List`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ComboboxGroup(props: ComboboxGroupProps): JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { omit } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { createIdSlot } from "../../core/slot.js";
|
|
5
|
+
import { ComboboxGroupContext } from "./ComboboxGroupContext.js";
|
|
6
|
+
/**
|
|
7
|
+
* Items that belong together: a `<div role="group">` named by its
|
|
8
|
+
* `Combobox.GroupLabel`. Place it inside `Combobox.List`.
|
|
9
|
+
*/
|
|
10
|
+
export function ComboboxGroup(props) {
|
|
11
|
+
const [labelId, registerLabelId] = createIdSlot();
|
|
12
|
+
const elementProps = mergeElementProps({
|
|
13
|
+
role: "group",
|
|
14
|
+
// The consumer's, else the GroupLabel's id, while one is rendered.
|
|
15
|
+
// Kept out of the merge ("`undefined` is a value", PLAN.md section 8).
|
|
16
|
+
get "aria-labelledby"() {
|
|
17
|
+
return props["aria-labelledby"] ?? labelId();
|
|
18
|
+
},
|
|
19
|
+
}, omit(props, "render", "aria-labelledby"));
|
|
20
|
+
return (<ComboboxGroupContext value={{ registerLabelId }}>
|
|
21
|
+
{renderElement(props, elementProps, (p) => (<div {...p}/>))}
|
|
22
|
+
</ComboboxGroupContext>);
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** What a group shares with its label. */
|
|
2
|
+
export interface ComboboxGroupContextValue {
|
|
3
|
+
/**
|
|
4
|
+
* Registers the `id` of a mounted GroupLabel, as a getter. Returns what
|
|
5
|
+
* unregisters it, for the label's disposal.
|
|
6
|
+
*/
|
|
7
|
+
registerLabelId(id: () => string | false): () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const ComboboxGroupContext: import("solid-js").Context<ComboboxGroupContextValue | null>;
|
|
10
|
+
export declare function useComboboxGroupContext(): ComboboxGroupContextValue;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext } from "solid-js";
|
|
2
|
+
import { isDev } from "@solidjs/web";
|
|
3
|
+
// `null` outside a group, so that the part can name what is missing.
|
|
4
|
+
export const ComboboxGroupContext = createContext(null);
|
|
5
|
+
export function useComboboxGroupContext() {
|
|
6
|
+
const context = useContext(ComboboxGroupContext);
|
|
7
|
+
// Production builds drop the check, and its message, with `isDev`.
|
|
8
|
+
if (isDev && !context) {
|
|
9
|
+
throw new Error("[menhir] Combobox.GroupLabel must be placed within <Combobox.Group>.");
|
|
10
|
+
}
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ComboboxGroupLabelProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
render?: RenderProp;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The label of a group, which names it in `aria-labelledby`: a `<div>`,
|
|
8
|
+
* not reached by the keys. Place it inside `Combobox.Group`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ComboboxGroupLabel(props: ComboboxGroupLabelProps): JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createUniqueId, omit, onSettled } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { useComboboxGroupContext } from "../group/ComboboxGroupContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* The label of a group, which names it in `aria-labelledby`: a `<div>`,
|
|
7
|
+
* not reached by the keys. Place it inside `Combobox.Group`.
|
|
8
|
+
*/
|
|
9
|
+
export function ComboboxGroupLabel(props) {
|
|
10
|
+
const group = useComboboxGroupContext();
|
|
11
|
+
const generated = createUniqueId();
|
|
12
|
+
// The consumer's `id`, else the generated one. Kept out of the merge,
|
|
13
|
+
// where a wrapper's `id={undefined}` would remove it.
|
|
14
|
+
const id = () => props.id ?? generated;
|
|
15
|
+
// Named once mounted, so the group names only a label that is rendered,
|
|
16
|
+
// and none in the server HTML, as a popup's Title.
|
|
17
|
+
onSettled(() => group.registerLabelId(id));
|
|
18
|
+
const elementProps = mergeElementProps({
|
|
19
|
+
get id() {
|
|
20
|
+
return id();
|
|
21
|
+
},
|
|
22
|
+
}, omit(props, "render", "id"));
|
|
23
|
+
return renderElement(props, elementProps, (p) => <div {...p}/>);
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ComboboxRoot as Root } from "./root/ComboboxRoot.tsx";
|
|
2
|
+
export { ComboboxInput as Input } from "./input/ComboboxInput.tsx";
|
|
3
|
+
export { ComboboxTrigger as Trigger } from "./trigger/ComboboxTrigger.tsx";
|
|
4
|
+
export { ComboboxClear as Clear } from "./clear/ComboboxClear.tsx";
|
|
5
|
+
export { ComboboxPopup as Popup } from "./popup/ComboboxPopup.tsx";
|
|
6
|
+
export { ComboboxList as List } from "./list/ComboboxList.tsx";
|
|
7
|
+
export { ComboboxItem as Item } from "./item/ComboboxItem.tsx";
|
|
8
|
+
export { ComboboxItemIndicator as ItemIndicator } from "./item-indicator/ComboboxItemIndicator.tsx";
|
|
9
|
+
export { ComboboxGroup as Group } from "./group/ComboboxGroup.tsx";
|
|
10
|
+
export { ComboboxGroupLabel as GroupLabel } from "./group-label/ComboboxGroupLabel.tsx";
|
|
11
|
+
export { ComboboxStatus as Status } from "./status/ComboboxStatus.tsx";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ComboboxRoot as Root } from "./root/ComboboxRoot.jsx";
|
|
2
|
+
export { ComboboxInput as Input } from "./input/ComboboxInput.jsx";
|
|
3
|
+
export { ComboboxTrigger as Trigger } from "./trigger/ComboboxTrigger.jsx";
|
|
4
|
+
export { ComboboxClear as Clear } from "./clear/ComboboxClear.jsx";
|
|
5
|
+
export { ComboboxPopup as Popup } from "./popup/ComboboxPopup.jsx";
|
|
6
|
+
export { ComboboxList as List } from "./list/ComboboxList.jsx";
|
|
7
|
+
export { ComboboxItem as Item } from "./item/ComboboxItem.jsx";
|
|
8
|
+
export { ComboboxItemIndicator as ItemIndicator } from "./item-indicator/ComboboxItemIndicator.jsx";
|
|
9
|
+
export { ComboboxGroup as Group } from "./group/ComboboxGroup.jsx";
|
|
10
|
+
export { ComboboxGroupLabel as GroupLabel } from "./group-label/ComboboxGroupLabel.jsx";
|
|
11
|
+
export { ComboboxStatus as Status } from "./status/ComboboxStatus.jsx";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ComboboxInputProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** What the browser may suggest. Default `"off"`, so its list does not cover the Combobox's. */
|
|
5
|
+
autocomplete?: string;
|
|
6
|
+
/** Shown while the input is empty. */
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
render?: RenderProp;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The combobox itself: an `<input type="text" role="combobox"
|
|
12
|
+
* aria-autocomplete="list">` with `aria-expanded`, naming the List in
|
|
13
|
+
* `aria-controls` and the active item in `aria-activedescendant`. It keeps
|
|
14
|
+
* focus while the list is open: typing opens and filters it, and the arrow
|
|
15
|
+
* keys, Enter and Escape act on it. A visually hidden `<input>` follows it,
|
|
16
|
+
* the form's view of the value. Name it with a `<label>`. Place it inside
|
|
17
|
+
* `Combobox.Root`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ComboboxInput(props: ComboboxInputProps): JSX.Element;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createSignal, merge, omit, onFlush, onSettled, untrack, } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* The combobox itself: an `<input type="text" role="combobox"
|
|
7
|
+
* aria-autocomplete="list">` with `aria-expanded`, naming the List in
|
|
8
|
+
* `aria-controls` and the active item in `aria-activedescendant`. It keeps
|
|
9
|
+
* focus while the list is open: typing opens and filters it, and the arrow
|
|
10
|
+
* keys, Enter and Escape act on it. A visually hidden `<input>` follows it,
|
|
11
|
+
* the form's view of the value. Name it with a `<label>`. Place it inside
|
|
12
|
+
* `Combobox.Root`.
|
|
13
|
+
*/
|
|
14
|
+
export function ComboboxInput(props) {
|
|
15
|
+
const combobox = useComboboxContext();
|
|
16
|
+
const { list } = combobox;
|
|
17
|
+
let input;
|
|
18
|
+
let hiddenInput;
|
|
19
|
+
const details = (reason, event) => ({ reason, event });
|
|
20
|
+
const setOpen = (open, reason, event) => combobox.setOpen(open, details(reason, event));
|
|
21
|
+
// What the input's `value` binds to: the Combobox's text, and each edit
|
|
22
|
+
// as it is made. The Combobox writes its own text after the event's flush
|
|
23
|
+
// (`createControllableSignal`), and a binding that re-ran in that flush,
|
|
24
|
+
// as `aria-activedescendant` does when typing empties the active item,
|
|
25
|
+
// would write the old text over the edit.
|
|
26
|
+
const [draft, setDraft] = createSignal(() => combobox.inputValue());
|
|
27
|
+
// Puts the draft and the element back to the Combobox's text, once that
|
|
28
|
+
// has settled: a controlled Combobox's consumer may have declined the
|
|
29
|
+
// edit, and a form reset sets the element without an `input` event.
|
|
30
|
+
const syncText = () => {
|
|
31
|
+
const text = untrack(combobox.inputValue);
|
|
32
|
+
setDraft(text);
|
|
33
|
+
// Only when it differs, since a write moves the caret to the end.
|
|
34
|
+
if (input && input.value !== text)
|
|
35
|
+
input.value = text;
|
|
36
|
+
};
|
|
37
|
+
const ownProps = merge(combobox.attributes, {
|
|
38
|
+
type: "text",
|
|
39
|
+
role: "combobox",
|
|
40
|
+
"aria-autocomplete": "list",
|
|
41
|
+
autocomplete: "off",
|
|
42
|
+
get value() {
|
|
43
|
+
return draft();
|
|
44
|
+
},
|
|
45
|
+
get disabled() {
|
|
46
|
+
return combobox.props.disabled;
|
|
47
|
+
},
|
|
48
|
+
get "aria-expanded"() {
|
|
49
|
+
return combobox.open() ? "true" : "false";
|
|
50
|
+
},
|
|
51
|
+
"aria-controls": combobox.listId,
|
|
52
|
+
// Only while open, as an item's `data-active`.
|
|
53
|
+
get "aria-activedescendant"() {
|
|
54
|
+
return combobox.open() ? list.activeId() : undefined;
|
|
55
|
+
},
|
|
56
|
+
get "aria-required"() {
|
|
57
|
+
return combobox.props.required ? "true" : undefined;
|
|
58
|
+
},
|
|
59
|
+
onInput: (event) => {
|
|
60
|
+
setDraft(input.value);
|
|
61
|
+
combobox.setInputValue(input.value, details("input-change", event));
|
|
62
|
+
// The keys start again from the text (README, "Keys while open").
|
|
63
|
+
list.move(undefined);
|
|
64
|
+
setOpen(true, "input-change", event);
|
|
65
|
+
onFlush(syncText);
|
|
66
|
+
},
|
|
67
|
+
onKeyDown: (event) => {
|
|
68
|
+
// An input method's keys, such as the Enter that commits what it
|
|
69
|
+
// composed (README, "An input method's composition").
|
|
70
|
+
if (event.isComposing || event.keyCode === 229)
|
|
71
|
+
return;
|
|
72
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey)
|
|
73
|
+
return;
|
|
74
|
+
const isOpen = combobox.open();
|
|
75
|
+
const { key, altKey } = event;
|
|
76
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
77
|
+
const down = key === "ArrowDown";
|
|
78
|
+
if (altKey) {
|
|
79
|
+
// Alt+Down opens without moving, Alt+Up closes.
|
|
80
|
+
if (down === isOpen)
|
|
81
|
+
return;
|
|
82
|
+
setOpen(down, "arrow-key", event);
|
|
83
|
+
}
|
|
84
|
+
else if (!isOpen) {
|
|
85
|
+
setOpen(true, "arrow-key", event);
|
|
86
|
+
// While closed, the move waits for the list to open.
|
|
87
|
+
const items = list.items();
|
|
88
|
+
list.move(down ? items[0] : items[items.length - 1]);
|
|
89
|
+
}
|
|
90
|
+
else if (!list.onKeyDown(event))
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
else if (key === "Enter" && !altKey) {
|
|
94
|
+
if (!isOpen)
|
|
95
|
+
return;
|
|
96
|
+
const item = list.active();
|
|
97
|
+
if (!item) {
|
|
98
|
+
// A form submits, as it would from a text input.
|
|
99
|
+
setOpen(false, "enter-key", event);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (combobox.select(item, event))
|
|
103
|
+
setOpen(false, "item-press", event);
|
|
104
|
+
}
|
|
105
|
+
else if (key === "Escape" && !altKey) {
|
|
106
|
+
if (isOpen)
|
|
107
|
+
setOpen(false, "escape-key", event);
|
|
108
|
+
else if (combobox.inputValue() || combobox.value() !== null)
|
|
109
|
+
combobox.clear(event, "escape-key");
|
|
110
|
+
// Nothing to close or clear: a dialog around it may close.
|
|
111
|
+
else
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
return;
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
},
|
|
118
|
+
onBlur: (event) => {
|
|
119
|
+
// Focus lost to another window comes back to the input.
|
|
120
|
+
if (!document.hasFocus())
|
|
121
|
+
return;
|
|
122
|
+
setOpen(false, "focus-out", event);
|
|
123
|
+
combobox.revert(event);
|
|
124
|
+
},
|
|
125
|
+
ref: (element) => {
|
|
126
|
+
input = element;
|
|
127
|
+
combobox.input = input;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
// A selection, which the Combobox makes through the hidden input.
|
|
131
|
+
const onHiddenChange = () => {
|
|
132
|
+
combobox.setValue(hiddenInput.value || null);
|
|
133
|
+
onFlush(syncHidden);
|
|
134
|
+
};
|
|
135
|
+
// Puts the hidden input back to the value, once that has settled.
|
|
136
|
+
const syncHidden = () => {
|
|
137
|
+
if (hiddenInput)
|
|
138
|
+
hiddenInput.value = untrack(combobox.value) ?? "";
|
|
139
|
+
};
|
|
140
|
+
// A form reset puts a control back to its default, and so it does the
|
|
141
|
+
// Combobox: through the setters, so that a controlled Combobox asks.
|
|
142
|
+
onSettled(() => {
|
|
143
|
+
const form = hiddenInput?.form;
|
|
144
|
+
if (!form)
|
|
145
|
+
return;
|
|
146
|
+
const onReset = (event) => {
|
|
147
|
+
const value = combobox.props.defaultValue ?? null;
|
|
148
|
+
combobox.setValue(value);
|
|
149
|
+
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", details("reset", event));
|
|
150
|
+
// The browser resets the inputs after this event, to their `value`
|
|
151
|
+
// attributes; `onFlush` runs after that.
|
|
152
|
+
onFlush(() => {
|
|
153
|
+
syncHidden();
|
|
154
|
+
syncText();
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
form.addEventListener("reset", onReset);
|
|
158
|
+
return () => form.removeEventListener("reset", onReset);
|
|
159
|
+
});
|
|
160
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render"));
|
|
161
|
+
return (<>
|
|
162
|
+
{renderElement(props, elementProps, (p) => (<input {...p}/>))}
|
|
163
|
+
<input aria-hidden="true" tabindex={-1} style={visuallyHidden} name={combobox.props.name} form={combobox.props.form} required={combobox.props.required} disabled={combobox.props.disabled} value={combobox.value() ?? ""} onChange={onHiddenChange}
|
|
164
|
+
// The browser focuses an invalid input when it blocks a submission.
|
|
165
|
+
// The user knows the visible input, not the hidden one.
|
|
166
|
+
onFocus={() => combobox.input?.focus()} ref={(element) => {
|
|
167
|
+
hiddenInput = element;
|
|
168
|
+
combobox.hiddenInput = element;
|
|
169
|
+
}}/>
|
|
170
|
+
</>);
|
|
171
|
+
}
|
|
172
|
+
// Hidden from sight but not from the form. Not `display: none`, so the
|
|
173
|
+
// browser can still anchor a validation message to it.
|
|
174
|
+
const visuallyHidden = "position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap;pointer-events:none";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ComboboxItemProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** What the Combobox's value is while this item is selected. Not `""`. */
|
|
5
|
+
value: string;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the item is disabled: still reached by the keys and the
|
|
8
|
+
* pointer, but not selected.
|
|
9
|
+
*/
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The item's text, when its content is not its label, such as an icon
|
|
13
|
+
* beside it: what the input shows once the item is selected.
|
|
14
|
+
*/
|
|
15
|
+
label?: string;
|
|
16
|
+
render?: RenderProp;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A value to select: a `<div role="option">` with `aria-selected`. A click
|
|
20
|
+
* selects it, sets the input's text to its label and closes the list, and
|
|
21
|
+
* so does Enter while it is the active item; a disabled item is not
|
|
22
|
+
* selected. Render the items that match the text, and place them inside
|
|
23
|
+
* `Combobox.List`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function ComboboxItem(props: ComboboxItemProps): JSX.Element;
|