Skip to content

<sessions-text-field>

A single-line (or multiline) text input.

Preact & React<TextField>GroupFormsDrawn asTextField

Preview

Drawn by the same renderers Sessions uses for your extension, from the DOM example beside it, without its event handlers.

When to use it

Controlled by you: set value, listen for input (every keystroke) or change (the committed value), and set error to show a validation message under it.

In Preact and React, import the component of the same name from @sessions/apps/preact or @sessions/apps/react. Attributes become camelCase props, a boolean attribute is a boolean prop, and an event is an on prop that receives the event’s detail.

Attributes

Attribute
label
The field label.Prop label
label-visibility
hidden keeps the label for screen readers but draws none.visiblehiddenProp labelVisibility
value
The current value.Prop value
placeholder
Hint text when empty.Prop placeholder
type
The HTML input type.textemailurlnumbertelProp type
help-text
Guidance under the field.Prop helpText
error
A validation message; the field turns critical.Prop error
disabledboolean
Non-interactive.Prop disabled
multilineboolean
A textarea instead of an input.Prop multiline
select-on-pasteboolean
Selects the whole value after a paste, so a wrong link is one keystroke from replaced.Prop selectOnPaste

Events

inputdetail: string — the new value
Every keystroke.Prop onInput
changedetail: string — the new value
The committed value.Prop onChange
focusdetail: undefined
The field gained focus.Prop onFocus
blurdetail: undefined
The field lost focus.Prop onBlur

Slots

slot="accessory"
Inside the field at its end — a small sessions-button, such as a Save that appears once the value changes.
Example
import {TextField} from '@sessions/apps/preact';

<TextField
  label="Playlist link"
  placeholder="https://open.spotify.com/playlist/…"
  value={model.draft}
  onInput={(value) => model.setDraft(value)}
/>

In the same group