Develop
Runtime and events
Attach behaviour to server-rendered markup, and the events components dispatch.
Components are render-pure: they produce markup and never touch the DOM. Behaviour is attached
afterwards by a runtime that reads the same data-ui hooks.
#Attach to a page
<script type="module" src="/assets/faifo-design/runtime/auto.js"></script>runtime/auto.js calls attachDesignSystemInteractions(document) and sets
data-faifo-interactions="attached" on the root element, which a test can wait for.
#Attach to an island
import { attachDesignSystemInteractions } from 'faifo-design/runtime'
const dispose = attachDesignSystemInteractions(root)
// when the island unmounts
dispose()The full list of runtime functions, with their signatures, is on the Runtime page.
#Narrow entries
faifo-design/help/runtimeexportsattachHelpDrawersfor a host that has its own runtime and needs only the screen help.faifo-design/date-picker/runtimeattaches the date pickers alone.
#Events
Components and their host communicate through DOM events that carry their data in detail.
| Event | Dispatched when |
|---|---|
faifo:screen-help-request | The shell's help control asks the current screen for its guide |
faifo:relation-created | A relation select created a record in place |
faifo:grid-ready | An editable grid has drawn itself |
faifo:search-filter-navigate | A search filter is about to change the collection's URL (dispatched on document) |
faifo:records-changed | Dispatched by the host's record runtime after a change; a mounted collection refreshes its read |
ket:navigation-start and ket:navigation-complete are dispatched by the KetJS framework, not
by the design system; components that keep state across a navigation listen to them.
#Returning to a row
A collection link can carry the row a reader left, so Back returns them to it. The row anchor
helpers (rowAnchorHref, rememberRowAnchor, takeRowAnchor, restoreRowAnchor) implement
that without the application tracking scroll positions.
#Server field errors after a fetch submit
A form that posts with fetch learns about a field error only after the page has rendered,
so it cannot pass error to Field. Do not call setCustomValidity/reportValidity for
it: the browser bubble covers the help text, disappears on the next click and leaves nothing
for a screen reader to find again. Call showFieldError(control, message) from
faifo-design with the control the server named (for a checkbox or radio
group, any of its inputs). It adds the same field-error markup Field renders with
error, after the help, sets data-invalid on the Field and aria-invalid plus the error
ID in aria-describedby on the control (on the group and every choice for an option group),
and focuses the control; pass { focus: false } when another error already took focus.
A second call replaces the message. The next input or change inside that Field removes
it and restores the attributes it found; the returned function and
clearFieldError(control) remove it earlier, including an error the Field was rendered with.
A check that answers while the person is still typing (an email someone already uses) passes
{ focus: false, announce: true }: focus stays in the field, and the message is an alert that
is read out when it appears.
A control outside a Field is a no-op, so say that message elsewhere (a toast or a Notice).