Skip to content
Focsd homeFocsd homeFocsd
Forms

Editable

A value shown as text and edited in place, on one line or many.

  • Tag: focsd-editable
  • Pattern: Button that switches to a text field
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-editable
label="Project name"
name="project"
value="Atlas"
required></focsd-editable>
<focsd-editable
label="Description"
name="desc"
multiline
placeholder="Add a description"></focsd-editable>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-editable.js';
</script>
<focsd-editable label="Project name" name="project" value="Atlas" required></focsd-editable>

API

Attributes

AttributePropertyTypeDefault
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluestring—
placeholderplaceholderstring—
multilinemultilinebooleanfalse
keep-open-on-blurkeepOpenOnBlurbooleanfalse

Methods

MethodDescription
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.

Events

EventDescription
inputFired once when a commit changes the value, before change.
changeFired once when a commit changes the value.

Slots

SlotDescription
(default)Not used.

CSS parts

Style the inside of the component with ::part(), for example focsd-editable::part(layout).

PartDescription
layoutThe box around the label and the body; `data-position` is the label position.
labelThe visible label (display mode; the editor shows its own).
bodyThe display button and the messages.
displayThe button that shows the value and starts editing.
valueThe value inside the button.
placeholderThe placeholder (or "Empty") inside the button when there is no value.
iconThe edit icon.
editorThe text field or textarea shown while editing.
hintThe hint text.
messageThe shown error, warning or success message (also `error`, `warning` or `success`).
message-iconThe message's icon.
announcerThe visually hidden status region.

Accessibility

  • Display mode is a button named "label: value, edit" (the visible label comes first, so the name starts with it). With no value it reads the placeholder, or "Empty".
  • Editing swaps in a text field (a textarea with multiline) named by the label. The text is selected and focused. A commit refused because the value is blank with required, or invalid, keeps the editor open and shows the error as its description.
  • Focus returns to the button after Enter or Escape. Moving focus to another element commits unless keep-open-on-blur is set, which keeps the draft open. Switching windows or tabs neither commits nor cancels.
  • Escape stops there, so a dialog around the editable stays open. Enter during IME composition picks a candidate and does not commit.
  • Fires one input and one change for a commit that changed the value, and nothing while typing. Escape fires focsd-cancel. Reset and restore leave edit mode without events.

Keyboard

KeyAction
Enter / SpaceOn the button: start editing
EnterIn a single line: commit
Ctrl/Cmd + EnterIn multiline: commit (Enter adds a new line)
EscapeCancel and restore the previous value