Skip to content

Commit fdd69e4

Browse files
committed
chore: Minor Improvements/Corrections to Documentation
We missed some of these documentation updates/improvements while updating our project. Hopefully the docs are better now, though surely there are other improvements that could be made.
1 parent 4206928 commit fdd69e4

File tree

10 files changed

+34
-23
lines changed

10 files changed

+34
-23
lines changed

TODO.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
## Priority
44

5-
- [ ] REVIEW OUR ENTIRE `FormValidityObserver` DOCUMENTATION to make sure it's looking correct. This would include our sub-bullet point below.
6-
- [ ] We need to update the `Integration` docs for the `FormValidityObserver`. Our example on how to create one's own integration needs to include the new change where we only use a singular `type` (instead of allowing an array of types).
75
- [ ] ALSO deprecate `useFormValidityObserver` in favor of `useMemo(() => createFormValidityObserver())`. We may also want to update the `DESIGN_DECISIONS` docs when we do this.
86
- [ ] Release `0.9.0` after doing everything ABOVE this task.
97
- [ ] CONSIDER updating `@form-observer/lit` to automatically use `renderByDefault` and Lit's `render` function.
8+
- [ ] Alternatively, consider updating our StackBlitz Lit example to have a renderer example and a default-renderer example.
109
- [ ] Add docs on how to reconcile error messages between server and client.
1110
- [ ] Consider doing this AFTER releasing `0.9.0` if you need to.
1211

docs/form-validity-observer/README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,24 @@ Validates all of the observed form's fields, returning `true` if _all_ of the va
299299
<dl>
300300
<dt><code>focus</code></dl>
301301
<dd>
302-
<p>Indicates that the <em>first</em> field in the DOM that fails validation should be focused. Defaults to <code>false</code>.</p>
302+
<p>
303+
Indicates that the <em>first</em> field in the DOM that fails validation should be focused and scrolled into view. Defaults to <code>false</code>.
304+
</p>
305+
<p>
306+
When the <code>focus</code> option is <code>false</code>, you can consider <code>validateFields()</code> to be an enhanced version of <code>form.checkValidity()</code>. When the <code>focus</code> option is <code>true</code>, you can consider <code>validateFields()</code> to be an enhanced version of <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reportValidity"><code>form.reportValidity()</code></a>.
307+
</p>
303308
</dd>
304309
<dt><code>enableRevalidation</code></dt>
305310
<dd>
306311
<p>
307312
Enables revalidation for <strong>all</strong> of the form's fields. Defaults to <code>true</code>. (This option is only relevant if a value was provided for the observer's <a href="#form-validity-observer-options-revalidate-on"><code>revalidateOn</code></a> option.)
308313
</p>
314+
<p>
315+
Note that the <code>enableRevalidation</code> option can prevent field revalidation from being turned on, but it cannot be used to <em>turn off</em> revalidation.
316+
</p>
309317
</dd>
310318
</dl>
311319

312-
When the `focus` option is `false`, you can consider `validateFields()` to be an enhanced version of `form.checkValidity()`. When the `focus` option is `true`, you can consider `validateFields()` to be an enhanced version of [`form.reportValidity()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reportValidity).
313-
314-
Note that the `enableRevalidation` option can prevent field revalidation from being turned on, but it cannot be used to _turn off_ revalidation.
315-
316320
### Method: `FormValidityObserver.validateField(name: string, options?: ValidateFieldOptions): boolean | Promise<boolean>`
317321

318322
Validates the form field with the specified `name`, returning `true` if the field passes validation and `false` otherwise. The `boolean` that `validateField()` returns will be wrapped in a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) if the field's [`validate` constraint](./types.md#validationerrorsm-e-r) runs asynchronously. This promise will `resolve` after the asynchronous validation function `resolves`. Unlike the [`validateFields()`](#method-formvalidityobservervalidatefieldsoptions-validatefieldsoptions-boolean--promiseboolean) method, this promise will also `reject` if the asynchronous validation function `rejects`.
@@ -330,21 +334,25 @@ Validates the form field with the specified `name`, returning `true` if the fiel
330334
<p>An object used to configure the <code>validateField()</code> method. The following properties are supported:</p>
331335
<dl>
332336
<dt><code>focus</code></dt>
333-
<dd>Indicates that the field should be focused if it fails validation. Defaults to <code>false</code>.</dd>
337+
<dd>
338+
<p>Indicates that the field should be focused and scrolled into view if it fails validation. Defaults to <code>false</code>.
339+
<p>
340+
When the <code>focus</code> option is <code>false</code>, you can consider <code>validateField()</code> to be an enhanced version of <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity"><code>field.checkValidity()</code></a>. When the <code>focus</code> option is <code>true</code>, you can consider <code>validateField()</code> to be an enhanced version of <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity"><code>field.reportValidity()</code></a>.
341+
</p>
342+
</dd>
334343
<dt><code>enableRevalidation</code></dt>
335344
<dd>
336345
<p>
337346
Enables revalidation for the validated field. Defaults to <code>true</code>. (This option is only relevant if a value was provided for the observer's <a href="#form-validity-observer-options-revalidate-on"><code>revalidateOn</code></a> option.)
338347
</p>
348+
<p>
349+
Note that the <code>enableRevalidation</code> option can prevent field revalidation from being turned on, but it cannot be used to <em>turn off</em> revalidation.
350+
</p>
339351
</dd>
340352
</dl>
341353
</dd>
342354
</dl>
343355

344-
When the `focus` option is `false`, you can consider `validateField()` to be an enhanced version of [`field.checkValidity()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity). When the `focus` option is `true`, you can consider `validateField()` to be an enhanced version of [`field.reportValidity()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity).
345-
346-
Note that the `enableRevalidation` option can prevent field revalidation from being turned on, but it cannot be used to _turn off_ revalidation.
347-
348356
### Method: `FormValidityObserver.setFieldError<E>(name: string, message: `[`ErrorMessage<string, E>`](./types.md#errormessagem-e)`|`[`ErrorMessage<M, E>`](./types.md#errormessagem-e)`, render?: boolean): void`
349357

350358
Marks the form field having the specified `name` as invalid (via the [`[aria-invalid="true"]`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid) attribute) and applies the provided error `message` to it. Typically, you shouldn't need to call this method manually; but in rare situations it might be helpful.

docs/form-validity-observer/integrations/lit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ customElements.define("my-form", MyForm);
7171

7272
> Note: If you prefer, you can call `observe` and `unobserve`/`disconnect` manually instead.
7373
74-
## Function: `createFormValidityObserver(types, options)`
74+
## Function: `createFormValidityObserver(type, options)`
7575

7676
Creates a `FormValidityObserver` whose methods can be safely destructured. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options). If you don't need to destructure any of the observer's methods, then you are free to use the `FormValidityObserver`'s constructor directly.
7777

docs/form-validity-observer/integrations/preact.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A _convenience_ API for reducing code repetition in a [Preact](https://preactjs.com/) application using the [`FormValidityObserver`](../README.md).
44

5-
## Function: `createFormValidityObserver(types, options)`
5+
## Function: `createFormValidityObserver(type, options)`
66

77
Creates an enhanced version of the `FormValidityObserver`, known as the `PreactFormValidityObserver`. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options).
88

docs/form-validity-observer/integrations/react.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Additional Topics:
1111

1212
- [`Usage with Class Components`](#usage-with-class-components)
1313

14-
## Function: `createFormValidityObserver(types, options)`
14+
## Function: `createFormValidityObserver(type, options)`
1515

1616
Creates an enhanced version of the `FormValidityObserver`, known as the `ReactFormValidityObserver`. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options).
1717

docs/form-validity-observer/integrations/solid.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A _convenience_ API for reducing code repetition in a [Solid](https://www.solidjs.com/) application using the [`FormValidityObserver`](../README.md).
44

5-
## Function: `createFormValidityObserver(types, options)`
5+
## Function: `createFormValidityObserver(type, options)`
66

77
Creates an enhanced version of the `FormValidityObserver`, known as the `SolidFormValidityObserver`. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options).
88

docs/form-validity-observer/integrations/svelte.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A _convenience_ API for reducing code repetition in a [Svelte](https://svelte.dev/) application using the [`FormValidityObserver`](../README.md).
44

5-
## Function: `createFormValidityObserver(types, options)`
5+
## Function: `createFormValidityObserver(type, options)`
66

77
Creates an enhanced version of the `FormValidityObserver`, known as the `SvelteFormValidityObserver`. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options).
88

docs/form-validity-observer/integrations/vue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A _convenience_ API for reducing code repetition in a [Vue](https://vuejs.org/) application using the [`FormValidityObserver`](../README.md).
44

5-
## Function: `createFormValidityObserver(types, options)`
5+
## Function: `createFormValidityObserver(type, options)`
66

77
Creates an enhanced version of the `FormValidityObserver`, known as the `VueFormValidityObserver`. It accepts the exact same arguments as the [`FormValidityObserver`'s constructor](../README.md#constructor-formvalidityobservertypes-options).
88

packages/core/FormValidityObserver.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface FormValidityObserverOptions<
105105
}
106106

107107
export interface ValidateFieldOptions {
108-
/** Indicates that the field should be focused if it fails validation. Defaults to `false`. */
108+
/** Indicates that the field should be focused and scrolled into view if it fails validation. Defaults to `false`. */
109109
focus?: boolean;
110110
/**
111111
* Enables revalidation for the validated field. Defaults to `true`.
@@ -115,7 +115,10 @@ export interface ValidateFieldOptions {
115115
}
116116

117117
export interface ValidateFieldsOptions {
118-
/** Indicates that the _first_ field in the DOM that fails validation should be focused. Defaults to `false`. */
118+
/**
119+
* Indicates that the _first_ field in the DOM that fails validation should be focused and scrolled into view.
120+
* Defaults to `false`.
121+
*/
119122
focus?: boolean;
120123
/**
121124
* Enables revalidation for **all** of the form's fields. Defaults to `true`.

packages/core/FormValidityObserver.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ const attrs = Object.freeze({
9292

9393
/**
9494
* @typedef {Object} ValidateFieldOptions
95-
* @property {boolean} [focus] Indicates that the field should be focused if it fails validation. Defaults to `false`.
95+
* @property {boolean} [focus] Indicates that the field should be focused and scrolled into view if it fails validation.
96+
* Defaults to `false`.
9697
*
9798
* @property {boolean} [enableRevalidation] Enables revalidation for the validated field. Defaults to `true`.
9899
* (This option is only relevant if a value was provided for the observer's
@@ -101,8 +102,8 @@ const attrs = Object.freeze({
101102

102103
/**
103104
* @typedef {Object} ValidateFieldsOptions
104-
* @property {boolean} [focus] Indicates that the _first_ field in the DOM that fails validation should be focused.
105-
* Defaults to `false`.
105+
* @property {boolean} [focus] Indicates that the _first_ field in the DOM that fails validation should be focused and
106+
* scrolled into view. Defaults to `false`.
106107
*
107108
* @property {boolean} [enableRevalidation] Enables revalidation for **all** of the form's fields. Defaults to `true`.
108109
* (This option is only relevant if a value was provided for the observer's

0 commit comments

Comments
 (0)