menhir 0.1.14 → 0.1.15
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/autocomplete/input/AutocompleteInput.js +5 -2
- package/dist/checkbox-group/root/CheckboxGroupRoot.js +3 -8
- package/dist/combobox/input/ComboboxInput.js +6 -2
- package/dist/combobox/input/createComboboxInput.js +2 -17
- package/dist/core/formReset.js +70 -0
- package/dist/core/hiddenInput.js +9 -12
- package/dist/field/root/FieldRoot.js +4 -6
- package/dist/form/Form.js +5 -7
- package/dist/input/root/InputRoot.js +14 -23
- package/dist/number-field/root/NumberFieldRoot.js +7 -17
- package/dist/select/trigger/SelectTrigger.js +7 -10
- package/dist/slider/root/SliderRoot.js +12 -22
- package/dist/source/autocomplete/input/AutocompleteInput.jsx +9 -2
- package/dist/source/checkbox-group/root/CheckboxGroupRoot.jsx +3 -9
- package/dist/source/combobox/input/ComboboxInput.jsx +10 -2
- package/dist/source/combobox/input/createComboboxInput.d.ts +0 -8
- package/dist/source/combobox/input/createComboboxInput.js +1 -17
- package/dist/source/core/formReset.d.ts +42 -0
- package/dist/source/core/formReset.js +74 -0
- package/dist/source/core/hiddenInput.d.ts +2 -2
- package/dist/source/core/hiddenInput.jsx +11 -16
- package/dist/source/field/root/FieldRoot.jsx +10 -12
- package/dist/source/form/Form.jsx +9 -10
- package/dist/source/input/root/InputRoot.jsx +19 -33
- package/dist/source/number-field/root/NumberFieldRoot.jsx +9 -25
- package/dist/source/select/trigger/SelectTrigger.jsx +9 -13
- package/dist/source/slider/root/SliderRoot.jsx +16 -32
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
|
-
import { createComboboxInput
|
|
4
|
+
import { createComboboxInput } from "../../combobox/input/createComboboxInput.js";
|
|
4
5
|
import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
5
6
|
import { spread, template } from "@solidjs/web";
|
|
6
7
|
import { merge, omit, onFlush } from "solid-js";
|
|
@@ -17,12 +18,14 @@ var _tmpl$ = /* @__PURE__ */ template(`<input>`);
|
|
|
17
18
|
function AutocompleteInput(props) {
|
|
18
19
|
const autocomplete = useComboboxContext("Autocomplete");
|
|
19
20
|
const input = createComboboxInput(autocomplete);
|
|
20
|
-
onFormReset(() => autocomplete.input, (event) => {
|
|
21
|
+
onFormReset(() => autocomplete.input?.form, (event) => {
|
|
21
22
|
autocomplete.setInputValue(autocomplete.props.defaultValue ?? "", {
|
|
22
23
|
reason: "reset",
|
|
23
24
|
event
|
|
24
25
|
});
|
|
25
26
|
onFlush(input.syncText);
|
|
27
|
+
}, () => {
|
|
28
|
+
autocomplete.input.defaultValue = autocomplete.input.value;
|
|
26
29
|
});
|
|
27
30
|
const ownProps = merge(input.props, {
|
|
28
31
|
get name() {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
|
|
5
6
|
import { createComponent, effect, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createUniqueId, omit
|
|
7
|
+
import { createUniqueId, omit } from "solid-js";
|
|
7
8
|
// src/checkbox-group/root/CheckboxGroupRoot.tsx
|
|
8
9
|
var _tmpl$ = /* @__PURE__ */ template(`<input type=radio 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
10
|
var _tmpl$2 = /* @__PURE__ */ template(`<fieldset>`);
|
|
@@ -32,13 +33,7 @@ function CheckboxGroupRoot(props) {
|
|
|
32
33
|
const validityName = createUniqueId();
|
|
33
34
|
let root;
|
|
34
35
|
let input;
|
|
35
|
-
|
|
36
|
-
const form = input?.form;
|
|
37
|
-
if (!form) return;
|
|
38
|
-
const onReset = () => setValue(props.defaultValue ?? []);
|
|
39
|
-
form.addEventListener("reset", onReset);
|
|
40
|
-
return () => form.removeEventListener("reset", onReset);
|
|
41
|
-
});
|
|
36
|
+
onFormReset(() => input?.form, () => setValue(props.defaultValue ?? []));
|
|
42
37
|
const elementProps = mergeElementProps({
|
|
43
38
|
get disabled() {
|
|
44
39
|
return props.disabled;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
4
|
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
4
|
-
import { createComboboxInput
|
|
5
|
+
import { createComboboxInput } from "./createComboboxInput.js";
|
|
5
6
|
import { effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
7
|
import { omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/combobox/input/ComboboxInput.tsx
|
|
@@ -27,7 +28,7 @@ function ComboboxInput(props) {
|
|
|
27
28
|
const syncHidden = () => {
|
|
28
29
|
if (hiddenInput) hiddenInput.value = untrack(combobox.value) ?? "";
|
|
29
30
|
};
|
|
30
|
-
onFormReset(() => hiddenInput, (event) => {
|
|
31
|
+
onFormReset(() => hiddenInput?.form, (event) => {
|
|
31
32
|
const value = combobox.props.defaultValue ?? null;
|
|
32
33
|
combobox.setValue(value);
|
|
33
34
|
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", {
|
|
@@ -38,6 +39,9 @@ function ComboboxInput(props) {
|
|
|
38
39
|
syncHidden();
|
|
39
40
|
input.syncText();
|
|
40
41
|
});
|
|
42
|
+
}, () => {
|
|
43
|
+
combobox.input.defaultValue = combobox.input.value;
|
|
44
|
+
hiddenInput.defaultValue = hiddenInput.value;
|
|
41
45
|
});
|
|
42
46
|
const elementProps = mergeElementProps(input.props, omit(props, "render"));
|
|
43
47
|
return [memo(() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSignal, merge, onFlush,
|
|
1
|
+
import { createSignal, merge, onFlush, untrack } from "solid-js";
|
|
2
2
|
// src/combobox/input/createComboboxInput.ts
|
|
3
3
|
/**
|
|
4
4
|
* The input of a combobox, the code `Combobox.Input` and
|
|
@@ -94,19 +94,4 @@ function createComboboxInput(combobox, onFocusOut) {
|
|
|
94
94
|
syncText
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
* Calls `reset` when the form of `input()` is reset, from the time the
|
|
99
|
-
* part has settled: a form reset puts a control back to its default, and
|
|
100
|
-
* so it does a combobox, through its setters, so that a controlled one
|
|
101
|
-
* asks. The browser resets the form's inputs after the event, to their
|
|
102
|
-
* `value` attributes; an `onFlush` in `reset` runs after that.
|
|
103
|
-
*/
|
|
104
|
-
function onFormReset(input, reset) {
|
|
105
|
-
onSettled(() => {
|
|
106
|
-
const form = input()?.form;
|
|
107
|
-
if (!form) return;
|
|
108
|
-
form.addEventListener("reset", reset);
|
|
109
|
-
return () => form.removeEventListener("reset", reset);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
export { createComboboxInput, onFormReset };
|
|
97
|
+
export { createComboboxInput };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { onSettled } from "solid-js";
|
|
2
|
+
// src/core/formReset.ts
|
|
3
|
+
var answers;
|
|
4
|
+
/**
|
|
5
|
+
* A form reset puts a native control back to its default, and so it does a
|
|
6
|
+
* part: `reset` asks for the part's default, through its setters, so that a
|
|
7
|
+
* controlled part asks. Listens to `form()`, read once the part has settled.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* onFormReset(
|
|
11
|
+
* () => input?.form,
|
|
12
|
+
* () => {
|
|
13
|
+
* setChecked(props.defaultChecked ?? false);
|
|
14
|
+
* onFlush(sync);
|
|
15
|
+
* },
|
|
16
|
+
* () => {
|
|
17
|
+
* input!.defaultChecked = input!.checked;
|
|
18
|
+
* },
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* - `hold` runs during the event, before the browser resets the controls,
|
|
23
|
+
* and what it returns is `reset`'s second argument. A part whose state
|
|
24
|
+
* is its own, not the element's, makes each element's state there the
|
|
25
|
+
* attribute the browser resets it to (`defaultChecked`, `defaultValue`),
|
|
26
|
+
* so the reset leaves it as it is: it never shows a state the part does
|
|
27
|
+
* not hold, and a binding that re-runs before `reset`, such as a Field's
|
|
28
|
+
* `data-touched` as the touched state clears, does not write its value
|
|
29
|
+
* back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
|
|
30
|
+
* part writes its own, a line, so no part pays for another's.
|
|
31
|
+
* - `reset` runs in a task after the event, not in `onFlush`: when the user
|
|
32
|
+
* presses a reset button, the browser runs microtasks as each listener
|
|
33
|
+
* returns, before it resets the controls and before later listeners
|
|
34
|
+
* could cancel the reset (src/input/README.md, "A form reset asks").
|
|
35
|
+
* Every part's `reset` runs in the same task, in the order the parts
|
|
36
|
+
* listened, so a set equal to one made before it in the task
|
|
37
|
+
* does nothing (`createControllableSignal`), and a Field, which listens
|
|
38
|
+
* before the controls inside it, reads them in an `onFlush` after theirs.
|
|
39
|
+
* - A reset the app cancels asks for nothing: the reset is the event's
|
|
40
|
+
* default action, so its `defaultPrevented` is the app saying no.
|
|
41
|
+
* - A part the reset removes before the task, such as a row of a list
|
|
42
|
+
* going back to its default length, asks for nothing, so it does not
|
|
43
|
+
* write its row back.
|
|
44
|
+
*/
|
|
45
|
+
function onFormReset(form, reset, hold) {
|
|
46
|
+
onSettled(() => {
|
|
47
|
+
const target = form();
|
|
48
|
+
if (!target) return;
|
|
49
|
+
let disposed = false;
|
|
50
|
+
const onReset = (event) => {
|
|
51
|
+
const held = hold?.();
|
|
52
|
+
if (!answers) {
|
|
53
|
+
const queue = answers = [];
|
|
54
|
+
setTimeout(() => {
|
|
55
|
+
answers = void 0;
|
|
56
|
+
for (const answer of queue) answer();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
answers.push(() => {
|
|
60
|
+
if (!disposed && !event.defaultPrevented) reset(event, held);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
target.addEventListener("reset", onReset);
|
|
64
|
+
return () => {
|
|
65
|
+
disposed = true;
|
|
66
|
+
target.removeEventListener("reset", onReset);
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export { onFormReset };
|
package/dist/core/hiddenInput.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { onFormReset } from "./formReset.js";
|
|
1
2
|
import { effect, heldRead, ref, setAttribute, setProperty, template } from "@solidjs/web";
|
|
2
|
-
import { onFlush,
|
|
3
|
+
import { onFlush, untrack } from "solid-js";
|
|
3
4
|
// src/core/hiddenInput.tsx
|
|
4
5
|
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>`);
|
|
5
6
|
/**
|
|
@@ -28,8 +29,8 @@ var _tmpl$ = /* @__PURE__ */ template(`<input aria-hidden=true tabindex=-1 style
|
|
|
28
29
|
* - `button` is where focus goes when the browser focuses the input, as it
|
|
29
30
|
* does when it blocks a submission.
|
|
30
31
|
* - `reset` asks for the control's default on a form reset, through the
|
|
31
|
-
* setter, so that a controlled control asks. A Radio's
|
|
32
|
-
* the group, which asks once.
|
|
32
|
+
* setter, so that a controlled control asks (`onFormReset`). A Radio's
|
|
33
|
+
* Items each ask the group, which asks once.
|
|
33
34
|
*
|
|
34
35
|
* A plain function with positional parameters, not a component with props:
|
|
35
36
|
* a component would wrap each prop in a getter, and an options object
|
|
@@ -46,15 +47,11 @@ function createHiddenInput(type, props, checked, setChecked, button, reset) {
|
|
|
46
47
|
event.stopPropagation();
|
|
47
48
|
if (props.readOnly) event.preventDefault();
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
onFlush(sync);
|
|
55
|
-
};
|
|
56
|
-
form.addEventListener("reset", onReset);
|
|
57
|
-
return () => form.removeEventListener("reset", onReset);
|
|
50
|
+
onFormReset(() => input?.form, () => {
|
|
51
|
+
reset();
|
|
52
|
+
onFlush(sync);
|
|
53
|
+
}, () => {
|
|
54
|
+
input.defaultChecked = input.checked;
|
|
58
55
|
});
|
|
59
56
|
return (() => {
|
|
60
57
|
var _el$ = _tmpl$();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormContext } from "../../core/formContext.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { FieldRootContext } from "./FieldRootContext.js";
|
|
@@ -79,22 +80,19 @@ function FieldRoot(props) {
|
|
|
79
80
|
attributes
|
|
80
81
|
};
|
|
81
82
|
const touch = () => update(true);
|
|
83
|
+
const findForm = () => root?.querySelector(controlSelector)?.form ?? root?.closest("form");
|
|
82
84
|
onSettled(() => {
|
|
83
85
|
setSettled(true);
|
|
84
|
-
const form =
|
|
86
|
+
const form = findForm();
|
|
85
87
|
if (!form) return;
|
|
86
|
-
const onReset = (event) => onFlush(() => {
|
|
87
|
-
if (!event.defaultPrevented) update(false);
|
|
88
|
-
});
|
|
89
88
|
form.addEventListener("submit", touch);
|
|
90
89
|
form.addEventListener("invalid", touch, true);
|
|
91
|
-
form.addEventListener("reset", onReset);
|
|
92
90
|
return () => {
|
|
93
91
|
form.removeEventListener("submit", touch);
|
|
94
92
|
form.removeEventListener("invalid", touch, true);
|
|
95
|
-
form.removeEventListener("reset", onReset);
|
|
96
93
|
};
|
|
97
94
|
});
|
|
95
|
+
onFormReset(findForm, () => onFlush(() => update(false)));
|
|
98
96
|
const ownProps = merge(attributes, {
|
|
99
97
|
onFocusOut: (event) => {
|
|
100
98
|
const to = event.relatedTarget;
|
package/dist/form/Form.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FormContext } from "../core/formContext.js";
|
|
2
|
+
import { onFormReset } from "../core/formReset.js";
|
|
2
3
|
import { callHandler, mergeElementProps } from "../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../core/renderElement.js";
|
|
4
5
|
import { createComponent, spread, template } from "@solidjs/web";
|
|
@@ -22,12 +23,9 @@ function Form(props) {
|
|
|
22
23
|
const names = hidden();
|
|
23
24
|
return current && names !== true && !names.has(name) && Object.hasOwn(current, name) ? current[name] : void 0;
|
|
24
25
|
} };
|
|
25
|
-
const hide = (update) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (untrack(errors) === met) setHidden((names) => names === true ? names : update(names));
|
|
29
|
-
});
|
|
30
|
-
};
|
|
26
|
+
const hide = (update, met = untrack(errors)) => onFlush(() => {
|
|
27
|
+
if (untrack(errors) === met) setHidden((names) => names === true ? names : update(names));
|
|
28
|
+
});
|
|
31
29
|
const hideError = (event) => {
|
|
32
30
|
const name = event.target.name;
|
|
33
31
|
if (name) hide((names) => new Set(names).add(name));
|
|
@@ -36,10 +34,10 @@ function Form(props) {
|
|
|
36
34
|
onSettled(() => {
|
|
37
35
|
if (form) form.noValidate = true;
|
|
38
36
|
});
|
|
37
|
+
onFormReset(() => form, (_, met) => hide(() => true, met), () => untrack(errors));
|
|
39
38
|
const ownProps = {
|
|
40
39
|
onInput: hideError,
|
|
41
40
|
onChange: hideError,
|
|
42
|
-
onReset: (event) => hide((names) => event.defaultPrevented ? names : true),
|
|
43
41
|
onSubmit: (event) => {
|
|
44
42
|
if (!event.submitter?.formNoValidate && !form.checkValidity()) {
|
|
45
43
|
event.preventDefault();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
1
2
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
2
3
|
import { renderElement } from "../../core/renderElement.js";
|
|
3
4
|
import { spread, template } from "@solidjs/web";
|
|
4
|
-
import { merge, omit, onFlush,
|
|
5
|
+
import { merge, omit, onFlush, untrack } from "solid-js";
|
|
5
6
|
// src/input/root/InputRoot.tsx
|
|
6
7
|
var _tmpl$ = /* @__PURE__ */ template(`<input>`);
|
|
7
8
|
/**
|
|
@@ -14,28 +15,18 @@ function InputRoot(props) {
|
|
|
14
15
|
const value = untrack(() => props.value);
|
|
15
16
|
if (element && value !== void 0 && element.value !== value) element.value = value;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
event
|
|
30
|
-
});
|
|
31
|
-
onFlush(restoreValue);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
form.addEventListener("reset", onReset);
|
|
35
|
-
return () => {
|
|
36
|
-
disposed = true;
|
|
37
|
-
form.removeEventListener("reset", onReset);
|
|
38
|
-
};
|
|
18
|
+
onFormReset(() => element?.form, (event, text) => {
|
|
19
|
+
const defaultText = untrack(() => props.defaultValue) ?? "";
|
|
20
|
+
if (text === defaultText) return;
|
|
21
|
+
props.onValueChange?.(defaultText, {
|
|
22
|
+
reason: "reset",
|
|
23
|
+
event
|
|
24
|
+
});
|
|
25
|
+
onFlush(restoreValue);
|
|
26
|
+
}, () => {
|
|
27
|
+
const text = element.value;
|
|
28
|
+
if (untrack(() => props.value) !== void 0) element.defaultValue = text;
|
|
29
|
+
return text;
|
|
39
30
|
});
|
|
40
31
|
const elementProps = merge(mergeElementProps({
|
|
41
32
|
onInput: (event) => {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { parseNumber } from "../parse.js";
|
|
5
6
|
import { NumberFieldRootContext } from "./NumberFieldRootContext.js";
|
|
6
7
|
import { createComponent, effect, heldRead, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
7
|
-
import { createMemo, createUniqueId, omit, onFlush,
|
|
8
|
+
import { createMemo, createUniqueId, omit, onFlush, untrack } from "solid-js";
|
|
8
9
|
// src/number-field/root/NumberFieldRoot.tsx
|
|
9
10
|
var _tmpl$ = /* @__PURE__ */ template(`<input type=number 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>`);
|
|
10
11
|
var _tmpl$2 = /* @__PURE__ */ template(`<div>`);
|
|
@@ -102,22 +103,11 @@ function NumberFieldRoot(props) {
|
|
|
102
103
|
change(roundAndClamp(parsed, options.maximumFractionDigits + (options.style === "percent" ? 2 : 0)));
|
|
103
104
|
}
|
|
104
105
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
if (disposed || event.defaultPrevented) return;
|
|
112
|
-
setValue(props.defaultValue ?? null);
|
|
113
|
-
onFlush(sync);
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
form.addEventListener("reset", onReset);
|
|
117
|
-
return () => {
|
|
118
|
-
disposed = true;
|
|
119
|
-
form.removeEventListener("reset", onReset);
|
|
120
|
-
};
|
|
106
|
+
onFormReset(() => hidden?.form, () => {
|
|
107
|
+
setValue(props.defaultValue ?? null);
|
|
108
|
+
onFlush(sync);
|
|
109
|
+
}, () => {
|
|
110
|
+
hidden.defaultValue = hidden.value;
|
|
121
111
|
});
|
|
122
112
|
const elementProps = mergeElementProps(context.attributes, omit(props, "render", "value", "defaultValue", "onValueChange", "min", "max", "step", "largeStep", "format", "locale", "name", "form", "required", "disabled", "readOnly", "id", "aria-describedby", "aria-invalid"));
|
|
123
113
|
return createComponent(NumberFieldRootContext, {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { warnUnlessButton } from "../../core/button.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { useSelectContext } from "../root/SelectContext.js";
|
|
5
6
|
import { effect, heldRead, isDev, memo, ref, setAttribute, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createUniqueId, merge, omit, onFlush,
|
|
7
|
+
import { createUniqueId, merge, omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/select/trigger/SelectTrigger.tsx
|
|
8
9
|
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
10
|
var _tmpl$2 = /* @__PURE__ */ template(`<button>`);
|
|
@@ -112,15 +113,11 @@ function SelectTrigger(props) {
|
|
|
112
113
|
else if (!filled) select.setValue(null);
|
|
113
114
|
onFlush(syncInput);
|
|
114
115
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
onFlush(syncInput);
|
|
121
|
-
};
|
|
122
|
-
form.addEventListener("reset", onReset);
|
|
123
|
-
return () => form.removeEventListener("reset", onReset);
|
|
116
|
+
onFormReset(() => input?.form, () => {
|
|
117
|
+
select.setValue(select.props.defaultValue ?? null);
|
|
118
|
+
onFlush(syncInput);
|
|
119
|
+
}, () => {
|
|
120
|
+
input.defaultValue = input.value;
|
|
124
121
|
});
|
|
125
122
|
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
126
123
|
return [memo(() => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.js";
|
|
4
5
|
import { SliderRootContext } from "./SliderRootContext.js";
|
|
5
6
|
import { createComponent, spread, template } from "@solidjs/web";
|
|
6
|
-
import { createMemo, merge, omit, onFlush,
|
|
7
|
+
import { createMemo, merge, omit, onFlush, untrack } from "solid-js";
|
|
7
8
|
// src/slider/root/SliderRoot.tsx
|
|
8
9
|
var _tmpl$ = /* @__PURE__ */ template(`<div>`);
|
|
9
10
|
var places = (number) => (String(number).split(".")[1] ?? "").length;
|
|
@@ -83,27 +84,16 @@ function SliderRoot(props) {
|
|
|
83
84
|
props.onValueCommit?.(current);
|
|
84
85
|
}
|
|
85
86
|
};
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
sync();
|
|
97
|
-
const current = untrack(value);
|
|
98
|
-
if (current !== before) props.onValueCommit?.(current);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
form.addEventListener("reset", onReset);
|
|
103
|
-
return () => {
|
|
104
|
-
disposed = true;
|
|
105
|
-
form.removeEventListener("reset", onReset);
|
|
106
|
-
};
|
|
87
|
+
onFormReset(() => context.input?.form, () => {
|
|
88
|
+
const before = requested();
|
|
89
|
+
setValue(defaultValue());
|
|
90
|
+
onFlush(() => {
|
|
91
|
+
sync();
|
|
92
|
+
const current = untrack(value);
|
|
93
|
+
if (current !== before) props.onValueCommit?.(current);
|
|
94
|
+
});
|
|
95
|
+
}, () => {
|
|
96
|
+
context.input.defaultValue = context.input.value;
|
|
107
97
|
});
|
|
108
98
|
const ownProps = merge(context.attributes, { get style() {
|
|
109
99
|
return { "--slider": `${(Math.min(Math.max(value(), min()), max()) - min()) / (max() - min()) * 100}%` };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { merge, omit, onFlush } from "solid-js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
-
import { createComboboxInput
|
|
5
|
+
import { createComboboxInput } from "../../combobox/input/createComboboxInput.js";
|
|
5
6
|
import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
6
7
|
/**
|
|
7
8
|
* The autocomplete itself, and the form's control: an `<input type="text"
|
|
@@ -14,12 +15,18 @@ import { useComboboxContext } from "../../combobox/root/ComboboxContext.js";
|
|
|
14
15
|
export function AutocompleteInput(props) {
|
|
15
16
|
const autocomplete = useComboboxContext("Autocomplete");
|
|
16
17
|
const input = createComboboxInput(autocomplete);
|
|
17
|
-
|
|
18
|
+
// A form reset puts a control back to its default, and so it does an
|
|
19
|
+
// autocomplete: through its setter, so that a controlled one asks.
|
|
20
|
+
onFormReset(() => autocomplete.input?.form, (event) => {
|
|
18
21
|
autocomplete.setInputValue(autocomplete.props.defaultValue ?? "", {
|
|
19
22
|
reason: "reset",
|
|
20
23
|
event,
|
|
21
24
|
});
|
|
22
25
|
onFlush(input.syncText);
|
|
26
|
+
},
|
|
27
|
+
// Held through the browser's reset (`onFormReset`).
|
|
28
|
+
() => {
|
|
29
|
+
autocomplete.input.defaultValue = autocomplete.input.value;
|
|
23
30
|
});
|
|
24
31
|
const ownProps = merge(input.props, {
|
|
25
32
|
get name() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createUniqueId, omit
|
|
1
|
+
import { createUniqueId, omit } from "solid-js";
|
|
2
2
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
3
4
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
5
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
6
|
import { CheckboxGroupRootContext } from "./CheckboxGroupRootContext.js";
|
|
@@ -32,14 +33,7 @@ export function CheckboxGroupRoot(props) {
|
|
|
32
33
|
// A form reset puts the list back to its default, once, through the
|
|
33
34
|
// setter, so that a controlled group asks once. Each Item's Checkbox asks
|
|
34
35
|
// for nothing itself (CheckboxGroupItem).
|
|
35
|
-
|
|
36
|
-
const form = input?.form;
|
|
37
|
-
if (!form)
|
|
38
|
-
return;
|
|
39
|
-
const onReset = () => setValue(props.defaultValue ?? []);
|
|
40
|
-
form.addEventListener("reset", onReset);
|
|
41
|
-
return () => form.removeEventListener("reset", onReset);
|
|
42
|
-
});
|
|
36
|
+
onFormReset(() => input?.form, () => setValue(props.defaultValue ?? []));
|
|
43
37
|
const ownProps = {
|
|
44
38
|
get disabled() {
|
|
45
39
|
return props.disabled;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { omit, onFlush, untrack } from "solid-js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
5
|
import { useComboboxContext } from "../root/ComboboxContext.js";
|
|
5
|
-
import { createComboboxInput
|
|
6
|
+
import { createComboboxInput } from "./createComboboxInput.js";
|
|
6
7
|
/**
|
|
7
8
|
* The combobox itself: an `<input type="text" role="combobox"
|
|
8
9
|
* aria-autocomplete="list">` with `aria-expanded`, naming the List in
|
|
@@ -26,7 +27,9 @@ export function ComboboxInput(props) {
|
|
|
26
27
|
if (hiddenInput)
|
|
27
28
|
hiddenInput.value = untrack(combobox.value) ?? "";
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
+
// A form reset puts a control back to its default, and so it does a
|
|
31
|
+
// combobox: through its setters, so that a controlled one asks.
|
|
32
|
+
onFormReset(() => hiddenInput?.form, (event) => {
|
|
30
33
|
const value = combobox.props.defaultValue ?? null;
|
|
31
34
|
combobox.setValue(value);
|
|
32
35
|
combobox.setInputValue(combobox.props.defaultInputValue ?? combobox.labelOfValue(value) ?? "", { reason: "reset", event });
|
|
@@ -34,6 +37,11 @@ export function ComboboxInput(props) {
|
|
|
34
37
|
syncHidden();
|
|
35
38
|
input.syncText();
|
|
36
39
|
});
|
|
40
|
+
},
|
|
41
|
+
// Both held through the browser's reset (`onFormReset`).
|
|
42
|
+
() => {
|
|
43
|
+
combobox.input.defaultValue = combobox.input.value;
|
|
44
|
+
hiddenInput.defaultValue = hiddenInput.value;
|
|
37
45
|
});
|
|
38
46
|
const elementProps = mergeElementProps(input.props, omit(props, "render"));
|
|
39
47
|
return (<>
|
|
@@ -20,11 +20,3 @@ export declare function createComboboxInput(combobox: ComboboxBase, onFocusOut?:
|
|
|
20
20
|
props: ComboboxInputElementProps;
|
|
21
21
|
syncText(): void;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Calls `reset` when the form of `input()` is reset, from the time the
|
|
25
|
-
* part has settled: a form reset puts a control back to its default, and
|
|
26
|
-
* so it does a combobox, through its setters, so that a controlled one
|
|
27
|
-
* asks. The browser resets the form's inputs after the event, to their
|
|
28
|
-
* `value` attributes; an `onFlush` in `reset` runs after that.
|
|
29
|
-
*/
|
|
30
|
-
export declare function onFormReset(input: () => HTMLInputElement | undefined, reset: (event: Event) => void): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSignal, merge, onFlush,
|
|
1
|
+
import { createSignal, merge, onFlush, untrack } from "solid-js";
|
|
2
2
|
/**
|
|
3
3
|
* The input of a combobox, the code `Combobox.Input` and
|
|
4
4
|
* `Autocomplete.Input` share: its attributes, typing, the keys, focus
|
|
@@ -122,19 +122,3 @@ export function createComboboxInput(combobox, onFocusOut) {
|
|
|
122
122
|
});
|
|
123
123
|
return { props, syncText };
|
|
124
124
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Calls `reset` when the form of `input()` is reset, from the time the
|
|
127
|
-
* part has settled: a form reset puts a control back to its default, and
|
|
128
|
-
* so it does a combobox, through its setters, so that a controlled one
|
|
129
|
-
* asks. The browser resets the form's inputs after the event, to their
|
|
130
|
-
* `value` attributes; an `onFlush` in `reset` runs after that.
|
|
131
|
-
*/
|
|
132
|
-
export function onFormReset(input, reset) {
|
|
133
|
-
onSettled(() => {
|
|
134
|
-
const form = input()?.form;
|
|
135
|
-
if (!form)
|
|
136
|
-
return;
|
|
137
|
-
form.addEventListener("reset", reset);
|
|
138
|
-
return () => form.removeEventListener("reset", reset);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A form reset puts a native control back to its default, and so it does a
|
|
3
|
+
* part: `reset` asks for the part's default, through its setters, so that a
|
|
4
|
+
* controlled part asks. Listens to `form()`, read once the part has settled.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* onFormReset(
|
|
8
|
+
* () => input?.form,
|
|
9
|
+
* () => {
|
|
10
|
+
* setChecked(props.defaultChecked ?? false);
|
|
11
|
+
* onFlush(sync);
|
|
12
|
+
* },
|
|
13
|
+
* () => {
|
|
14
|
+
* input!.defaultChecked = input!.checked;
|
|
15
|
+
* },
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* - `hold` runs during the event, before the browser resets the controls,
|
|
20
|
+
* and what it returns is `reset`'s second argument. A part whose state
|
|
21
|
+
* is its own, not the element's, makes each element's state there the
|
|
22
|
+
* attribute the browser resets it to (`defaultChecked`, `defaultValue`),
|
|
23
|
+
* so the reset leaves it as it is: it never shows a state the part does
|
|
24
|
+
* not hold, and a binding that re-runs before `reset`, such as a Field's
|
|
25
|
+
* `data-touched` as the touched state clears, does not write its value
|
|
26
|
+
* back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
|
|
27
|
+
* part writes its own, a line, so no part pays for another's.
|
|
28
|
+
* - `reset` runs in a task after the event, not in `onFlush`: when the user
|
|
29
|
+
* presses a reset button, the browser runs microtasks as each listener
|
|
30
|
+
* returns, before it resets the controls and before later listeners
|
|
31
|
+
* could cancel the reset (src/input/README.md, "A form reset asks").
|
|
32
|
+
* Every part's `reset` runs in the same task, in the order the parts
|
|
33
|
+
* listened, so a set equal to one made before it in the task
|
|
34
|
+
* does nothing (`createControllableSignal`), and a Field, which listens
|
|
35
|
+
* before the controls inside it, reads them in an `onFlush` after theirs.
|
|
36
|
+
* - A reset the app cancels asks for nothing: the reset is the event's
|
|
37
|
+
* default action, so its `defaultPrevented` is the app saying no.
|
|
38
|
+
* - A part the reset removes before the task, such as a row of a list
|
|
39
|
+
* going back to its default length, asks for nothing, so it does not
|
|
40
|
+
* write its row back.
|
|
41
|
+
*/
|
|
42
|
+
export declare function onFormReset<T = void>(form: () => HTMLFormElement | null | undefined, reset: (event: Event, held: T) => void, hold?: () => T): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { onSettled } from "solid-js";
|
|
2
|
+
// The answers to the resets under way, run together in one task, in the
|
|
3
|
+
// order the parts listened: a part's `onFlush` then runs after those of the
|
|
4
|
+
// parts before it, as when each answered during the event.
|
|
5
|
+
let answers;
|
|
6
|
+
/**
|
|
7
|
+
* A form reset puts a native control back to its default, and so it does a
|
|
8
|
+
* part: `reset` asks for the part's default, through its setters, so that a
|
|
9
|
+
* controlled part asks. Listens to `form()`, read once the part has settled.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* onFormReset(
|
|
13
|
+
* () => input?.form,
|
|
14
|
+
* () => {
|
|
15
|
+
* setChecked(props.defaultChecked ?? false);
|
|
16
|
+
* onFlush(sync);
|
|
17
|
+
* },
|
|
18
|
+
* () => {
|
|
19
|
+
* input!.defaultChecked = input!.checked;
|
|
20
|
+
* },
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* - `hold` runs during the event, before the browser resets the controls,
|
|
25
|
+
* and what it returns is `reset`'s second argument. A part whose state
|
|
26
|
+
* is its own, not the element's, makes each element's state there the
|
|
27
|
+
* attribute the browser resets it to (`defaultChecked`, `defaultValue`),
|
|
28
|
+
* so the reset leaves it as it is: it never shows a state the part does
|
|
29
|
+
* not hold, and a binding that re-runs before `reset`, such as a Field's
|
|
30
|
+
* `data-touched` as the touched state clears, does not write its value
|
|
31
|
+
* back over the reset element (`UNCOMMITTED_INPUT_OVERWRITTEN`). Each
|
|
32
|
+
* part writes its own, a line, so no part pays for another's.
|
|
33
|
+
* - `reset` runs in a task after the event, not in `onFlush`: when the user
|
|
34
|
+
* presses a reset button, the browser runs microtasks as each listener
|
|
35
|
+
* returns, before it resets the controls and before later listeners
|
|
36
|
+
* could cancel the reset (src/input/README.md, "A form reset asks").
|
|
37
|
+
* Every part's `reset` runs in the same task, in the order the parts
|
|
38
|
+
* listened, so a set equal to one made before it in the task
|
|
39
|
+
* does nothing (`createControllableSignal`), and a Field, which listens
|
|
40
|
+
* before the controls inside it, reads them in an `onFlush` after theirs.
|
|
41
|
+
* - A reset the app cancels asks for nothing: the reset is the event's
|
|
42
|
+
* default action, so its `defaultPrevented` is the app saying no.
|
|
43
|
+
* - A part the reset removes before the task, such as a row of a list
|
|
44
|
+
* going back to its default length, asks for nothing, so it does not
|
|
45
|
+
* write its row back.
|
|
46
|
+
*/
|
|
47
|
+
export function onFormReset(form, reset, hold) {
|
|
48
|
+
onSettled(() => {
|
|
49
|
+
const target = form();
|
|
50
|
+
if (!target)
|
|
51
|
+
return;
|
|
52
|
+
let disposed = false;
|
|
53
|
+
const onReset = (event) => {
|
|
54
|
+
const held = hold?.();
|
|
55
|
+
if (!answers) {
|
|
56
|
+
const queue = (answers = []);
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
answers = undefined;
|
|
59
|
+
for (const answer of queue)
|
|
60
|
+
answer();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
answers.push(() => {
|
|
64
|
+
if (!disposed && !event.defaultPrevented)
|
|
65
|
+
reset(event, held);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
target.addEventListener("reset", onReset);
|
|
69
|
+
return () => {
|
|
70
|
+
disposed = true;
|
|
71
|
+
target.removeEventListener("reset", onReset);
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -34,8 +34,8 @@ export interface HiddenInputProps {
|
|
|
34
34
|
* - `button` is where focus goes when the browser focuses the input, as it
|
|
35
35
|
* does when it blocks a submission.
|
|
36
36
|
* - `reset` asks for the control's default on a form reset, through the
|
|
37
|
-
* setter, so that a controlled control asks. A Radio's
|
|
38
|
-
* the group, which asks once.
|
|
37
|
+
* setter, so that a controlled control asks (`onFormReset`). A Radio's
|
|
38
|
+
* Items each ask the group, which asks once.
|
|
39
39
|
*
|
|
40
40
|
* A plain function with positional parameters, not a component with props:
|
|
41
41
|
* a component would wrap each prop in a getter, and an options object
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { onFlush,
|
|
1
|
+
import { onFlush, untrack } from "solid-js";
|
|
2
|
+
import { onFormReset } from "./formReset.js";
|
|
2
3
|
/**
|
|
3
4
|
* The form's view of a control whose element is a native button (PLAN.md
|
|
4
5
|
* section 8, "The hidden input is the form's view of the control"): a
|
|
@@ -25,8 +26,8 @@ import { onFlush, onSettled, untrack } from "solid-js";
|
|
|
25
26
|
* - `button` is where focus goes when the browser focuses the input, as it
|
|
26
27
|
* does when it blocks a submission.
|
|
27
28
|
* - `reset` asks for the control's default on a form reset, through the
|
|
28
|
-
* setter, so that a controlled control asks. A Radio's
|
|
29
|
-
* the group, which asks once.
|
|
29
|
+
* setter, so that a controlled control asks (`onFormReset`). A Radio's
|
|
30
|
+
* Items each ask the group, which asks once.
|
|
30
31
|
*
|
|
31
32
|
* A plain function with positional parameters, not a component with props:
|
|
32
33
|
* a component would wrap each prop in a getter, and an options object
|
|
@@ -54,19 +55,13 @@ export function createHiddenInput(type, props, checked, setChecked, button, rese
|
|
|
54
55
|
};
|
|
55
56
|
// A form reset puts a native control back to its default, and so it does
|
|
56
57
|
// this one: through the setter, so that a controlled control asks.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// attribute, which the binding does not set. `onFlush` runs after
|
|
65
|
-
// that, as the event has finished by then.
|
|
66
|
-
onFlush(sync);
|
|
67
|
-
};
|
|
68
|
-
form.addEventListener("reset", onReset);
|
|
69
|
-
return () => form.removeEventListener("reset", onReset);
|
|
58
|
+
onFormReset(() => input?.form, () => {
|
|
59
|
+
reset();
|
|
60
|
+
onFlush(sync);
|
|
61
|
+
},
|
|
62
|
+
// Held through the browser's reset (`onFormReset`).
|
|
63
|
+
() => {
|
|
64
|
+
input.defaultChecked = input.checked;
|
|
70
65
|
});
|
|
71
66
|
return (
|
|
72
67
|
// The element, for the button to click. On the server it is the HTML,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createSignal, createUniqueId, merge, omit, onFlush, onSettled, useContext, } from "solid-js";
|
|
2
2
|
import { FormContext } from "../../core/formContext.js";
|
|
3
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
3
4
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
5
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
6
|
import { FieldRootContext } from "./FieldRootContext.js";
|
|
@@ -46,7 +47,6 @@ export function FieldRoot(props) {
|
|
|
46
47
|
// Reads the controls' validity again, and sets touched if given. The
|
|
47
48
|
// Field's own state is written after the event's flush, so async work the
|
|
48
49
|
// event starts does not hold it (PLAN.md section 8, "API conventions").
|
|
49
|
-
// By then a form reset has reset the controls too.
|
|
50
50
|
const update = (touch) => onFlush(() => {
|
|
51
51
|
setInvalidControl(readValidity());
|
|
52
52
|
if (touch !== undefined)
|
|
@@ -104,29 +104,27 @@ export function FieldRoot(props) {
|
|
|
104
104
|
// A submission attempt, or a control found invalid: `invalid` does not
|
|
105
105
|
// bubble, so the Root and the form listen in the capture phase.
|
|
106
106
|
const touch = () => update(true);
|
|
107
|
+
const findForm = () => root?.querySelector(controlSelector)?.form ??
|
|
108
|
+
root?.closest("form");
|
|
107
109
|
onSettled(() => {
|
|
108
110
|
setSettled(true);
|
|
109
111
|
// A submission attempt touches every Field of the form, by its submit
|
|
110
|
-
// event or an `invalid` event of any control in it
|
|
111
|
-
|
|
112
|
-
const form = root?.querySelector(controlSelector)?.form ??
|
|
113
|
-
root?.closest("form");
|
|
112
|
+
// event or an `invalid` event of any control in it.
|
|
113
|
+
const form = findForm();
|
|
114
114
|
if (!form)
|
|
115
115
|
return;
|
|
116
|
-
// A reset the app cancels, after this listener, keeps it touched.
|
|
117
|
-
const onReset = (event) => onFlush(() => {
|
|
118
|
-
if (!event.defaultPrevented)
|
|
119
|
-
update(false);
|
|
120
|
-
});
|
|
121
116
|
form.addEventListener("submit", touch);
|
|
122
117
|
form.addEventListener("invalid", touch, true);
|
|
123
|
-
form.addEventListener("reset", onReset);
|
|
124
118
|
return () => {
|
|
125
119
|
form.removeEventListener("submit", touch);
|
|
126
120
|
form.removeEventListener("invalid", touch, true);
|
|
127
|
-
form.removeEventListener("reset", onReset);
|
|
128
121
|
};
|
|
129
122
|
});
|
|
123
|
+
// A form reset clears touched, unless the app cancels it, and the Root
|
|
124
|
+
// reads the validity of the reset controls once they have put their
|
|
125
|
+
// inputs back: the Root listens before the controls inside it, so its
|
|
126
|
+
// `onFlush` comes after theirs only from inside one (`onFormReset`).
|
|
127
|
+
onFormReset(findForm, () => onFlush(() => update(false)));
|
|
130
128
|
const ownProps = merge(attributes, {
|
|
131
129
|
onFocusOut: (event) => {
|
|
132
130
|
const to = event.relatedTarget;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createMemo, createSignal, omit, onFlush, onSettled, untrack, } from "solid-js";
|
|
2
2
|
import { FormContext } from "../core/formContext.js";
|
|
3
|
+
import { onFormReset } from "../core/formReset.js";
|
|
3
4
|
import { callHandler, mergeElementProps } from "../core/mergeElementProps.js";
|
|
4
5
|
import { renderElement } from "../core/renderElement.jsx";
|
|
5
6
|
/**
|
|
@@ -35,14 +36,11 @@ export function Form(props) {
|
|
|
35
36
|
// Hides errors once the event's flush has run, as Field writes its own
|
|
36
37
|
// state, and only the `errors` the event met: a new object passed in the
|
|
37
38
|
// same update is the answer to a later submission.
|
|
38
|
-
const hide = (update) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
39
|
+
const hide = (update, met = untrack(errors)) => onFlush(() => {
|
|
40
|
+
if (untrack(errors) === met) {
|
|
41
|
+
setHidden((names) => (names === true ? names : update(names)));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
46
44
|
// An edit makes the error of that control's name stale.
|
|
47
45
|
const hideError = (event) => {
|
|
48
46
|
const name = event.target.name;
|
|
@@ -56,11 +54,12 @@ export function Form(props) {
|
|
|
56
54
|
if (form)
|
|
57
55
|
form.noValidate = true;
|
|
58
56
|
});
|
|
57
|
+
// A reset hides every error, unless the app cancels it: in a task after
|
|
58
|
+
// the event, with the errors the event met (`onFormReset`).
|
|
59
|
+
onFormReset(() => form, (_, met) => hide(() => true, met), () => untrack(errors));
|
|
59
60
|
const ownProps = {
|
|
60
61
|
onInput: hideError,
|
|
61
62
|
onChange: hideError,
|
|
62
|
-
// A reset the app cancels, by its own handler, keeps the errors.
|
|
63
|
-
onReset: (event) => hide((names) => (event.defaultPrevented ? names : true)),
|
|
64
63
|
onSubmit: (event) => {
|
|
65
64
|
const submitter = event.submitter;
|
|
66
65
|
// `checkValidity()` fires `invalid` at each invalid control, which
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { merge, omit, onFlush,
|
|
1
|
+
import { merge, omit, onFlush, untrack } from "solid-js";
|
|
2
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
2
3
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
4
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
5
|
/**
|
|
@@ -19,39 +20,24 @@ export function InputRoot(props) {
|
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
// A form reset puts a control back to its default, and so it does an
|
|
22
|
-
// Input: through `onValueChange`, so that a controlled one asks.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// Input: through `onValueChange`, so that a controlled one asks. An
|
|
24
|
+
// uncontrolled Input lets the browser reset it, to its `defaultValue`; a
|
|
25
|
+
// controlled one keeps its text through the reset, and its consumer
|
|
26
|
+
// decides.
|
|
27
|
+
onFormReset(() => element?.form, (event, text) => {
|
|
28
|
+
const defaultText = untrack(() => props.defaultValue) ?? "";
|
|
29
|
+
if (text === defaultText)
|
|
26
30
|
return;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (untrack(() => props.value) !== undefined) {
|
|
38
|
-
element.defaultValue = text;
|
|
39
|
-
}
|
|
40
|
-
// In a task of its own, not `onFlush`: when the user presses a reset
|
|
41
|
-
// button, the browser runs microtasks as each listener returns,
|
|
42
|
-
// before later listeners could cancel the reset.
|
|
43
|
-
setTimeout(() => {
|
|
44
|
-
if (disposed || event.defaultPrevented || text === defaultText)
|
|
45
|
-
return;
|
|
46
|
-
props.onValueChange?.(defaultText, { reason: "reset", event });
|
|
47
|
-
onFlush(restoreValue);
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
form.addEventListener("reset", onReset);
|
|
51
|
-
return () => {
|
|
52
|
-
disposed = true;
|
|
53
|
-
form.removeEventListener("reset", onReset);
|
|
54
|
-
};
|
|
31
|
+
props.onValueChange?.(defaultText, { reason: "reset", event });
|
|
32
|
+
onFlush(restoreValue);
|
|
33
|
+
},
|
|
34
|
+
// The text before the reset, held through it while controlled
|
|
35
|
+
// (`onFormReset`).
|
|
36
|
+
() => {
|
|
37
|
+
const text = element.value;
|
|
38
|
+
if (untrack(() => props.value) !== undefined)
|
|
39
|
+
element.defaultValue = text;
|
|
40
|
+
return text;
|
|
55
41
|
});
|
|
56
42
|
const ownProps = {
|
|
57
43
|
onInput: (event) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createMemo, createUniqueId, omit, onFlush,
|
|
1
|
+
import { createMemo, createUniqueId, omit, onFlush, untrack } from "solid-js";
|
|
2
2
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
3
4
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
5
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
6
|
import { parseNumber } from "../parse.js";
|
|
@@ -130,30 +131,13 @@ export function NumberFieldRoot(props) {
|
|
|
130
131
|
};
|
|
131
132
|
// A form reset puts a control back to its default, and so it does this
|
|
132
133
|
// one: through the setter, so that a controlled field asks.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const onReset = (event) => {
|
|
141
|
-
// In a task of its own, not `onFlush`: when the user presses a reset
|
|
142
|
-
// button, the browser runs microtasks as each listener returns,
|
|
143
|
-
// before it resets the controls and before later listeners could
|
|
144
|
-
// cancel the reset (src/input/README.md).
|
|
145
|
-
setTimeout(() => {
|
|
146
|
-
if (disposed || event.defaultPrevented)
|
|
147
|
-
return;
|
|
148
|
-
setValue(props.defaultValue ?? null);
|
|
149
|
-
onFlush(sync);
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
form.addEventListener("reset", onReset);
|
|
153
|
-
return () => {
|
|
154
|
-
disposed = true;
|
|
155
|
-
form.removeEventListener("reset", onReset);
|
|
156
|
-
};
|
|
134
|
+
// The Input's text is bound as its `defaultValue`, which the browser
|
|
135
|
+
// resets it to, so only the hidden input is held.
|
|
136
|
+
onFormReset(() => hidden?.form, () => {
|
|
137
|
+
setValue(props.defaultValue ?? null);
|
|
138
|
+
onFlush(sync);
|
|
139
|
+
}, () => {
|
|
140
|
+
hidden.defaultValue = hidden.value;
|
|
157
141
|
});
|
|
158
142
|
const elementProps = mergeElementProps(context.attributes, omit(props, "render", "value", "defaultValue", "onValueChange", "min", "max", "step", "largeStep", "format", "locale", "name", "form", "required", "disabled", "readOnly", "id", "aria-describedby", "aria-invalid"));
|
|
159
143
|
return (<NumberFieldRootContext value={context}>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isDev } from "@solidjs/web";
|
|
2
|
-
import { createUniqueId, merge, omit, onFlush,
|
|
2
|
+
import { createUniqueId, merge, omit, onFlush, untrack } from "solid-js";
|
|
3
3
|
import { warnUnlessButton } from "../../core/button.js";
|
|
4
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
4
5
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
5
6
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
6
7
|
import { useSelectContext } from "../root/SelectContext.js";
|
|
@@ -151,18 +152,13 @@ export function SelectTrigger(props) {
|
|
|
151
152
|
};
|
|
152
153
|
// A form reset puts a control back to its default, and so it does the
|
|
153
154
|
// Select: through the setter, so that a controlled Select asks.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// attribute; `onFlush` runs after that.
|
|
162
|
-
onFlush(syncInput);
|
|
163
|
-
};
|
|
164
|
-
form.addEventListener("reset", onReset);
|
|
165
|
-
return () => form.removeEventListener("reset", onReset);
|
|
155
|
+
onFormReset(() => input?.form, () => {
|
|
156
|
+
select.setValue(select.props.defaultValue ?? null);
|
|
157
|
+
onFlush(syncInput);
|
|
158
|
+
},
|
|
159
|
+
// Held through the browser's reset (`onFormReset`).
|
|
160
|
+
() => {
|
|
161
|
+
input.defaultValue = input.value;
|
|
166
162
|
});
|
|
167
163
|
const elementProps = mergeElementProps(ownProps, omit(props, "render", "id"));
|
|
168
164
|
return (<>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createMemo, merge, omit, onFlush,
|
|
1
|
+
import { createMemo, merge, omit, onFlush, untrack } from "solid-js";
|
|
2
2
|
import { createControllableSignal } from "../../core/createControllableSignal.js";
|
|
3
|
+
import { onFormReset } from "../../core/formReset.js";
|
|
3
4
|
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
4
5
|
import { renderElement } from "../../core/renderElement.jsx";
|
|
5
6
|
import { SliderRootContext } from "./SliderRootContext.js";
|
|
@@ -107,37 +108,20 @@ export function SliderRoot(props) {
|
|
|
107
108
|
};
|
|
108
109
|
// A form reset puts a control back to its default, and so it does this
|
|
109
110
|
// one: through the setter, so that a controlled slider asks.
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
const before = requested();
|
|
126
|
-
setValue(defaultValue());
|
|
127
|
-
onFlush(() => {
|
|
128
|
-
sync();
|
|
129
|
-
// Once taken: a controlled slider may decline it.
|
|
130
|
-
const current = untrack(value);
|
|
131
|
-
if (current !== before)
|
|
132
|
-
props.onValueCommit?.(current);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
form.addEventListener("reset", onReset);
|
|
137
|
-
return () => {
|
|
138
|
-
disposed = true;
|
|
139
|
-
form.removeEventListener("reset", onReset);
|
|
140
|
-
};
|
|
111
|
+
onFormReset(() => context.input?.form, () => {
|
|
112
|
+
const before = requested();
|
|
113
|
+
setValue(defaultValue());
|
|
114
|
+
onFlush(() => {
|
|
115
|
+
sync();
|
|
116
|
+
// Once taken: a controlled slider may decline it.
|
|
117
|
+
const current = untrack(value);
|
|
118
|
+
if (current !== before)
|
|
119
|
+
props.onValueCommit?.(current);
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
// Held through the browser's reset (`onFormReset`).
|
|
123
|
+
() => {
|
|
124
|
+
context.input.defaultValue = context.input.value;
|
|
141
125
|
});
|
|
142
126
|
const ownProps = merge(context.attributes, {
|
|
143
127
|
get style() {
|