Skip to content

GhostInput ​

GhostInput is an unstyled native single-line text control with a string v-model and first-class disabled, readonly, invalid, and required states. Import it from @ghostvue/vue for headless use, or from @ghostvue/themes for the default visual treatment.

Account details

Account form with labels, hints, live email validation, and readonly and disabled fields.

The account form composes themed GhostInput with GhostField for labels, hints, and errors. The work email validates as you type: invalid on the field sets aria-invalid on the input and links the error through aria-describedby. The workspace URL is readonly, so it stays focusable and is submitted. The billing contact is disabled. Long values stay on one line and end with an ellipsis at rest; long hints and errors wrap. The form keeps a 28rem maximum width and the name row stacks when it gets narrow.

Basic use ​

Use a visible label with the native <input>. Use GhostField when the field also needs a hint or error.

Themed use ​

Themed

Size props on the @ghostvue/themes wrapper, with aligned labels.

Importing the themed component loads the default stylesheet. Visual props exist only on this wrapper:

@ghostvue/themes adds these to the headless GhostInput API, which it forwards:

PropTypeDefaultDescription
size'sm' | 'md' | 'lg'"md"Control size. The default omits data-size so CSS can treat a missing hook as md.
blockbooleanfalseStretch to the available inline size via data-block.

Themed size, padding, radius, and type come from density and control tokens. Comfortable md is 40px tall with an 8px radius at --ghost-roundness: 1. See density, type, and roundness. There are no per-component tokens.

You can also import the stylesheet and wrap unstyled inputs in .ghost-theme when you want a region of headless components to pick up the defaults. See the default theme guide.

Disabled, readonly, invalid, and required ​

States

Disabled, readonly, invalid, and required, composed with GhostField.

Use letters, numbers, and hyphens only.

Each state is set on GhostField, which forwards disabled, invalid, and required to the input; readonly goes on the input directly. Without a field, pass the same props to GhostInput.

Disabled uses the native disabled attribute. Readonly uses native readonly. Required uses native required. Invalid is a consumer flag for custom or async errors; native constraint validation still runs on submit for required / pattern / maxlength.

type="search" keeps native search behavior for DataTable-style filters. This sample filters a local list of reports and announces the match count:

Search

Controlled type=search filtering a local list of reports.

Add a unit, icon, or clear button ​

GhostInput has no slots. To put content beside it, wrap the themed input from @ghostvue/themes in a grid of your own, next to GhostField and GhostButton. The input keeps its label, value, validation attributes, ref, and form behavior. Nothing new is imported.

Unit suffix

A visible unit beside the input, read as the first description and never submitted.

seconds

A unit that readers must hear is visible text with its own ID. Put that ID first in the input's aria-describedby, ahead of the IDs GhostFieldControl supplies, which it does not merge for you. The unit is not submitted: timeoutSeconds=30 carries it in the field name. A prefix such as https:// works the same way at the start of the grid.

Clearable search

Report search with a decorative icon and a Clear button that returns focus to the field and never submits.

The magnifier is decorative: aria-hidden="true" and focusable="false". Clear search is an icon-only GhostButton, which defaults to type="button". Activating it never submits the form, and Enter in the field submits without clearing. It appears only while there is text and the field is editable. Clearing writes '' to the v-model and moves focus to the input, and focus also moves there if the button disappears while it has focus. The button stays in the Tab order because browsers differ on whether Escape clears a search field. Inside the group, the browser's own cancel button is hidden so there is one clear control. Columns follow the inline direction, so the icon sits at the start and the button at the end in RTL too. A headless version uses the same markup with styles the example owns.

Use a plain field when the unit fits in the label ("Request timeout (seconds)"), when a search needs no clear button, or when the value is a bounded or formatted number: use GhostNumberInput with formatOptions instead of a suffix. Do not wrap the group in a <label>, and never use a placeholder as a unit or label. See the input group specification for the full contract.

Enter a duration (mm:ss) ​

There is no duration component. For an elapsed time such as a bake time or a segment length, use one GhostInput inside GhostField, keep the value in seconds, and convert at the edges.

Duration (mm:ss)

A minutes-and-seconds field that parses to whole seconds, shows a field error for out-of-range seconds, and drives a progress bar.

checkout-api canary

Tideline promotes the canary to production after it bakes without errors.

Baking in us-east02:10 of 05:00

The field holds the text the reader types, and the saved value is a number of seconds. Three small functions do the work, and you can copy them from the source:

  • parseDuration accepts one or two minute digits and exactly two second digits, so 5:00 and 05:00 both save 300 seconds. It returns an error message instead of throwing: 01:75 gives "Seconds must be from 00 to 59.", text without a colon asks for the format, and anything outside 00:30 to 30:00 gives the range.
  • formatDuration turns seconds back into zero-padded mm:ss. After a save the field shows that text, so 5:00 becomes 05:00.
  • speakDuration gives the progress bar spoken value text such as "2 min 10 s of 5 min", because screen readers read 02:10 as digits or a clock time.

The format is in the label's description, not a placeholder. Errors wait for the first Save, then update as the reader corrects the text, and a failed save moves focus to the field. Leave inputmode unset: many phone number pads have no colon key.

GhostProgress already takes seconds, so the bar beside the field uses the same saved value as max and needs no conversion. Its visible text uses formatDuration and its valueText uses speakDuration.

An hour or more ​

Don't let minutes run past 59, because 90:00 is hard to read. Add an hours segment instead, say so in the description ("h:mm:ss"), and keep storing seconds:

ts
const match = /^(?:(\d+):)?(\d{1,2}):(\d{2})$/.exec(text.trim())
// match[1] is hours or undefined; check minutes and seconds are 0 to 59.
const total =
  Number(match[1] ?? 0) * 3600 + Number(match[2]) * 60 + Number(match[3])

Format it back the same way (1:05:00). The pattern also accepts plain mm:ss, so drop the hours segment when it is zero.

Customize with headless controls ​

Import from @ghostvue/vue to provide your own styles, or bind the composable to a native element.

Basic Headless

Native labeled text field. The default type is text.

Composable Headless

Same contract as GhostInput, applied to a native host.

For a headless adornment with consumer-owned styles, see the clearable search example in the headless input reference.

Component refs ​

Component ref Headless

Template refs expose element, focus, and blur.

The ref exposes element, focus(options?), and blur(). Before mount and after unmount, element is null and the methods are safe no-ops. Use element for select() or selection APIs.

Styling ​

The unstyled component renders one native <input> with class ghost-input, data-part="root", and data-state of invalid, disabled, or readonly. Invalid wins when those overlap because native disabled / readonly already cover unavailability. There is no internal wrapper to target.

css
.ghost-input[data-state='invalid'] {
  /* Applies while invalid, including when also disabled. */
}

The themed wrapper sets data-size and data-block from visual props. The default size omits data-size.

API ​

PropTypeDefaultDescription
defaultValuestring""Initial uncontrolled value. Later changes are ignored. Also the form-reset seed.
disabledbooleanfalseApplies native disabled semantics, prevents editing and sequential focus, and omits the field from form submit.
invalidbooleanfalseConsumer-owned validity. Sets aria-invalid and data-state=invalid. Does not mirror native ValidityState.
modelValuestring—Controlled value. Omit for uncontrolled mode. An empty string is a real controlled value, not unset.
readonlybooleanfalseApplies native readonly semantics. The field stays focusable and is submitted, but cannot be edited.
requiredbooleanfalseApplies the native required constraint.
typeGhostInputType"text"Native text-like type (text, search, email, password, tel, url). Checkbox, radio, file, and number are out of scope.

v-model emits update:modelValue on the native input event, matching Vue on a plain <input>. Native listeners such as @change and @blur still attach to the element. Do not pass a native value attribute for the current text.

The component does not generate an id. There is no content slot.

Accessibility and environment behavior ​

The control is a native textbox. Name it with a <label> or ARIA naming attributes. Descriptions and errors attach through aria-describedby. Keyboard editing is native; the component adds no key handlers. Disabled fields are not in the tab order; readonly fields are.

SSR markup is deterministic from props and the current string. Setup does not read browser globals. An owner form reset restores the uncontrolled seed.

See the GhostInput specification for the complete behavior and compatibility contract.