Shared form-control policy for form-associated components: ElementInternals validity + form value, and the inline error-display recipe.
The two decisions here — constraint validity and the error-describedby
token — are pure functions, separated from their effects (set-validity! /
sync! / apply-error-display!), so the policy that maps a component's
error / required / emptiness onto native validity and invalid markers
lives in one place and is unit-testable.
A component supplies only its genuine per-control variation — what counts as empty, which element is the validity anchor, its value projection, any non-default missing message, and (for describedby) any author-supplied id — and composes this policy.
Shared form-control policy for form-associated components: ElementInternals validity + form value, and the inline error-display recipe. The two decisions here — constraint `validity` and the `error-describedby` token — are pure functions, separated from their effects (`set-validity!` / `sync!` / `apply-error-display!`), so the policy that maps a component's `error` / `required` / emptiness onto native validity and invalid markers lives in one place and is unit-testable. A component supplies only its genuine per-control variation — what counts as *empty*, which element is the validity *anchor*, its *value* projection, any non-default *missing message*, and (for describedby) any author-supplied id — and composes this policy.
(apply-error-display! el anchor error-el {:keys [error has-error?]} describedby)Effect: render a control's inline validation error and its invalid markers,
from {:error :has-error?}:
[part=error] span text and toggle its error-hidden class,data-invalid on the host el,aria-invalid on the anchor,aria-describedby on the anchor to describedby, or remove it when
describedby is nil.
describedby is passed in (see error-describedby) because the token set —
error only, or author-supplied ids plus error — is the caller's to decide.Effect: render a control's inline validation error and its invalid markers,
from `{:error :has-error?}`:
- set the `[part=error]` span text and toggle its `error-hidden` class,
- set/remove `data-invalid` on the host `el`,
- set `aria-invalid` on the `anchor`,
- set `aria-describedby` on the `anchor` to `describedby`, or remove it when
`describedby` is nil.
`describedby` is passed in (see `error-describedby`) because the token set —
error only, or author-supplied ids plus error — is the caller's to decide.(disabled? el)True when el is disabled by its own attribute or by a fieldset.
True when `el` is disabled by its own attribute or by a fieldset.
(error-describedby has-error? author)Pure: the aria-describedby value for a control's interactive element — the
inline-error id when an error is present, appended after an optional
author-supplied id list. Returns nil when there is neither an error nor an
author value (the caller then removes the attribute).
Pure: the `aria-describedby` value for a control's interactive element — the inline-error id when an error is present, appended after an optional author-supplied id list. Returns nil when there is neither an error nor an author value (the caller then removes the attribute).
(focus-quietly! control)Focuses control without a focus ring.
Focuses `control` without a focus ring.
(install-validity-api! proto k-internals)Install the native form-control validation surface on proto, delegating to
the ElementInternals each instance stashes under k-internals: validity,
validationMessage, willValidate, form and labels as read-only
getters, plus checkValidity() and reportValidity().
ElementInternals never mirrors any of this onto the host element — a
form-associated custom element has to expose it itself, or consumers can only
observe validity through a submit attempt. Where attachInternals is
unavailable the members fall back to the shape of a control that never blocks
submission, so feature-detecting callers see a consistent surface.
Install the native form-control validation surface on `proto`, delegating to the ElementInternals each instance stashes under `k-internals`: `validity`, `validationMessage`, `willValidate`, `form` and `labels` as read-only getters, plus `checkValidity()` and `reportValidity()`. ElementInternals never mirrors any of this onto the host element — a form-associated custom element has to expose it itself, or consumers can only observe validity through a submit attempt. Where `attachInternals` is unavailable the members fall back to the shape of a control that never blocks submission, so feature-detecting callers see a consistent surface.
(label-activation? el control evt)True when a click on the host el acts on control, as a click on a native label does.
A click from a link, a button or a form control in the label does not.
True when a click on the host `el` acts on `control`, as a click on a native label does. A click from a link, a button or a form control in the label does not.
(label-rules part opacity-var)The CSS of a slotted label in part part, dimmed by opacity-var when disabled.
The host sets data-labelled and data-disabled.
The CSS of a slotted label in part `part`, dimmed by `opacity-var` when disabled. The host sets `data-labelled` and `data-disabled`.
(make-label-section! part)Creates the label span of part part with a default slot in it.
Returns {:label span :slot slot}. The caller appends the span to its shadow root.
Creates the label span of part `part` with a default slot in it.
Returns `{:label span :slot slot}`. The caller appends the span to its shadow root.(set-validity! internals anchor inputs)Effect: apply the standard validity projection to internals, anchored at
anchor. No-op when internals is nil (older browsers / attachInternals
absent). inputs is the map accepted by validity.
Effect: apply the standard `validity` projection to `internals`, anchored at `anchor`. No-op when `internals` is nil (older browsers / attachInternals absent). `inputs` is the map accepted by `validity`.
(slot-has-content? slot-el)True when the light DOM assigns content to slot-el.
True when the light DOM assigns content to `slot-el`.
(sync! internals anchor value inputs)Effect: push value into the form and apply the standard validity in one
call. No-op when internals is nil. inputs is the map accepted by
validity.
Effect: push `value` into the form and apply the standard validity in one call. No-op when `internals` is nil. `inputs` is the map accepted by `validity`.
(validity {:keys [has-error? error required? empty? missing-message]})Pure: the standard BareDOM constraint-validation projection.
Returns a map {:flags <#js validity-state> :message <string>} ready for
ElementInternals.setValidity. Precedence: a present error with a message wins as a
customError; otherwise a required? control that is empty? reports
valueMissing; otherwise the field is valid (empty flags + empty message).
Pure: the standard BareDOM constraint-validation projection.
Returns a map `{:flags <#js validity-state> :message <string>}` ready for
`ElementInternals.setValidity`. Precedence: a present `error` with a message wins as a
`customError`; otherwise a `required?` control that is `empty?` reports
`valueMissing`; otherwise the field is valid (empty flags + empty message).(watch-label-slot! slot-el on-change)Calls on-change when the content of slot-el changes. Call once per slot.
Calls `on-change` when the content of `slot-el` changes. Call once per slot.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |