Skip to content

Inline add form

One line at the foot of a list that starts a new thing by name.

<form class="cap-inline-add" method="post" action="#" aria-label="Add a scene">
  <input type="hidden" name="intent" value="new-scene" />
  <div class="cap-field">
    <label class="cap-field-label" for="ia-scene">New scene</label>
    <input class="cap-input" id="ia-scene" name="name" required placeholder="Scene name" autocomplete="off" />
  </div>
  <button type="submit" class="cap-btn">Start it</button>
</form>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/inline-add-form.css";

Usage

<form class="cap-inline-add" method="post" aria-label="Add a chapter">
  <input type="hidden" name="intent" value="new-chapter">
  <div class="cap-field">
    <label class="cap-field-label" for="new-chapter">New chapter</label>
    <input class="cap-input" id="new-chapter" name="name" required placeholder="Chapter name" autocomplete="off">
  </div>
  <div class="cap-field" data-size="short">...a select...</div>
  <button type="submit" class="cap-btn">Start it</button>
</form>
import { InlineAddForm } from "capsomer/react/inline-add-form";

<InlineAddForm Form={Form} hidden={{ intent: "new-chapter" }} submit="Start it" pending={busy}>
  <Field label="New chapter"><input className="cap-input" name="name" required placeholder="Chapter name" autoComplete="off" /></Field>
  <Field label="First scene"><input className="cap-input" name="scene" placeholder="Scene name" autoComplete="off" /></Field>
</InlineAddForm>

Examples

Two fields, the second optional

<form class="cap-inline-add" method="post" action="#">
  <input type="hidden" name="intent" value="new-chapter" />
  <div class="cap-field">
    <label class="cap-field-label" for="ia-chapter">New chapter</label>
    <input class="cap-input" id="ia-chapter" name="name" required placeholder="Chapter name" autocomplete="off" />
  </div>
  <div class="cap-field">
    <label class="cap-field-label" for="ia-first">First scene</label>
    <input class="cap-input" id="ia-first" name="scene" placeholder="Scene name" autocomplete="off" />
  </div>
  <button type="submit" class="cap-btn">Start it</button>
</form>

A short select beside the name

<form class="cap-inline-add" method="post" action="#">
  <div class="cap-field" data-size="short">
    <label class="cap-field-label" for="ia-kind">New entry</label>
    <select class="cap-select" id="ia-kind" name="kind">
      <option value="person">Person</option>
      <option value="place">Place</option>
      <option value="rule">Rule</option>
    </select>
  </div>
  <div class="cap-field">
    <label class="cap-field-label" for="ia-name">Name</label>
    <input class="cap-input" id="ia-name" name="name" required placeholder="Name" autocomplete="off" />
  </div>
  <button type="submit" class="cap-btn">Add it</button>
</form>

A narrow column: the fields wrap, the button follows

<div class="inline-add-narrow">
  <form class="cap-inline-add" method="post" action="#">
    <div class="cap-field">
      <label class="cap-field-label" for="ia-n1">New chapter</label>
      <input class="cap-input" id="ia-n1" name="name" placeholder="Chapter name" autocomplete="off" />
    </div>
    <div class="cap-field">
      <label class="cap-field-label" for="ia-n2">First scene</label>
      <input class="cap-input" id="ia-n2" name="scene" placeholder="Scene name" autocomplete="off" />
    </div>
    <button type="submit" class="cap-btn">Start it</button>
  </form>
</div>

API reference

InlineAddForm

PropTypeRequiredDoes
childrenReactNodeYesThe fields, usually Field elements: "New chapter", "First scene".
submitReactNodeYesThe button's words: "Start it", "Add".
hiddenRecord<string, string>Hidden fields the action needs: { intent: "new-chapter" }.
actionstringWhere it posts, and the router's form. A plain <form> without it.
FormFormComponent
pendingbooleanA post in flight: the button shows its spinner.
labelstringThe form's name, when the fields' labels do not say what it adds: "Add a chapter".

Parts and data attributes

ClassIs
.cap-inline-addthe root
AttributeValues
data-sizeshort

Accessibility

KeyDoes
TabThe fields, then the button
Enter in a fieldPosts the form
  • Labels are real label elements. A form whose labels do not say what it adds takes an aria-label ("Add a scene").
  • A required field is required, so the browser says what is missing.
  • Control heights and hit areas are the field's and button's (--control, --target).