@omer-x/tailwind-ui-kit 1.0.0-alpha.3 → 1.0.0-alpha.30
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/MIGRATION.md +283 -0
- package/README.md +761 -0
- package/dist/components/button/BaseButton.d.ts +39 -12
- package/dist/components/button/BaseButton.js +57 -51
- package/dist/components/button/index.d.ts +2 -4
- package/dist/components/button/index.js +1 -4
- package/dist/components/dialog/BaseAlertDialog.d.ts +49 -0
- package/dist/components/dialog/BaseAlertDialog.js +27 -0
- package/dist/components/dialog/BaseAlertDialogTrigger.d.ts +16 -0
- package/dist/components/dialog/BaseAlertDialogTrigger.js +11 -0
- package/dist/components/dialog/BaseDialog.d.ts +58 -0
- package/dist/components/dialog/BaseDialog.js +24 -0
- package/dist/components/dialog/BaseDialogClose.d.ts +13 -0
- package/dist/components/dialog/BaseDialogClose.js +7 -0
- package/dist/components/dialog/BaseDialogDescription.d.ts +8 -0
- package/dist/components/dialog/BaseDialogDescription.js +7 -0
- package/dist/components/dialog/BaseDialogPopup.d.ts +41 -0
- package/dist/components/dialog/BaseDialogPopup.js +42 -0
- package/dist/components/dialog/BaseDialogTitle.d.ts +8 -0
- package/dist/components/dialog/BaseDialogTitle.js +11 -0
- package/dist/components/dialog/BaseDialogTrigger.d.ts +20 -0
- package/dist/components/dialog/BaseDialogTrigger.js +11 -0
- package/dist/components/dialog/createAlertDialogHandle.d.ts +14 -0
- package/dist/components/dialog/createAlertDialogHandle.js +11 -0
- package/dist/components/dialog/createDialogHandle.d.ts +36 -0
- package/dist/components/dialog/createDialogHandle.js +31 -0
- package/dist/components/dialog/index.d.ts +8 -5
- package/dist/components/dialog/index.js +5 -8
- package/dist/components/disclosure/BaseAccordion.d.ts +48 -0
- package/dist/components/disclosure/BaseAccordion.js +18 -0
- package/dist/components/disclosure/BaseAccordionItem.d.ts +20 -0
- package/dist/components/disclosure/BaseAccordionItem.js +10 -0
- package/dist/components/disclosure/BaseAccordionPanel.d.ts +20 -0
- package/dist/components/disclosure/BaseAccordionPanel.js +15 -0
- package/dist/components/disclosure/BaseAccordionTrigger.d.ts +22 -0
- package/dist/components/disclosure/BaseAccordionTrigger.js +23 -0
- package/dist/components/disclosure/index.d.ts +4 -0
- package/dist/components/disclosure/index.js +1 -0
- package/dist/components/disclosure/panelTransition.d.ts +7 -0
- package/dist/components/disclosure/panelTransition.js +9 -0
- package/dist/components/display/BaseAvatar.d.ts +24 -0
- package/dist/components/display/BaseAvatar.js +35 -0
- package/dist/components/display/BaseAvatarFallback.d.ts +14 -0
- package/dist/components/display/BaseAvatarFallback.js +14 -0
- package/dist/components/display/BaseAvatarImage.d.ts +23 -0
- package/dist/components/display/BaseAvatarImage.js +14 -0
- package/dist/components/display/index.d.ts +3 -0
- package/dist/components/display/index.js +1 -0
- package/dist/components/elements/JustAnchor.d.ts +7 -0
- package/dist/components/elements/JustAnchor.js +11 -0
- package/dist/components/elements/JustButton.d.ts +7 -0
- package/dist/components/elements/JustButton.js +11 -0
- package/dist/components/elements/JustDiv.d.ts +7 -0
- package/dist/components/elements/JustDiv.js +11 -0
- package/dist/components/elements/JustInput.d.ts +7 -0
- package/dist/components/elements/JustInput.js +11 -0
- package/dist/components/elements/JustSpan.d.ts +7 -0
- package/dist/components/elements/JustSpan.js +11 -0
- package/dist/components/elements/index.d.ts +6 -0
- package/dist/components/elements/index.js +6 -0
- package/dist/components/form/BaseForm.d.ts +13 -0
- package/dist/components/form/BaseForm.js +78 -0
- package/dist/components/form/BaseFormField.d.ts +24 -0
- package/dist/components/form/BaseFormField.js +33 -0
- package/dist/components/form/BaseInput.d.ts +7 -0
- package/dist/components/form/BaseInput.js +22 -0
- package/dist/components/form/BaseSwitch.d.ts +35 -0
- package/dist/components/form/BaseSwitch.js +21 -0
- package/dist/components/form/ClientSideError.d.ts +9 -0
- package/dist/components/form/ClientSideError.js +39 -0
- package/dist/components/form/FieldRoot.d.ts +8 -0
- package/dist/components/form/FieldRoot.js +21 -0
- package/dist/components/form/FormContext.d.ts +28 -0
- package/dist/components/form/FormContext.js +12 -0
- package/dist/components/form/ServerSideError.d.ts +8 -0
- package/dist/components/form/ServerSideError.js +15 -0
- package/dist/components/form/index.d.ts +7 -0
- package/dist/components/form/index.js +6 -0
- package/dist/components/form/useFormMessages.d.ts +10 -0
- package/dist/components/form/useFormMessages.js +16 -0
- package/dist/components/layout/Container.d.ts +4 -10
- package/dist/components/layout/Container.js +9 -10
- package/dist/components/layout/index.d.ts +2 -3
- package/dist/components/layout/index.js +1 -4
- package/dist/components/page/Pagination.d.ts +27 -0
- package/dist/components/page/Pagination.js +68 -0
- package/dist/components/page/index.d.ts +3 -0
- package/dist/components/page/index.js +3 -0
- package/dist/components/page/usePagination.d.ts +30 -0
- package/dist/components/page/usePagination.js +41 -0
- package/dist/components/table/TableCell.d.ts +13 -0
- package/dist/components/table/TableCell.js +17 -0
- package/dist/components/table/Tdx.d.ts +6 -10
- package/dist/components/table/Tdx.js +11 -9
- package/dist/components/table/index.d.ts +3 -3
- package/dist/components/table/index.js +3 -4
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useRipples.d.ts +2 -5
- package/dist/hooks/useRipples.js +44 -32
- package/dist/utils/cn.d.ts +6 -5
- package/dist/utils/cn.js +8 -6
- package/dist/utils/dirty-form.d.ts +7 -0
- package/dist/utils/dirty-form.js +40 -0
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +2 -3
- package/dist/utils/render.d.ts +31 -0
- package/dist/utils/render.js +24 -0
- package/package.json +60 -26
- package/typescript-badge.d.ts +4 -0
- package/dist/components/button/PulseButton.d.ts +0 -10
- package/dist/components/button/PulseButton.js +0 -24
- package/dist/components/dialog/AnimatedPopup.d.ts +0 -6
- package/dist/components/dialog/AnimatedPopup.js +0 -34
- package/dist/components/dialog/DialogBackdrop.d.ts +0 -6
- package/dist/components/dialog/DialogBackdrop.js +0 -26
- package/dist/components/dialog/DialogTitle.d.ts +0 -6
- package/dist/components/dialog/DialogTitle.js +0 -19
- package/dist/styles/ripple.module.css +0 -10
- package/dist/styles/ripple.module.d.ts +0 -2
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Migrating from 1.0.0-alpha.18 to 1.0.0-alpha.19+
|
|
2
|
+
|
|
3
|
+
Each breaking change has its own section with before / after code and the reason for it.
|
|
4
|
+
|
|
5
|
+
- **Mechanical:** a rename or a type change. The compiler points you to every place to fix.
|
|
6
|
+
- **Check manually:** behavior changed. Code still compiles, but may act differently.
|
|
7
|
+
|
|
8
|
+
## Types
|
|
9
|
+
|
|
10
|
+
### Props no longer name Base UI types (mechanical, #55)
|
|
11
|
+
|
|
12
|
+
Component props are now native element props plus the kit's own props, and `render` / `render*` props use the kit's `RenderProp` type. This changes three things:
|
|
13
|
+
|
|
14
|
+
- `className` and `style` on `BaseButton` and `BaseSwitch` no longer take a function of the state. Use data attributes instead:
|
|
15
|
+
|
|
16
|
+
```diff
|
|
17
|
+
- className={state => (state.disabled ? "opacity-50" : "")}
|
|
18
|
+
+ className="data-disabled:opacity-50"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Event handlers get React's event types, so `event.preventBaseUIHandler()` is no longer typed.
|
|
22
|
+
- Types like `ComponentProps<typeof Button>` or `useRender.ComponentProps<"div">` from `@base-ui/react` are replaced by the kit's types: `RenderProp`, `ButtonState`, `SwitchState` and `FieldState`. To build your own component with a `render` prop, use `useRender` and `mergeProps` from `@omer-x/tailwind-ui-kit/utils`:
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
- import { useRender } from "@base-ui/react/use-render";
|
|
26
|
+
- import { mergeProps } from "@base-ui/react/merge-props";
|
|
27
|
+
+ import { mergeProps, type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The kit's `useRender` takes `defaultTagName`, `render`, `props` and `state`.
|
|
31
|
+
|
|
32
|
+
**Why:** Base UI is an implementation detail. Types that named it tied apps to it, and replacing it would have broken them.
|
|
33
|
+
|
|
34
|
+
## Button
|
|
35
|
+
|
|
36
|
+
### Font Awesome is removed: pass a `spinner` (mechanical, #5, #8)
|
|
37
|
+
|
|
38
|
+
The kit no longer depends on Font Awesome. `BaseButton` used to show Font Awesome's spinner while pending; now it shows the `spinner` you pass, and nothing without one. Set it once in your themed wrapper:
|
|
39
|
+
|
|
40
|
+
```diff
|
|
41
|
+
<BaseButton
|
|
42
|
+
{...props}
|
|
43
|
+
+ spinner={<FontAwesomeIcon icon={faSpinner} spinPulse />}
|
|
44
|
+
className={...}
|
|
45
|
+
/>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
You can remove the Font Awesome peer dependencies and the `@fortawesome/fontawesome-svg-core/styles.css` import if your app doesn't use Font Awesome itself.
|
|
49
|
+
|
|
50
|
+
**Why:** the kit needed three peer dependencies and Font Awesome's CSS for one spinner, and apps couldn't choose their own icon.
|
|
51
|
+
|
|
52
|
+
### Submit buttons get the full pending state while their form submits (check manually, #5)
|
|
53
|
+
|
|
54
|
+
A submit button inside a submitting form now behaves exactly like `pending`: it shows the spinner, ignores clicks, **keeps keyboard focus**, and sets `aria-busy="true"` and `data-pending`. `pending` itself now really blocks clicks (before, a pending button could still be clicked and submit twice).
|
|
55
|
+
|
|
56
|
+
`data-submitting` is replaced by `data-pending`:
|
|
57
|
+
|
|
58
|
+
```diff
|
|
59
|
+
- className="data-submitting:opacity-50"
|
|
60
|
+
+ className="data-pending:opacity-50"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Remove any `pending={isSubmitting}` you wired up by hand for submit buttons of `BaseForm`.
|
|
64
|
+
|
|
65
|
+
**Why:** "submitting" and "pending" were two states that looked and behaved differently: a submitting button was disabled with no spinner and lost focus.
|
|
66
|
+
|
|
67
|
+
### Icon-only buttons: use `iconOnly` (mechanical, #5)
|
|
68
|
+
|
|
69
|
+
```diff
|
|
70
|
+
- <Button className="w-10 px-0"><TrashIcon /></Button>
|
|
71
|
+
+ <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`iconOnly` makes the button square at every size, and the types require an `aria-label`. While pending, the spinner replaces the icon.
|
|
75
|
+
|
|
76
|
+
## Page
|
|
77
|
+
|
|
78
|
+
### `Pagination`: the app builds the links (mechanical, #16)
|
|
79
|
+
|
|
80
|
+
`queryParams` is removed, and `renderLink` is now a function of the page number. The kit no longer builds URLs, so keep your query parameters and choose the page parameter yourself:
|
|
81
|
+
|
|
82
|
+
```diff
|
|
83
|
+
<Pagination
|
|
84
|
+
totalItems={total}
|
|
85
|
+
itemsPerPage={20}
|
|
86
|
+
currentPage={page}
|
|
87
|
+
- queryParams={{ q: search }}
|
|
88
|
+
- renderLink={props => <Link {...props} href={props.href!} className="..." />}
|
|
89
|
+
+ renderLink={(page, props) => <Link {...props} href={{ pathname: "/products", query: { q: search, page } }} className="..." />}
|
|
90
|
+
renderButton={<button className="..." />}
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Why:** typed hrefs (e.g. next-intl's typed pathnames) can't be built from a string, and the kit put `undefined` and joined arrays into links.
|
|
95
|
+
|
|
96
|
+
### `Pagination`: new markup (check manually, #16)
|
|
97
|
+
|
|
98
|
+
- The wrapper is a `<nav aria-label="Pagination">` instead of a `<div>`.
|
|
99
|
+
- The current page goes through `renderLink` with `aria-current="page"`, not through `renderButton` as a disabled button. Style it with `aria-[current=page]:` instead of `disabled:`.
|
|
100
|
+
- Ellipses are a `<span aria-hidden>` from the new `renderEllipsis`, not disabled buttons. `renderButton` only renders disabled arrows now.
|
|
101
|
+
- The arrows have accessible names (`previousLabel` / `nextLabel`).
|
|
102
|
+
|
|
103
|
+
**Why:** screen readers announced a plain group of buttons and links, with no current page and unnamed arrows.
|
|
104
|
+
|
|
105
|
+
## Dialog
|
|
106
|
+
|
|
107
|
+
### `AnimatedPopup`, `DialogBackdrop` and `DialogTitle` are replaced by `BaseDialog` (mechanical, #52)
|
|
108
|
+
|
|
109
|
+
The dialog entry point now wraps every part, so apps no longer import `@base-ui/react/dialog`. `BaseDialog.Popup` brings its portal and the backdrop that `DialogBackdrop` used to style, and `BaseDialog.Title` has `DialogTitle`'s typography:
|
|
110
|
+
|
|
111
|
+
```diff
|
|
112
|
+
- import { Dialog } from "@base-ui/react/dialog";
|
|
113
|
+
- import { AnimatedPopup, DialogBackdrop, DialogTitle } from "@omer-x/tailwind-ui-kit/dialog";
|
|
114
|
+
+ import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
|
|
115
|
+
|
|
116
|
+
- <Dialog.Root>
|
|
117
|
+
- <Dialog.Trigger render={<Button />}>Open</Dialog.Trigger>
|
|
118
|
+
- <Dialog.Portal>
|
|
119
|
+
- <Dialog.Backdrop render={<DialogBackdrop />} />
|
|
120
|
+
- <Dialog.Popup render={<AnimatedPopup className="rounded-lg bg-white p-6 shadow-lg" />}>
|
|
121
|
+
- <Dialog.Title render={<DialogTitle />}>Delete item?</Dialog.Title>
|
|
122
|
+
- <Dialog.Close render={<Button />}>Cancel</Dialog.Close>
|
|
123
|
+
- </Dialog.Popup>
|
|
124
|
+
- </Dialog.Portal>
|
|
125
|
+
- </Dialog.Root>
|
|
126
|
+
+ <BaseDialog>
|
|
127
|
+
+ <BaseDialog.Trigger render={<Button />}>Open</BaseDialog.Trigger>
|
|
128
|
+
+ <BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
|
|
129
|
+
+ <BaseDialog.Title>Delete item?</BaseDialog.Title>
|
|
130
|
+
+ <BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
|
|
131
|
+
+ </BaseDialog.Popup>
|
|
132
|
+
+ </BaseDialog>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- `Dialog.createHandle()` becomes `createDialogHandle()`. Its `open()` no longer needs an argument.
|
|
136
|
+
- `onOpenChange` gets the DOM event instead of Base UI's event details.
|
|
137
|
+
- Portal props (`container`, `keepMounted`) move to `BaseDialog.Popup`. Style the backdrop with its `renderBackdrop` prop, or turn it off with `backdrop={false}`.
|
|
138
|
+
|
|
139
|
+
**Why:** apps had to import Base UI to build a dialog, which tied them to it.
|
|
140
|
+
|
|
141
|
+
## Form
|
|
142
|
+
|
|
143
|
+
### `BaseSwitch`: `onCheckedChange` gets the DOM event (mechanical, #55)
|
|
144
|
+
|
|
145
|
+
The second argument of `onCheckedChange` is now the DOM `Event`, not Base UI's event details. `eventDetails.cancel()` is gone: to refuse a change, control the switch with `checked`.
|
|
146
|
+
|
|
147
|
+
```diff
|
|
148
|
+
- onCheckedChange={(checked, details) => track(details.event)}
|
|
149
|
+
+ onCheckedChange={(checked, event) => track(event)}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Why:** the event details were a Base UI type (#55).
|
|
153
|
+
|
|
154
|
+
### Fields are validated in the browser (check manually, #65)
|
|
155
|
+
|
|
156
|
+
`BaseFormField`'s constraints (`required`, `minLength`, `max`, … from the schema) used to block nothing: every submit reached the action. Now an invalid field blocks the submit and shows its browser error (`valueMissing`, `tooShort`, …) through `formatMessage`, so add those codes to your translations.
|
|
157
|
+
|
|
158
|
+
The `control` you pass is rendered as Base UI's field control, so it now gets `aria-invalid` and `data-invalid` when it has an error.
|
|
159
|
+
|
|
160
|
+
**Why:** the control was a plain `<input>` that Base UI's form didn't know about, and the form turns off the browser's own validation.
|
|
161
|
+
|
|
162
|
+
### `BaseForm` takes a `@omer-x/next-form-actions` v2 action (mechanical, #10)
|
|
163
|
+
|
|
164
|
+
The action now returns the typed `FormActionState` of `@omer-x/next-form-actions` v2 instead of a flat `Record<string, string>`. Install it, and migrate your actions with [its own guide](https://github.com/omermecitoglu/next-form-actions/blob/main/MIGRATION.md).
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
npm install @omer-x/next-form-actions@^2.0.0-alpha.1
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```diff
|
|
171
|
+
- export async function saveProfile(_state: unknown, formData: FormData) {
|
|
172
|
+
- if (await isTaken(name)) return { name: "name_taken" };
|
|
173
|
+
- return { "[success]": "saved" };
|
|
174
|
+
- }
|
|
175
|
+
+ export const saveProfile = defineFormAction({
|
|
176
|
+
+ schema: z.object({ name: z.string().refine(async name => !(await isTaken(name)), { params: { customErrorCode: "taken" } }) }),
|
|
177
|
+
+ action: input => async () => save(input),
|
|
178
|
+
+ });
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Why:** the flat record mixed field errors and form messages in one namespace, its rules were invisible in the types, it couldn't carry data, and success had to be guessed from a `[success]` key.
|
|
182
|
+
|
|
183
|
+
### `messages` and `clientSideErrors` are replaced by `formatMessage` (mechanical, #10)
|
|
184
|
+
|
|
185
|
+
`BaseForm`'s `messages`, and `BaseFormField`'s `messages` and `clientSideErrors`, are removed. One `formatMessage(code, params)` on `BaseForm` formats every text: server error codes, browser validity states and form message texts. Set it in your themed form wrapper:
|
|
186
|
+
|
|
187
|
+
```diff
|
|
188
|
+
// src/components/Form.tsx
|
|
189
|
+
"use client";
|
|
190
|
+
+ const t = useTranslations("Form");
|
|
191
|
+
- <BaseForm {...props} messages={messages} />
|
|
192
|
+
+ <BaseForm {...props} formatMessage={(code, params) => t(code, params)} />
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```diff
|
|
196
|
+
<BaseFormField
|
|
197
|
+
name="username"
|
|
198
|
+
schema={z.string().min(3)}
|
|
199
|
+
- clientSideErrors={{ valueMissing: "Required", tooShort: min => `At least ${min} characters` }}
|
|
200
|
+
/>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```diff
|
|
204
|
+
// en.json
|
|
205
|
+
"Form": {
|
|
206
|
+
- "REQUIRED": "This field is required",
|
|
207
|
+
+ "required": "This field is required",
|
|
208
|
+
+ "valueMissing": "This field is required",
|
|
209
|
+
+ "tooShort": "At least {minimum} characters",
|
|
210
|
+
+ "too_small": "At least {minimum} characters"
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Server codes are now lowercase Zod issue codes (`required`, `too_small`, …) with params like `{ minimum, origin }`. Browser validity states get `{ minimum }` (`tooShort`, `rangeUnderflow`) or `{ maximum }` (`tooLong`, `rangeOverflow`). See the README for the full list.
|
|
215
|
+
|
|
216
|
+
**Why:** server and browser errors were configured in two places, and plain lookup maps couldn't use error params ("at least 3 characters") or plurals.
|
|
217
|
+
|
|
218
|
+
### `BaseForm` renders no messages: use `useFormMessages()` (mechanical, #58)
|
|
219
|
+
|
|
220
|
+
`renderMessages` is removed, and `BaseForm` no longer renders form-level messages at the top of the form. Render them yourself, wherever you want:
|
|
221
|
+
|
|
222
|
+
```diff
|
|
223
|
+
- <Form action={save} renderMessages={<div className="rounded p-3 data-[message-type=default]:bg-red-100" />}>
|
|
224
|
+
+ <Form action={save}>
|
|
225
|
+
+ <FormAlerts />
|
|
226
|
+
...
|
|
227
|
+
</Form>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
const FormAlerts = () => {
|
|
232
|
+
const { messages } = useFormMessages();
|
|
233
|
+
return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
|
|
234
|
+
};
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`data-message-type` is gone. Each message has a `type` (`"error"` or `"warning"`) instead. For toasts, run your effect on `submissionId`, which changes once per submission.
|
|
238
|
+
|
|
239
|
+
**Why:** apps couldn't show messages as toasts, use their own alert boxes, or move them (next to the submit button, into a dialog footer, …).
|
|
240
|
+
|
|
241
|
+
### `onStateChange` is replaced by `onResult` (check manually, #62)
|
|
242
|
+
|
|
243
|
+
```diff
|
|
244
|
+
- <Form action={update} onStateChange={state => state["[success]"] && dialog.close()}>
|
|
245
|
+
+ <Form action={update} onResult={result => result.status === "success" && dialog.close()}>
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
`onResult` is called once per completed submission, right when the action returns. Unlike `onStateChange`, it is **not** called on mount, and two identical results in a row trigger two calls. Remove any guard you added against the initial call.
|
|
249
|
+
|
|
250
|
+
**Why:** `onStateChange` ran from an effect, so it fired on mount with the empty initial state, and success had to be guessed from the result's keys.
|
|
251
|
+
|
|
252
|
+
### Forms no longer reset after submit (check manually, #4)
|
|
253
|
+
|
|
254
|
+
`BaseForm` used to submit through `<form action>`, which made React reset the form after every submission. That also put controlled checkboxes and selects back to their first rendered values in the DOM. Now nothing is reset: after a failure the user keeps what they typed.
|
|
255
|
+
|
|
256
|
+
Remove the workarounds:
|
|
257
|
+
|
|
258
|
+
- hidden inputs that mirrored controlled checkbox or select values,
|
|
259
|
+
- a `key` on fields or on the form that changed after each submit.
|
|
260
|
+
|
|
261
|
+
If a form should be cleared after a **successful** submit (e.g. "add another"), use the new `resetOnSuccess` prop instead of changing its `key`:
|
|
262
|
+
|
|
263
|
+
```diff
|
|
264
|
+
- <Form key={formKey} action={create} onStateChange={() => setFormKey(k => k + 1)}>
|
|
265
|
+
+ <Form action={create} resetOnSuccess>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### `onlyDirty` sends cleared fields as empty values (check manually, #17)
|
|
269
|
+
|
|
270
|
+
With `onlyDirty`, a field that changed to "no value" is now sent with an empty value (`name=""`) instead of being left out: a checkbox that was checked by default and is now unchecked, a multi-select with everything deselected, a cleared text field. `BaseSwitch` sends its `uncheckedValue` as before. Fields are also compared by name now, so:
|
|
271
|
+
|
|
272
|
+
- file inputs send the selected `File` objects (before: the browser's fake path string),
|
|
273
|
+
- multi-selects and checkbox groups send every selected value, and an array default (`tags: ["a", "b"]`) matches them in any order,
|
|
274
|
+
- radio groups are compared with their string default (before: always sent).
|
|
275
|
+
|
|
276
|
+
On the server, treat an empty value as "cleared", and a missing field as "unchanged":
|
|
277
|
+
|
|
278
|
+
```diff
|
|
279
|
+
- const active = formData.has("active");
|
|
280
|
+
+ const active = formData.has("active") ? formData.get("active") === "on" : undefined;
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Why:** the server couldn't tell an unchecked checkbox from an unchanged one, and files, multi-selects and checkbox groups were sent wrong.
|