Skip to content

Input group for adornments and actions ​

Purpose and user problems ​

GhostInput renders one native <input> and has no slots. The Input spec leaves prefixes, suffixes, clear buttons and inline icons out of scope. Two everyday cases still need content beside the input:

  • A unit after a value. “Request timeout: [30] seconds”. The unit is information. A reader must hear it with the value, and it must not enter the submitted value.
  • A clearable search. “Search reports: [forecast] [×]”. The × is a named button that empties the field. It must not submit the form, and focus must not be lost when it disappears.

Both must keep the input's label, native name/value, validation attributes, ID, template ref and focus behavior exactly as they are without a group.

Non-goals ​

  • No new input behavior. Typing, model updates, validation, constraint attributes, reset reconciliation and the exposed ref stay with GhostInput.
  • No model ownership. Clearing writes to the caller's v-model; the group stores no value. Schema validation stays with the form.
  • No numeric steppers or formatting. GhostNumberInput keeps its own layout. Use its formatOptions for units and currency (see Composition).
  • No combobox, tags or date-picker affordances. Their triggers and clear actions belong to those widgets.
  • No icon artwork. Per ADR 0013 icons are consumer-supplied.

Public API ​

Options compared ​

OptionExports and selectorsWhat it solvesCost
A. Themed documentation recipe (chosen)None. Example-owned layout around shipped Input, Field and Button.Unit suffix, prefix, clearable searchThe caller joins one description ID and writes a three-line clear handler.
B. Themed compound parts (GhostInputGroup, …Text)New components, manifests, size budgets and theme selectors in @ghostvue/themes.Same cases, plus attached chromeThe text part must add its ID to the input's aria-describedby, which GhostFieldControl already writes. Either the group re-wraps Field's slot props, or GhostInput learns a group context and changes for every consumer. Clear still needs the caller's model.
C. Headless parts in @ghostvue/vueB's surface, plus a layout contract in the headless package.Same as BHeadless parts would ship layout without behavior, which the headless package does not do.

Option A is chosen. Every relationship the two cases need already exists as native HTML or a shipped contract: Field supplies the label and descriptions, aria-describedby carries the unit, GhostButton defaults to type="button", and the GhostInput ref provides focus(). A component would add exports without removing any of that wiring. The clear action has to reach the caller's model either way.

GhostInputGroup in the spec index identifies this design. It names no export. The recipe imports existing @ghostvue/themes components. A headless consumer uses the same markup with @ghostvue/vue parts or native elements and owns the styles.

Recipe contract ​

A group is a layout element around one input and its adornments. It has no props, events, slots or exposed methods, because it is the example's own element. The parts are:

PartElementOwns
Group<span> or <div> with an example classGrid layout only. No role, name, ID, tabindex, listener or ARIA.
InputGhostInput, unchangedLabel target, ID, name, value, validation attributes, invalid, ref and focus.
Text adornmentPlain element with an IDA unit or prefix readers must hear. Referenced from the input's aria-describedby.
Decorative iconInline <svg aria-hidden="true">Nothing. It is hidden from assistive technology and is not a click target.
ActionGhostButton (default type="button")One named action, such as Clear search. It never submits.

State model ​

Value and the clear action ​

The clear button requires a controlled v-model on GhostInput. Its click handler writes '' to that model and then calls focus() on the input ref. It never writes element.value, so GhostInput remains the only writer of the DOM value. An uncontrolled input cannot offer the clear action in this recipe.

Render the button only while it has something to do:

ts
const canClear = computed(() => query.value !== '' && !disabled && !readonly)

Typing the first character adds the button and deleting the last character removes it. The input keeps focus in both cases, so neither transition moves focus.

Loading, empty, disabled, read-only, and error states ​

  • Empty. No clear button. A text adornment stays visible.
  • Disabled. GhostField disabled disables the input, and the clear button is not rendered. A disabled input submits nothing.
  • Read-only. readonly on the input keeps it focusable and submitted. The clear button is not rendered, because clearing is an edit.
  • Invalid. GhostField invalid marks the input. Only the input shows the danger border; the group and adornments carry no invalid state.
  • Loading. None. Pending search work belongs to the caller.

Async behavior ​

None. The recipe starts no timers or requests.

Consumer data ​

The form submits only the input's own entry, such as timeoutSeconds=30 or q=forecast. Adornment text is never submitted, so a receiver that needs the unit should get it from the field name or a separate named control. Buttons with type="button" add no entries. The recipe does not trim, parse or mutate the caller's value.

Accessibility contract ​

Semantics and relationships ​

  • Name. GhostFieldLabel names the input through for/id. Do not wrap the group in a <label>. HTML allows no labelable element inside a label other than its own control, and a nested button's name can join the input's accessible name.
  • Text adornment. Visible text with its own ID. Put that ID first in the input's aria-describedby, followed by the IDs GhostFieldControl supplies, so the unit qualifies the value before the hint is read: “Request timeout, 30, seconds. Between 1 and 120.” GhostFieldControl passes aria-describedby as a slot prop and does not merge caller IDs, so bind the joined list after v-bind="field". Drop empty tokens. Keep the text in reading order too. Browse mode may read it twice, which is better than losing it if a reference breaks. Spell out an abbreviation such as “GB” with visually hidden text inside the adornment when its spoken form would be unclear.
  • Prefix. A start adornment, such as https://, follows the same rules.
  • Decorative icon. aria-hidden="true" and focusable="false" on the <svg>. It contributes nothing to any name.
  • Action. An icon-only GhostButton with icon-only, an aria-label naming the action and field (“Clear search”) and an aria-hidden glyph in data-part="icon". Visible text such as “Clear” also works and needs no aria-label.
  • Group. No role and no name. A named group around one control would repeat the input's label.

Keyboard interaction ​

The recipe adds no key handlers.

  • Tab / Shift+Tab follow DOM order: input, then the clear button when present, then the next control. The icon and unit are not focusable.
  • Enter in the input performs the form's implicit submission. The clear button is never the default button because it is type="button". A native <button> without a type placed before the real submit button would be the default button and would clear and submit on Enter, so the recipe always uses GhostButton or an explicit type="button".
  • Enter / Space on the clear button run its click handler. Neither submits.
  • Escape in a search input keeps native behavior. Where the browser clears a search field on Escape, the native input event updates the model as typing does. Engines differ here, so the button stays in the Tab order as the keyboard path in every browser.

Focus behavior ​

  • After clearing, by pointer, Enter or Space, focus moves to the input. The handler focuses the input in the same tick that it writes '', before the button unmounts.
  • When the button disappears for another reason while it holds focus, for example a caller switches the input to read-only, move focus to the input in a pre-flush watcher on canClear. When the same render disables the input, focus is lost as it is when disabling any focused control, and the caller that disables the field owns where focus goes.
  • Form reset clears the model through GhostInput's reset reconciliation. Focus stays on the reset button that started it.
  • Visible focus. Each focusable part keeps its own themed focus ring. The group sets no overflow that would clip a ring, and its gap keeps adjacent rings from overlapping.

Assistive technology expectations ​

A user reaches an ordinary textbox or searchbox named by its label, with the unit as its first description. Clearing announces the focused, now empty field. A results count that the caller already renders in a status region, like the report-search example, announces the new count. The recipe adds no live region of its own.

Rendering and customization ​

Unit suffix ​

vue
<script setup lang="ts">
import { computed, ref, useId } from 'vue'
import {
  GhostButton,
  GhostField,
  GhostFieldControl,
  GhostFieldDescription,
  GhostFieldError,
  GhostFieldLabel,
  GhostInput,
} from '@ghostvue/themes'

const timeout = ref('30')
const unitId = `${useId()}-unit`
const invalid = computed(() => {
  const seconds = Number(timeout.value)
  return !/^\d+$/.test(timeout.value) || seconds < 1 || seconds > 120
})

function describedBy(fieldIds: string | undefined): string {
  return [unitId, fieldIds].filter(Boolean).join(' ')
}
</script>

<template>
  <form novalidate @submit.prevent>
    <GhostField :invalid>
      <GhostFieldLabel>Request timeout</GhostFieldLabel>
      <GhostFieldDescription>Between 1 and 120.</GhostFieldDescription>
      <GhostFieldControl v-slot="field">
        <span class="unit-group">
          <GhostInput
            v-bind="field"
            v-model="timeout"
            :aria-describedby="describedBy(field['aria-describedby'])"
            name="timeoutSeconds"
            inputmode="numeric"
            autocomplete="off"
            block
          />
          <span :id="unitId" class="unit-group__text">seconds</span>
        </span>
      </GhostFieldControl>
      <GhostFieldError v-if="invalid">
        Enter a whole number from 1 to 120.
      </GhostFieldError>
    </GhostField>
    <GhostButton type="submit">Save timeout</GhostButton>
  </form>
</template>

<style scoped>
.unit-group {
  align-items: center;
  display: grid;
  gap: var(--ghost-space-gap-sm);
  grid-template-columns: minmax(50%, 1fr) minmax(0, auto);
}
.unit-group__text {
  color: var(--ghost-text-muted);
  overflow-wrap: anywhere;
}
</style>
vue
<script setup lang="ts">
import { computed, ref, useTemplateRef, watch } from 'vue'
import {
  GhostButton,
  GhostField,
  GhostFieldControl,
  GhostFieldLabel,
  GhostInput,
  type GhostInputExposed,
} from '@ghostvue/themes'

const { disabled, readonly } = defineProps<{
  disabled?: boolean
  readonly?: boolean
}>()

const query = ref('')
const group = useTemplateRef<HTMLElement>('group')
const input = useTemplateRef<GhostInputExposed>('input')
const canClear = computed(() => query.value !== '' && !disabled && !readonly)

function clear(): void {
  query.value = ''
  // Focus before the button unmounts so focus never falls to <body>.
  input.value?.focus()
}

// The button is the group's only other focusable part.
watch(
  canClear,
  (next) => {
    const active = document.activeElement
    if (
      !next &&
      active !== input.value?.element &&
      group.value?.contains(active)
    )
      input.value?.focus()
  },
  { flush: 'pre' },
)
</script>

<template>
  <form role="search" @submit.prevent>
    <GhostField :disabled>
      <GhostFieldLabel>Search reports</GhostFieldLabel>
      <GhostFieldControl v-slot="field">
        <span ref="group" class="search-group">
          <svg
            class="search-group__icon"
            aria-hidden="true"
            focusable="false"
            viewBox="0 0 16 16"
            width="16"
            height="16"
          >
            <circle cx="7" cy="7" r="4.5" fill="none" stroke="currentColor" />
            <path d="m10.5 10.5 3.5 3.5" stroke="currentColor" />
          </svg>
          <GhostInput
            ref="input"
            v-bind="field"
            v-model="query"
            type="search"
            name="q"
            :readonly
            block
          />
          <GhostButton
            v-if="canClear"
            variant="ghost"
            tone="neutral"
            icon-only
            aria-label="Clear search"
            @click="clear"
          >
            <span data-part="icon" aria-hidden="true">×</span>
          </GhostButton>
        </span>
      </GhostFieldControl>
    </GhostField>
    <GhostButton type="submit">Search</GhostButton>
    <GhostButton type="reset" variant="ghost" tone="neutral">Reset</GhostButton>
  </form>
</template>

<style scoped>
.search-group {
  align-items: center;
  display: grid;
  gap: var(--ghost-space-gap-sm);
  /* Reserve the button's track so the input does not resize as it appears. */
  grid-template-columns: auto minmax(0, 1fr) var(--ghost-control-size-md-min);
}
.search-group__icon {
  color: var(--ghost-text-muted);
}
/* One clear affordance: hide the UA cancel button inside this group only. */
.search-group :deep(.ghost-input::-webkit-search-cancel-button) {
  display: none;
}
</style>

Layout rules ​

  • Grid, not flex. The themed GhostInput renders a scope <span> around its <input>. That span is not public layout, so the recipe never selects it. Grid tracks size whatever element is the direct child, and block makes the input fill its track.
  • Logical placement. Columns follow the inline direction, so under dir="rtl" the icon sits at the inline start (right) and the button and unit at the inline end (left) with no extra CSS. Use only logical properties. The magnifier and × glyphs are not mirrored.
  • Long text and narrow widths. The unit track can take up to half the group and wraps within itself. At 320 CSS pixels the input keeps at least half the width and nothing scrolls horizontally. A unit longer than a short word belongs in the label instead.
  • Tokens. Spacing and color come from existing semantic tokens. The recipe adds no component tokens and changes no input, field or button selector.
  • Forced colors. Each part keeps its own system-color mapping: the input maps to Field/FieldText, the button to ButtonFace/ButtonText, and text and currentColor icons to CanvasText. The group draws no border or background that forced colors would remove.

The headless adaptation keeps the same markup, relationships and focus handling with @ghostvue/vue GhostField parts, GhostInput and GhostButton, and styles that the example owns.

Environment behavior ​

SSR and hydration ​

Server and client render the same markup from the initial value. useId() allocates the unit ID once per instance, so the description reference resolves in server HTML before JavaScript runs. The clear button renders on the server only when the initial query is nonempty and editable. The watcher reads document only when canClear changes, which happens only on the client.

Mobile and touch ​

The icon-only button uses the themed control size, including the coarse-pointer floor. Native inputmode, type="search" and autocomplete choose the virtual keyboard. The unit and icon are not touch targets. The input fills the remaining track, so its target stays large.

Performance ​

Constant-time rendering per instance. No global listeners. The only reactive work is one computed boolean and one watcher on it.

Composition ​

  • Reused contracts. GhostField parts for name, hint and error; GhostInput for value, validation, reset and ref; GhostButton for the named action and its non-submitting default type; ADR 0013 for icons.
  • NumberInput. Do not wrap GhostNumberInput in a group. Its root, steppers and spinbutton are its public layout, and a suffix after the increment button would read out of order. Use formatOptions instead, for example { style: 'unit', unit: 'second', unitDisplay: 'long' }, or the currency style in the order-limits example. The formatted text then appears in the field and in aria-valuetext.
  • A plain field is enough when:
    • the unit can go in the label (“Request timeout (seconds)”);
    • the value is numeric with bounds, stepping or locale formatting (GhostNumberInput);
    • a search needs no explicit clear action (report search keeps the native field).
  • Placeholder is never a unit or a label.

Test plan ​

Collect this evidence with the executable recipes in the implementation issue.

Unit suffix. The textbox is named Request timeout and described as seconds Between 1 and 120. Entering 0 adds Enter a whole number from 1 to 120. to the description and sets aria-invalid="true" on the input only. Submitting 30 yields one entry, timeoutSeconds=30. Clicking the unit text does not move focus.

Clearable search.

StateTab stops in orderClear searchEntries in new FormData(form)
EmptySearch reports → Search → ResetAbsentq=
Typed forecastSearch reports → Clear search → Search → ResetPresentq=forecast
Read-only with forecastSearch reports → Search → ResetAbsentq=forecast
Disabled with forecastSearch → ResetAbsentEmpty
  • Browser and keyboard. Assert names, descriptions and real focus (toBeFocused()) in both Tab directions in each row. Activate Clear by click, Enter and Space: the value becomes empty, the input is focused, the button is gone and no submit event fires. Enter in the input submits once with q=forecast. Reset empties the field, removes the button and leaves focus on Reset. Switch to read-only while Clear is focused: focus moves to the input. Confirm a single visible clear affordance in Chromium, Firefox and WebKit, and record Escape behavior per engine without asserting it.
  • Accessibility. Run axe on each state above and on the unit example with and without its error. Check the icon is absent from the accessibility tree and the button's name is exactly Clear search.
  • Layout. At 320 CSS pixels and 1280 CSS pixels, in light, dark and dir="rtl", check placement, visible focus rings on the input and button, no horizontal scrolling and wrapping of a long unit. Emulate forced-colors: active and check that the input border, button and focus indicator remain visible.
  • SSR and hydration. Server-render two unit groups and assert each description reference resolves to its own unit. Hydrate with a nonempty initial query and assert no hydration warnings and a working Clear.
  • Types. Typecheck both themed SFCs against public imports in the playground and in a clean packed consumer. There is no new exported type and no framework-neutral logic, so no unit or type fixture is needed.
  • Assistive technology. On NVDA with Firefox and VoiceOver with Safari, confirm the unit is heard with the value, the icon is silent, Clear is named and announced as a button, and focus lands on the empty field after clearing. Record tester, revision, versions and observations per the assistive-technology review process.

Documentation plan ​

Add a section to the Input guide, after its existing lead, that shows the themed unit-suffix and clearable-search examples. Follow it with a headless adaptation and the “plain field is enough” guidance above, and link it from the NumberInput guide's formatting section. Register the examples in the Input manifests and the playground. Example IDs: input/unit-suffix, input/clearable-search and input/clearable-search-headless. Keep input/search as the plain-field case.

Compatibility and release impact ​

Issue #465 schedules this design for 0.2.0. This docs-only spec needs no Changeset. Under option A the implementation issue adds examples and manifest example metadata only. GhostInput, GhostField, GhostButton and GhostNumberInput keep their public contracts, and a consumer who adds no group sees no change. Release inclusion is a separate decision.

Open architectural questions ​

None. The maintainer approved three choices on 2026-11-29:

  1. Package ownership: the themed documentation recipe with no new exports, not themed or headless compound parts.
  2. Visual treatment: adjacent parts that keep their own border and focus ring, not attached chrome with one shared border.
  3. Clear button focus: the button stays in the Tab order, because Escape clearing differs across engines.

Reconsider themed parts (option B) if the attached look becomes a requirement, or if independent consumers repeat the description join and clear-focus handling enough that an export would remove real duplication.