@zag-js/number-input 0.53.0 → 0.55.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 +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +871 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +842 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/number-input.connect.ts +199 -185
- package/src/number-input.types.ts +7 -7
|
@@ -47,194 +47,208 @@ export function connect<T extends PropTypes>(state: State, send: Send, normalize
|
|
|
47
47
|
dom.getInputEl(state.context)?.focus()
|
|
48
48
|
},
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
50
|
+
getRootProps() {
|
|
51
|
+
return normalize.element({
|
|
52
|
+
id: dom.getRootId(state.context),
|
|
53
|
+
...parts.root.attrs,
|
|
54
|
+
dir: state.context.dir,
|
|
55
|
+
"data-disabled": dataAttr(disabled),
|
|
56
|
+
"data-focus": dataAttr(focused),
|
|
57
|
+
"data-invalid": dataAttr(invalid),
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
getLabelProps() {
|
|
62
|
+
return normalize.label({
|
|
63
|
+
...parts.label.attrs,
|
|
64
|
+
dir: state.context.dir,
|
|
65
|
+
"data-disabled": dataAttr(disabled),
|
|
66
|
+
"data-focus": dataAttr(focused),
|
|
67
|
+
"data-invalid": dataAttr(invalid),
|
|
68
|
+
id: dom.getLabelId(state.context),
|
|
69
|
+
htmlFor: dom.getInputId(state.context),
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
getControlProps() {
|
|
74
|
+
return normalize.element({
|
|
75
|
+
...parts.control.attrs,
|
|
76
|
+
dir: state.context.dir,
|
|
77
|
+
role: "group",
|
|
78
|
+
"aria-disabled": disabled,
|
|
79
|
+
"data-focus": dataAttr(focused),
|
|
80
|
+
"data-disabled": dataAttr(disabled),
|
|
81
|
+
"data-invalid": dataAttr(invalid),
|
|
82
|
+
"aria-invalid": ariaAttr(state.context.invalid),
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
getInputProps() {
|
|
87
|
+
return normalize.input({
|
|
88
|
+
...parts.input.attrs,
|
|
89
|
+
dir: state.context.dir,
|
|
90
|
+
name: state.context.name,
|
|
91
|
+
form: state.context.form,
|
|
92
|
+
id: dom.getInputId(state.context),
|
|
93
|
+
role: "spinbutton",
|
|
94
|
+
defaultValue: state.context.formattedValue,
|
|
95
|
+
pattern: state.context.pattern,
|
|
96
|
+
inputMode: state.context.inputMode,
|
|
97
|
+
"aria-invalid": ariaAttr(invalid),
|
|
98
|
+
"data-invalid": dataAttr(invalid),
|
|
99
|
+
disabled: disabled,
|
|
100
|
+
"data-disabled": dataAttr(disabled),
|
|
101
|
+
readOnly: !!state.context.readOnly,
|
|
102
|
+
autoComplete: "off",
|
|
103
|
+
autoCorrect: "off",
|
|
104
|
+
spellCheck: "false",
|
|
105
|
+
type: "text",
|
|
106
|
+
"aria-roledescription": "numberfield",
|
|
107
|
+
"aria-valuemin": state.context.min,
|
|
108
|
+
"aria-valuemax": state.context.max,
|
|
109
|
+
"aria-valuenow": Number.isNaN(state.context.valueAsNumber) ? undefined : state.context.valueAsNumber,
|
|
110
|
+
"aria-valuetext": state.context.valueText,
|
|
111
|
+
onFocus() {
|
|
112
|
+
send("INPUT.FOCUS")
|
|
113
|
+
},
|
|
114
|
+
onBlur() {
|
|
115
|
+
send({ type: "INPUT.COMMIT", src: "blur" })
|
|
116
|
+
},
|
|
117
|
+
onChange(event) {
|
|
118
|
+
send({ type: "INPUT.CHANGE", target: event.currentTarget, hint: "set" })
|
|
119
|
+
},
|
|
120
|
+
onBeforeInput(event) {
|
|
121
|
+
try {
|
|
122
|
+
const { selectionStart, selectionEnd, value } = event.currentTarget
|
|
123
|
+
|
|
124
|
+
const nextValue = value.slice(0, selectionStart!) + ((event as any).data ?? "") + value.slice(selectionEnd!)
|
|
125
|
+
const isValid = state.context.parser.isValidPartialNumber(nextValue)
|
|
126
|
+
|
|
127
|
+
if (!isValid) {
|
|
128
|
+
event.preventDefault()
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// noop
|
|
122
132
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
133
|
+
},
|
|
134
|
+
onKeyDown(event) {
|
|
135
|
+
if (event.defaultPrevented) return
|
|
136
|
+
if (readOnly) return
|
|
137
|
+
if (isComposingEvent(event)) return
|
|
138
|
+
|
|
139
|
+
const step = getEventStep(event) * state.context.step
|
|
140
|
+
|
|
141
|
+
const keyMap: EventKeyMap = {
|
|
142
|
+
ArrowUp() {
|
|
143
|
+
send({ type: "INPUT.ARROW_UP", step })
|
|
144
|
+
event.preventDefault()
|
|
145
|
+
},
|
|
146
|
+
ArrowDown() {
|
|
147
|
+
send({ type: "INPUT.ARROW_DOWN", step })
|
|
148
|
+
event.preventDefault()
|
|
149
|
+
},
|
|
150
|
+
Home() {
|
|
151
|
+
send("INPUT.HOME")
|
|
152
|
+
event.preventDefault()
|
|
153
|
+
},
|
|
154
|
+
End() {
|
|
155
|
+
send("INPUT.END")
|
|
156
|
+
event.preventDefault()
|
|
157
|
+
},
|
|
158
|
+
Enter() {
|
|
159
|
+
send({ type: "INPUT.COMMIT", src: "enter" })
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const exec = keyMap[event.key]
|
|
164
|
+
exec?.(event)
|
|
165
|
+
},
|
|
166
|
+
})
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
getDecrementTriggerProps() {
|
|
170
|
+
return normalize.button({
|
|
171
|
+
...parts.decrementTrigger.attrs,
|
|
172
|
+
dir: state.context.dir,
|
|
173
|
+
id: dom.getDecrementTriggerId(state.context),
|
|
174
|
+
disabled: isDecrementDisabled,
|
|
175
|
+
"data-disabled": dataAttr(isDecrementDisabled),
|
|
176
|
+
"aria-label": translations.decrementLabel,
|
|
177
|
+
type: "button",
|
|
178
|
+
tabIndex: -1,
|
|
179
|
+
"aria-controls": dom.getInputId(state.context),
|
|
180
|
+
onPointerDown(event) {
|
|
181
|
+
if (isDecrementDisabled || !isLeftClick(event)) return
|
|
182
|
+
send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType })
|
|
183
|
+
if (event.pointerType === "mouse") {
|
|
145
184
|
event.preventDefault()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
185
|
+
}
|
|
186
|
+
if (event.pointerType === "touch") {
|
|
187
|
+
event.currentTarget?.focus({ preventScroll: true })
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
onPointerUp(event) {
|
|
191
|
+
send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType })
|
|
192
|
+
},
|
|
193
|
+
onPointerLeave() {
|
|
194
|
+
if (isDecrementDisabled) return
|
|
195
|
+
send({ type: "TRIGGER.PRESS_UP", hint: "decrement" })
|
|
196
|
+
},
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
getIncrementTriggerProps() {
|
|
201
|
+
return normalize.button({
|
|
202
|
+
...parts.incrementTrigger.attrs,
|
|
203
|
+
dir: state.context.dir,
|
|
204
|
+
id: dom.getIncrementTriggerId(state.context),
|
|
205
|
+
disabled: isIncrementDisabled,
|
|
206
|
+
"data-disabled": dataAttr(isIncrementDisabled),
|
|
207
|
+
"aria-label": translations.incrementLabel,
|
|
208
|
+
type: "button",
|
|
209
|
+
tabIndex: -1,
|
|
210
|
+
"aria-controls": dom.getInputId(state.context),
|
|
211
|
+
onPointerDown(event) {
|
|
212
|
+
if (isIncrementDisabled || !isLeftClick(event)) return
|
|
213
|
+
send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType })
|
|
214
|
+
if (event.pointerType === "mouse") {
|
|
149
215
|
event.preventDefault()
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
},
|
|
181
|
-
onPointerUp(event) {
|
|
182
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType })
|
|
183
|
-
},
|
|
184
|
-
onPointerLeave() {
|
|
185
|
-
if (isDecrementDisabled) return
|
|
186
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "decrement" })
|
|
187
|
-
},
|
|
188
|
-
}),
|
|
189
|
-
|
|
190
|
-
incrementTriggerProps: normalize.button({
|
|
191
|
-
...parts.incrementTrigger.attrs,
|
|
192
|
-
dir: state.context.dir,
|
|
193
|
-
id: dom.getIncrementTriggerId(state.context),
|
|
194
|
-
disabled: isIncrementDisabled,
|
|
195
|
-
"data-disabled": dataAttr(isIncrementDisabled),
|
|
196
|
-
"aria-label": translations.incrementLabel,
|
|
197
|
-
type: "button",
|
|
198
|
-
tabIndex: -1,
|
|
199
|
-
"aria-controls": dom.getInputId(state.context),
|
|
200
|
-
onPointerDown(event) {
|
|
201
|
-
if (isIncrementDisabled || !isLeftClick(event)) return
|
|
202
|
-
send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType })
|
|
203
|
-
if (event.pointerType === "mouse") {
|
|
216
|
+
}
|
|
217
|
+
if (event.pointerType === "touch") {
|
|
218
|
+
event.currentTarget?.focus({ preventScroll: true })
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
onPointerUp(event) {
|
|
222
|
+
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType })
|
|
223
|
+
},
|
|
224
|
+
onPointerLeave(event) {
|
|
225
|
+
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType })
|
|
226
|
+
},
|
|
227
|
+
})
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
getScrubberProps() {
|
|
231
|
+
return normalize.element({
|
|
232
|
+
...parts.scrubber.attrs,
|
|
233
|
+
dir: state.context.dir,
|
|
234
|
+
"data-disabled": dataAttr(disabled),
|
|
235
|
+
id: dom.getScrubberId(state.context),
|
|
236
|
+
role: "presentation",
|
|
237
|
+
onMouseDown(event) {
|
|
238
|
+
if (disabled) return
|
|
239
|
+
|
|
240
|
+
const point = getEventPoint(event)
|
|
241
|
+
|
|
242
|
+
point.x = point.x - roundToDevicePixel(7.5)
|
|
243
|
+
point.y = point.y - roundToDevicePixel(7.5)
|
|
244
|
+
|
|
245
|
+
send({ type: "SCRUBBER.PRESS_DOWN", point })
|
|
204
246
|
event.preventDefault()
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType })
|
|
212
|
-
},
|
|
213
|
-
onPointerLeave(event) {
|
|
214
|
-
send({ type: "TRIGGER.PRESS_UP", hint: "increment", pointerType: event.pointerType })
|
|
215
|
-
},
|
|
216
|
-
}),
|
|
217
|
-
|
|
218
|
-
scrubberProps: normalize.element({
|
|
219
|
-
...parts.scrubber.attrs,
|
|
220
|
-
dir: state.context.dir,
|
|
221
|
-
"data-disabled": dataAttr(disabled),
|
|
222
|
-
id: dom.getScrubberId(state.context),
|
|
223
|
-
role: "presentation",
|
|
224
|
-
onMouseDown(event) {
|
|
225
|
-
if (disabled) return
|
|
226
|
-
|
|
227
|
-
const point = getEventPoint(event)
|
|
228
|
-
|
|
229
|
-
point.x = point.x - roundToDevicePixel(7.5)
|
|
230
|
-
point.y = point.y - roundToDevicePixel(7.5)
|
|
231
|
-
|
|
232
|
-
send({ type: "SCRUBBER.PRESS_DOWN", point })
|
|
233
|
-
event.preventDefault()
|
|
234
|
-
},
|
|
235
|
-
style: {
|
|
236
|
-
cursor: disabled ? undefined : "ew-resize",
|
|
237
|
-
},
|
|
238
|
-
}),
|
|
247
|
+
},
|
|
248
|
+
style: {
|
|
249
|
+
cursor: disabled ? undefined : "ew-resize",
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
},
|
|
239
253
|
}
|
|
240
254
|
}
|
|
@@ -307,11 +307,11 @@ export interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
307
307
|
*/
|
|
308
308
|
focus(): void
|
|
309
309
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
310
|
+
getRootProps(): T["element"]
|
|
311
|
+
getLabelProps(): T["label"]
|
|
312
|
+
getControlProps(): T["element"]
|
|
313
|
+
getInputProps(): T["input"]
|
|
314
|
+
getDecrementTriggerProps(): T["button"]
|
|
315
|
+
getIncrementTriggerProps(): T["button"]
|
|
316
|
+
getScrubberProps(): T["element"]
|
|
317
317
|
}
|