Input Primitive
Use Input to collect a short text value such as an email address. It uses a native input and can share its state with a Field.
Anatomy
Use the Astro primitive adapter to render Input anatomy with the Runtime wiring included.
---import { Input } from "@starwind-ui/astro/input";---
<Input.Root placeholder="Email" />Use the React primitive adapter when Input state participates in React rendering.
import { Input } from "@starwind-ui/react/input";
export function Example() { return ( <Input.Root placeholder="Email" /> );}Use the Vue components to build Input.
<script setup lang="ts">import Input from "@starwind-ui/vue/input";</script>
<template> <Input.Root placeholder="Email" /></template>Use the Svelte components to build Input.
<script lang="ts"> import { Input } from "@starwind-ui/svelte/input";</script>
<Input.Root placeholder="Email" />Render the Input data-sw-* contract yourself, then initialize createInput.
<input data-sw-input placeholder="Email" />
<script type="module"> import { createInput } from "@starwind-ui/runtime/input";
const root = document.querySelector("[data-sw-input]"); if (root) { createInput(root); }</script>Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed package’s types for the available props and events. Plain HTML uses DOM events and Runtime methods.
API Reference
Root
The main element that owns the Input Runtime instance.
- Default element
- input
- Discovery hook
- data-sw-input
- Role
- -
Props
value InputValue -
- Description
- Controls the current Input value.
- Kind
- control
- Targets
- -
- Full type
- InputValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for state changes.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
listen for starwind:value-change and call setValue for later updates.
starwind:value-changesetValue
defaultValue InputValue -
- Description
- Sets the initial Input value for uncontrolled usage.
- Kind
- control
- Targets
- -
- Full type
- InputValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for state changes.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
listen for starwind:value-change and call setValue for later updates.
starwind:value-changesetValue
disabled boolean false
- Description
- Disables the Root part.
- Kind
- option
- Targets
- -
- Full type
- boolean
name string -
- Description
- Sets the submitted form field name.
- Kind
- attribute
- Targets
- root
- Full type
- string
required boolean -
- Description
- Marks the form control as required.
- Kind
- attribute
- Targets
- root
- Full type
- boolean
onValueChange (value: string, details: InputValueChangeDetails) => void -
- Description
- Runs when the Input value changes.
- Kind
- callback
- Targets
- -
- Full type
- (value: string, details: InputValueChangeDetails) => void
- React
Use value for controlled state and defaultValue for default state, and onValueChange for state changes.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
listen for starwind:value-change and call setValue for later updates.
starwind:value-changesetValue
Events
valueChange onValueChange value: string
- Description
- Fires when the value changes for Input.
- DOM event
- starwind:value-change
- Details type
- InputValueChangeDetails
- Timing
- -
- Cancelable
- No
State
value InputValue value / defaultValue
- Description
- Tracks the current Input value.
- Initial attribute
- -
- Runtime getter
- getValue
- Runtime setter
- setValue
- React
Use value for controlled state and defaultValue for default state, and onValueChange for state changes.
valuedefaultValueonValueChange
- Astro
Use value or defaultValue for initial state, listen for starwind:value-change, and call setValue for later updates.
valuedefaultValuestarwind:value-changesetValue
- Runtime / HTML
listen for starwind:value-change and call setValue for later updates.
starwind:value-changesetValue
Data Attributes
Runtime hooks
Metadata
Runtime API
- Factory
createInput- Import
@starwind-ui/runtime/input- Root hook
- root
data-sw-input - Option props
- defaultValue, disabled, onValueChange, value
Runtime Setters
Form Participation
| Fact | Value |
|---|---|
| Form props | name, required, value |
| Hidden input | - |
| Field integration | Yes |
Related Styled Components
Changelog
View version history v1.1.1 8 releases
v1.1.1
- In Svelte, Input no longer clears the text that the user typed when the parent changes another prop, such as `class` or `disabled`. This happened when it had no `value` prop or used `bind:value`.
- In Vue, this component now needs Vue 3.5.21 or newer.
v1.1.0
- In Astro, an attribute that you set on an Input part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.
- In Svelte, a defined `value` that you pass when Input mounts now stays under your control, as in React and Vue. To change it, use `bind:` or update your state in the change callback. A form reset keeps it. If you pass `undefined` at mount, Input keeps its own state. Input also follows `push()` and `splice()` on a `$state` array.
- Fixed Input writing an unchanged value back into the field. In some browsers this moved the caret or ended an IME composition.
- Vue Input now keeps the caret during a normal edit, puts the old text back when the parent refuses a change, and follows a `v-model` that starts as `undefined`.
v1.0.3
- In Svelte apps that render on the server, a form reset now puts Input back to its default value. Before, a reset after the page loaded cleared it.
v1.0.2
- Kept the input working when its elements are replaced or it moves to another form.
- Updated the shared setup file included with the Astro Primitive. Its public API and behavior are unchanged.
v1.0.1
- Removed old comments from the Vue Primitive files that said the code was internal and not for release. The CLI also removes the blank line that these comments left in the Vue Primitive `index.ts` files that it copies into your project.
v1.0.0
- This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.
v0.1.1
- The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.
v0.1.0
- First release. Input keeps its value in sync with Starwind Runtime. Native input attributes and events still work.