@zag-js/combobox 0.52.0 → 0.54.0
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.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1476 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1446 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
- package/src/combobox.connect.ts +181 -164
- package/src/combobox.types.ts +8 -8
package/src/combobox.connect.ts
CHANGED
|
@@ -84,142 +84,153 @@ export function connect<T extends PropTypes, V extends CollectionItem>(
|
|
|
84
84
|
if (nextOpen === open) return
|
|
85
85
|
send(nextOpen ? "OPEN" : "CLOSE")
|
|
86
86
|
},
|
|
87
|
-
rootProps: normalize.element({
|
|
88
|
-
...parts.root.attrs,
|
|
89
|
-
dir: state.context.dir,
|
|
90
|
-
id: dom.getRootId(state.context),
|
|
91
|
-
"data-invalid": dataAttr(invalid),
|
|
92
|
-
"data-readonly": dataAttr(readOnly),
|
|
93
|
-
}),
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
onClick(event) {
|
|
105
|
-
if (composite) return
|
|
106
|
-
event.preventDefault()
|
|
107
|
-
dom.getTriggerEl(state.context)?.focus({ preventScroll: true })
|
|
108
|
-
},
|
|
109
|
-
}),
|
|
88
|
+
getRootProps() {
|
|
89
|
+
return normalize.element({
|
|
90
|
+
...parts.root.attrs,
|
|
91
|
+
dir: state.context.dir,
|
|
92
|
+
id: dom.getRootId(state.context),
|
|
93
|
+
"data-invalid": dataAttr(invalid),
|
|
94
|
+
"data-readonly": dataAttr(readOnly),
|
|
95
|
+
})
|
|
96
|
+
},
|
|
110
97
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
getLabelProps() {
|
|
99
|
+
return normalize.label({
|
|
100
|
+
...parts.label.attrs,
|
|
101
|
+
dir: state.context.dir,
|
|
102
|
+
htmlFor: dom.getInputId(state.context),
|
|
103
|
+
id: dom.getLabelId(state.context),
|
|
104
|
+
"data-readonly": dataAttr(readOnly),
|
|
105
|
+
"data-disabled": dataAttr(disabled),
|
|
106
|
+
"data-invalid": dataAttr(invalid),
|
|
107
|
+
"data-focus": dataAttr(focused),
|
|
108
|
+
onClick(event) {
|
|
109
|
+
if (composite) return
|
|
110
|
+
event.preventDefault()
|
|
111
|
+
dom.getTriggerEl(state.context)?.focus({ preventScroll: true })
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
},
|
|
120
115
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
getControlProps() {
|
|
117
|
+
return normalize.element({
|
|
118
|
+
...parts.control.attrs,
|
|
119
|
+
dir: state.context.dir,
|
|
120
|
+
id: dom.getControlId(state.context),
|
|
121
|
+
"data-state": open ? "open" : "closed",
|
|
122
|
+
"data-focus": dataAttr(focused),
|
|
123
|
+
"data-disabled": dataAttr(disabled),
|
|
124
|
+
"data-invalid": dataAttr(invalid),
|
|
125
|
+
})
|
|
126
|
+
},
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
autoFocus: state.context.autoFocus,
|
|
137
|
-
autoComplete: "off",
|
|
138
|
-
autoCorrect: "off",
|
|
139
|
-
autoCapitalize: "none",
|
|
140
|
-
spellCheck: "false",
|
|
141
|
-
readOnly: readOnly,
|
|
142
|
-
placeholder: state.context.placeholder,
|
|
143
|
-
id: dom.getInputId(state.context),
|
|
144
|
-
type: "text",
|
|
145
|
-
role: "combobox",
|
|
146
|
-
defaultValue: state.context.inputValue,
|
|
147
|
-
"aria-autocomplete": state.context.autoComplete ? "both" : "list",
|
|
148
|
-
"aria-controls": dom.getContentId(state.context),
|
|
149
|
-
"aria-expanded": open,
|
|
150
|
-
"data-state": open ? "open" : "closed",
|
|
151
|
-
"aria-activedescendant": highlightedValue ? dom.getItemId(state.context, highlightedValue) : undefined,
|
|
152
|
-
onClick(event) {
|
|
153
|
-
if (event.defaultPrevented) return
|
|
154
|
-
if (!state.context.openOnClick) return
|
|
155
|
-
if (!interactive) return
|
|
156
|
-
send("INPUT.CLICK")
|
|
157
|
-
},
|
|
158
|
-
onFocus() {
|
|
159
|
-
if (disabled) return
|
|
160
|
-
send("INPUT.FOCUS")
|
|
161
|
-
},
|
|
162
|
-
onBlur() {
|
|
163
|
-
if (disabled) return
|
|
164
|
-
send("INPUT.BLUR")
|
|
165
|
-
},
|
|
166
|
-
onChange(event) {
|
|
167
|
-
send({ type: "INPUT.CHANGE", value: event.currentTarget.value })
|
|
168
|
-
},
|
|
169
|
-
onKeyDown(event) {
|
|
170
|
-
if (event.defaultPrevented) return
|
|
171
|
-
if (!interactive) return
|
|
128
|
+
getPositionerProps() {
|
|
129
|
+
return normalize.element({
|
|
130
|
+
...parts.positioner.attrs,
|
|
131
|
+
dir: state.context.dir,
|
|
132
|
+
id: dom.getPositionerId(state.context),
|
|
133
|
+
style: popperStyles.floating,
|
|
134
|
+
})
|
|
135
|
+
},
|
|
172
136
|
|
|
173
|
-
|
|
137
|
+
getInputProps() {
|
|
138
|
+
return normalize.input({
|
|
139
|
+
...parts.input.attrs,
|
|
140
|
+
dir: state.context.dir,
|
|
141
|
+
"aria-invalid": ariaAttr(invalid),
|
|
142
|
+
"data-invalid": dataAttr(invalid),
|
|
143
|
+
name: state.context.name,
|
|
144
|
+
form: state.context.form,
|
|
145
|
+
disabled: disabled,
|
|
146
|
+
autoFocus: state.context.autoFocus,
|
|
147
|
+
autoComplete: "off",
|
|
148
|
+
autoCorrect: "off",
|
|
149
|
+
autoCapitalize: "none",
|
|
150
|
+
spellCheck: "false",
|
|
151
|
+
readOnly: readOnly,
|
|
152
|
+
placeholder: state.context.placeholder,
|
|
153
|
+
id: dom.getInputId(state.context),
|
|
154
|
+
type: "text",
|
|
155
|
+
role: "combobox",
|
|
156
|
+
defaultValue: state.context.inputValue,
|
|
157
|
+
"aria-autocomplete": state.context.autoComplete ? "both" : "list",
|
|
158
|
+
"aria-controls": dom.getContentId(state.context),
|
|
159
|
+
"aria-expanded": open,
|
|
160
|
+
"data-state": open ? "open" : "closed",
|
|
161
|
+
"aria-activedescendant": highlightedValue ? dom.getItemId(state.context, highlightedValue) : undefined,
|
|
162
|
+
onClick(event) {
|
|
163
|
+
if (event.defaultPrevented) return
|
|
164
|
+
if (!state.context.openOnClick) return
|
|
165
|
+
if (!interactive) return
|
|
166
|
+
send("INPUT.CLICK")
|
|
167
|
+
},
|
|
168
|
+
onFocus() {
|
|
169
|
+
if (disabled) return
|
|
170
|
+
send("INPUT.FOCUS")
|
|
171
|
+
},
|
|
172
|
+
onBlur() {
|
|
173
|
+
if (disabled) return
|
|
174
|
+
send("INPUT.BLUR")
|
|
175
|
+
},
|
|
176
|
+
onChange(event) {
|
|
177
|
+
send({ type: "INPUT.CHANGE", value: event.currentTarget.value })
|
|
178
|
+
},
|
|
179
|
+
onKeyDown(event) {
|
|
180
|
+
if (event.defaultPrevented) return
|
|
181
|
+
if (!interactive) return
|
|
174
182
|
|
|
175
|
-
|
|
176
|
-
const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey
|
|
177
|
-
const keypress = true
|
|
183
|
+
if (event.ctrlKey || event.shiftKey || isComposingEvent(event)) return
|
|
178
184
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
send({ type: event.altKey ? "CLOSE" : "INPUT.ARROW_UP", keypress })
|
|
188
|
-
event.preventDefault()
|
|
189
|
-
},
|
|
190
|
-
Home(event) {
|
|
191
|
-
if (isModifierKey) return
|
|
192
|
-
send({ type: "INPUT.HOME", keypress })
|
|
193
|
-
if (open) {
|
|
185
|
+
const openOnKeyPress = state.context.openOnKeyPress
|
|
186
|
+
const isModifierKey = event.ctrlKey || event.metaKey || event.shiftKey
|
|
187
|
+
const keypress = true
|
|
188
|
+
|
|
189
|
+
const keymap: EventKeyMap = {
|
|
190
|
+
ArrowDown(event) {
|
|
191
|
+
if (!openOnKeyPress && !open) return
|
|
192
|
+
send({ type: event.altKey ? "OPEN" : "INPUT.ARROW_DOWN", keypress })
|
|
194
193
|
event.preventDefault()
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
send({ type: "INPUT.END", keypress })
|
|
200
|
-
if (open) {
|
|
194
|
+
},
|
|
195
|
+
ArrowUp() {
|
|
196
|
+
if (!openOnKeyPress && !open) return
|
|
197
|
+
send({ type: event.altKey ? "CLOSE" : "INPUT.ARROW_UP", keypress })
|
|
201
198
|
event.preventDefault()
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
},
|
|
200
|
+
Home(event) {
|
|
201
|
+
if (isModifierKey) return
|
|
202
|
+
send({ type: "INPUT.HOME", keypress })
|
|
203
|
+
if (open) {
|
|
204
|
+
event.preventDefault()
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
End(event) {
|
|
208
|
+
if (isModifierKey) return
|
|
209
|
+
send({ type: "INPUT.END", keypress })
|
|
210
|
+
if (open) {
|
|
211
|
+
event.preventDefault()
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
Enter(event) {
|
|
215
|
+
send({ type: "INPUT.ENTER", keypress })
|
|
216
|
+
if (open) {
|
|
217
|
+
event.preventDefault()
|
|
218
|
+
}
|
|
219
|
+
const itemEl = dom.getHighlightedItemEl(state.context)
|
|
220
|
+
clickIfLink(itemEl)
|
|
221
|
+
},
|
|
222
|
+
Escape() {
|
|
223
|
+
send({ type: "INPUT.ESCAPE", keypress })
|
|
207
224
|
event.preventDefault()
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
clickIfLink(itemEl)
|
|
211
|
-
},
|
|
212
|
-
Escape() {
|
|
213
|
-
send({ type: "INPUT.ESCAPE", keypress })
|
|
214
|
-
event.preventDefault()
|
|
215
|
-
},
|
|
216
|
-
}
|
|
225
|
+
},
|
|
226
|
+
}
|
|
217
227
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
const key = getEventKey(event, state.context)
|
|
229
|
+
const exec = keymap[key]
|
|
230
|
+
exec?.(event)
|
|
231
|
+
},
|
|
232
|
+
})
|
|
233
|
+
},
|
|
223
234
|
|
|
224
235
|
getTriggerProps(props = {}) {
|
|
225
236
|
return normalize.button({
|
|
@@ -279,47 +290,53 @@ export function connect<T extends PropTypes, V extends CollectionItem>(
|
|
|
279
290
|
})
|
|
280
291
|
},
|
|
281
292
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
293
|
+
getContentProps() {
|
|
294
|
+
return normalize.element({
|
|
295
|
+
...parts.content.attrs,
|
|
296
|
+
dir: state.context.dir,
|
|
297
|
+
id: dom.getContentId(state.context),
|
|
298
|
+
role: !composite ? "dialog" : "listbox",
|
|
299
|
+
tabIndex: -1,
|
|
300
|
+
hidden: !open,
|
|
301
|
+
"data-state": open ? "open" : "closed",
|
|
302
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
303
|
+
"aria-multiselectable": state.context.multiple && composite ? true : undefined,
|
|
304
|
+
onPointerDown(event) {
|
|
305
|
+
// prevent options or elements within listbox from taking focus
|
|
306
|
+
event.preventDefault()
|
|
307
|
+
},
|
|
308
|
+
})
|
|
309
|
+
},
|
|
297
310
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
311
|
+
getListProps() {
|
|
312
|
+
return normalize.element({
|
|
313
|
+
role: !composite ? "listbox" : undefined,
|
|
314
|
+
"aria-labelledby": dom.getLabelId(state.context),
|
|
315
|
+
"aria-multiselectable": state.context.multiple && !composite ? true : undefined,
|
|
316
|
+
})
|
|
317
|
+
},
|
|
303
318
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
event
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
getClearTriggerProps() {
|
|
320
|
+
return normalize.button({
|
|
321
|
+
...parts.clearTrigger.attrs,
|
|
322
|
+
dir: state.context.dir,
|
|
323
|
+
id: dom.getClearTriggerId(state.context),
|
|
324
|
+
type: "button",
|
|
325
|
+
tabIndex: -1,
|
|
326
|
+
disabled: disabled,
|
|
327
|
+
"aria-label": translations.clearTriggerLabel,
|
|
328
|
+
"aria-controls": dom.getInputId(state.context),
|
|
329
|
+
hidden: !state.context.value.length,
|
|
330
|
+
onPointerDown(event) {
|
|
331
|
+
event.preventDefault()
|
|
332
|
+
},
|
|
333
|
+
onClick(event) {
|
|
334
|
+
if (event.defaultPrevented) return
|
|
335
|
+
if (!interactive) return
|
|
336
|
+
send({ type: "VALUE.CLEAR", src: "clear-trigger" })
|
|
337
|
+
},
|
|
338
|
+
})
|
|
339
|
+
},
|
|
323
340
|
|
|
324
341
|
getItemState,
|
|
325
342
|
|
package/src/combobox.types.ts
CHANGED
|
@@ -411,15 +411,15 @@ export interface MachineApi<T extends PropTypes = PropTypes, V extends Collectio
|
|
|
411
411
|
*/
|
|
412
412
|
reposition(options?: Partial<PositioningOptions>): void
|
|
413
413
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
414
|
+
getRootProps(): T["element"]
|
|
415
|
+
getLabelProps(): T["label"]
|
|
416
|
+
getControlProps(): T["element"]
|
|
417
|
+
getPositionerProps(): T["element"]
|
|
418
|
+
getInputProps(): T["input"]
|
|
419
|
+
getContentProps(): T["element"]
|
|
420
420
|
getTriggerProps(props?: TriggerProps): T["button"]
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
getClearTriggerProps(): T["button"]
|
|
422
|
+
getListProps(): T["element"]
|
|
423
423
|
getItemProps(props: ItemProps): T["element"]
|
|
424
424
|
getItemTextProps(props: ItemProps): T["element"]
|
|
425
425
|
getItemIndicatorProps(props: ItemProps): T["element"]
|