menhir 0.1.14 → 0.1.16
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/context-menu/root/ContextMenuContext.js +15 -3
- package/dist/context-menu/root/ContextMenuRoot.js +5 -7
- package/dist/context-menu/trigger/ContextMenuTrigger.js +2 -2
- 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/menu/popup/MenuPopup.js +2 -2
- package/dist/menu/root/MenuContext.js +2 -2
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +1 -1
- 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/context-menu/root/ContextMenuContext.d.ts +6 -1
- package/dist/source/context-menu/root/ContextMenuContext.js +15 -2
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +3 -8
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +4 -3
- 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/menu/popup/MenuPopup.jsx +2 -2
- package/dist/source/menu/root/MenuContext.d.ts +12 -2
- package/dist/source/menu/root/MenuContext.js +2 -2
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +1 -1
- 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,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
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MenuAnchor } from "../../menu/popup/MenuPopup.tsx";
|
|
2
|
-
import type { Menu } from "../../menu/root/MenuContext.ts";
|
|
2
|
+
import type { Menu, MenuStateProps } from "../../menu/root/MenuContext.ts";
|
|
3
3
|
/**
|
|
4
4
|
* A context menu: Menu's state, plus where the menu was asked for, which
|
|
5
5
|
* its Trigger sets and its Popup is placed against.
|
|
@@ -14,5 +14,10 @@ export interface ContextMenu extends Menu {
|
|
|
14
14
|
/** The Trigger's element, once rendered: the anchor before the first. */
|
|
15
15
|
area: HTMLElement | undefined;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a context menu's state: Menu's, with where it was asked for and
|
|
19
|
+
* the area, which start unset.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createContextMenu(props: MenuStateProps): ContextMenu;
|
|
17
22
|
/** The Root's context menu, for its Trigger and its Popup. */
|
|
18
23
|
export declare function useContextMenu(): ContextMenu;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { isDev } from "@solidjs/web";
|
|
2
|
-
import { useContext } from "solid-js";
|
|
3
|
-
import { MenuContext } from "../../menu/root/MenuContext.js";
|
|
2
|
+
import { createSignal, useContext } from "solid-js";
|
|
3
|
+
import { createMenu, MenuContext } from "../../menu/root/MenuContext.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a context menu's state: Menu's, with where it was asked for and
|
|
6
|
+
* the area, which start unset.
|
|
7
|
+
*/
|
|
8
|
+
export function createContextMenu(props) {
|
|
9
|
+
const [anchor, setAnchor] = createSignal();
|
|
10
|
+
// Added to Menu's state, not copied: its functions write to that object.
|
|
11
|
+
const menu = createMenu(props);
|
|
12
|
+
menu.anchor = anchor;
|
|
13
|
+
menu.setAnchor = (value) => setAnchor(() => value);
|
|
14
|
+
menu.area = undefined;
|
|
15
|
+
return menu;
|
|
16
|
+
}
|
|
4
17
|
/** The Root's context menu, for its Trigger and its Popup. */
|
|
5
18
|
export function useContextMenu() {
|
|
6
19
|
const context = useContext(MenuContext);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MenuContext } from "../../menu/root/MenuContext.js";
|
|
2
|
+
import { createContextMenu } from "./ContextMenuContext.js";
|
|
3
3
|
/**
|
|
4
4
|
* A menu that an area opens with the `contextmenu` event: holds whether it
|
|
5
5
|
* is open, and where it was asked for, and shares them with
|
|
@@ -7,10 +7,5 @@ import { createMenu, MenuContext } from "../../menu/root/MenuContext.js";
|
|
|
7
7
|
* Renders no element of its own.
|
|
8
8
|
*/
|
|
9
9
|
export function ContextMenuRoot(props) {
|
|
10
|
-
|
|
11
|
-
// Added to Menu's state, not copied: its functions write to that object.
|
|
12
|
-
const menu = createMenu(props);
|
|
13
|
-
menu.anchor = anchor;
|
|
14
|
-
menu.setAnchor = (value) => setAnchor(() => value);
|
|
15
|
-
return <MenuContext value={menu}>{props.children}</MenuContext>;
|
|
10
|
+
return (<MenuContext value={createContextMenu(props)}>{props.children}</MenuContext>);
|
|
16
11
|
}
|
|
@@ -29,13 +29,14 @@ export function ContextMenuTrigger(props) {
|
|
|
29
29
|
: { getBoundingClientRect: () => new DOMRect(clientX, clientY) });
|
|
30
30
|
// The element the menu opens from, where Menu returns focus when the
|
|
31
31
|
// browser does not, as after an item in a submenu: the element a key
|
|
32
|
-
// was pressed on, or the one a press focused
|
|
32
|
+
// was pressed on, or the one a press focused. Not Menu's trigger, so
|
|
33
|
+
// a press on it is a press outside (README, "Decisions").
|
|
33
34
|
const focused = document.activeElement;
|
|
34
|
-
menu.
|
|
35
|
+
menu.returnTo = focused === document.body ? undefined : focused;
|
|
35
36
|
const details = { reason: "trigger-press", event };
|
|
36
37
|
// A second one while open moves the menu and starts it over.
|
|
37
38
|
menu.closeSubmenus(details);
|
|
38
|
-
menu.
|
|
39
|
+
menu.openAtFirst(details);
|
|
39
40
|
},
|
|
40
41
|
ref: (element) => {
|
|
41
42
|
menu.area = element;
|
|
@@ -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) => {
|
|
@@ -42,7 +42,7 @@ export function MenuPopup(props) {
|
|
|
42
42
|
get returnFocus() {
|
|
43
43
|
return (props.returnFocus ??
|
|
44
44
|
((focused) => focused ??
|
|
45
|
-
(focusInside ? menu.trigger : undefined)));
|
|
45
|
+
(focusInside ? (menu.returnTo ?? menu.trigger) : undefined)));
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
// Presence first: the popover is shown before it is placed and focused.
|
|
@@ -142,7 +142,7 @@ export function MenuPopup(props) {
|
|
|
142
142
|
// Shift+Tab from a submenu lands on its trigger, inside the menu that
|
|
143
143
|
// closes: focus goes on to the Trigger, where it leaves the menu.
|
|
144
144
|
if (popup.contains(event.relatedTarget))
|
|
145
|
-
menu.trigger?.focus();
|
|
145
|
+
(menu.returnTo ?? menu.trigger)?.focus();
|
|
146
146
|
},
|
|
147
147
|
ref: (element) => {
|
|
148
148
|
popup = element;
|
|
@@ -34,8 +34,11 @@ export interface Menu {
|
|
|
34
34
|
closeSubmenus(details: OpenChangeDetails): void;
|
|
35
35
|
/** Closes every menu, from the Root's down, as an activated item does. */
|
|
36
36
|
closeAll(details: OpenChangeDetails): void;
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Opens the menu with focus on its first item: from a key, or from a
|
|
39
|
+
* Context Menu's `contextmenu`, which a pointer fires too.
|
|
40
|
+
*/
|
|
41
|
+
openAtFirst(details: OpenChangeDetails): void;
|
|
39
42
|
/** The menu around a submenu; `undefined` for the Root's. */
|
|
40
43
|
readonly parent: Menu | undefined;
|
|
41
44
|
/**
|
|
@@ -54,6 +57,13 @@ export interface Menu {
|
|
|
54
57
|
triggerId(): string | false | undefined;
|
|
55
58
|
/** The trigger's element, once rendered: the anchor by default. */
|
|
56
59
|
trigger: HTMLElement | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Where focus returns when the browser does not, as after an item in a
|
|
62
|
+
* submenu, instead of `trigger`. Set by a Context Menu's Trigger to the
|
|
63
|
+
* element the menu opened from, left out of `trigger` so that a press on
|
|
64
|
+
* it is a press outside.
|
|
65
|
+
*/
|
|
66
|
+
returnTo?: HTMLElement;
|
|
57
67
|
/** A submenu's trigger, as an item of its parent menu. */
|
|
58
68
|
triggerItem: MenuItemEntry | undefined;
|
|
59
69
|
/** The Popup's element, once rendered. */
|
|
@@ -28,7 +28,7 @@ export function createMenu(props, parent) {
|
|
|
28
28
|
event.preventDefault();
|
|
29
29
|
if (item.submenu) {
|
|
30
30
|
if (!item.disabled)
|
|
31
|
-
item.submenu.
|
|
31
|
+
item.submenu.openAtFirst({ reason: "arrow-key", event });
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
// Right Arrow on an item with no submenu moves along a menubar, from
|
|
@@ -78,7 +78,7 @@ export function createMenu(props, parent) {
|
|
|
78
78
|
submenu.close(details);
|
|
79
79
|
},
|
|
80
80
|
closeAll: (details) => parent ? parent.closeAll(details) : menu.close(details),
|
|
81
|
-
|
|
81
|
+
openAtFirst: (details) => {
|
|
82
82
|
setOpen(true, details);
|
|
83
83
|
// While closed, the move waits for the menu to open (list navigation).
|
|
84
84
|
list.move(list.items()[0]);
|
|
@@ -28,7 +28,7 @@ export function MenuSubmenuTrigger(props) {
|
|
|
28
28
|
const details = { reason: "trigger-press", event: key ?? event };
|
|
29
29
|
// A key moves focus into the submenu; a click leaves it here.
|
|
30
30
|
if (key)
|
|
31
|
-
submenu.
|
|
31
|
+
submenu.openAtFirst(details);
|
|
32
32
|
else
|
|
33
33
|
submenu.setOpen(true, details);
|
|
34
34
|
},
|
|
@@ -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}>
|