SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

TextField

A labeled, described and validated single-line text field.

Create a workspace

You can rename it later; the address stays.

Shown to everyone you invite.

Enter an address we can invoice.
View code
tsx
<form
	method="post"
	action="/examples/workspaces"
	mix={[on<HTMLFormElement, "submit">("submit", (event) => event.preventDefault())]}
>
	<Card>
		<Card.Header>
			<Card.Title>Create a workspace</Card.Title>
			<Card.Description>You can rename it later; the address stays.</Card.Description>
		</Card.Header>
		<Card.Content mix={[vstack({ gap: 4, align: "stretch" })]}>
			<TextField name="name" required autoComplete="organization" defaultValue="Acme Design">
				<TextField.Label>Workspace name</TextField.Label>
				<TextField.Description>Shown to everyone you invite.</TextField.Description>
			</TextField>

			<TextField type="email" name="billingEmail" required defaultValue="billing@acme">
				<TextField.Label>Billing email</TextField.Label>
				<TextField.Error>Enter an address we can invoice.</TextField.Error>
			</TextField>
		</Card.Content>
		<Card.Footer mix={[hstack({ gap: 2, align: "center", justify: "end" })]}>
			<Button type="submit">Create workspace</Button>
		</Card.Footer>
	</Card>
</form>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add text-field

Usage

typescript
import { TextField } from "@sdxc/ui";

Renders a text field: the control from the native attributes, laid out with the parts the caller writes. A .Prefix or .Suffix joins the control as one bordered field; an enclosing Form's issue for name shows as the error when no .Error is written.

Examples

Invalid value

Usernames need at least 3 characters.
View code
tsx
<TextField name="username" defaultValue="ab">
	<TextField.Label>Username</TextField.Label>
	<TextField.Error>Usernames need at least 3 characters.</TextField.Error>
</TextField>

With a prefix or suffix

Teammates open the workspace at this address.

View code
tsx
<TextField name="slug" defaultValue="northwind">
	<TextField.Label>Workspace URL</TextField.Label>
	<TextField.Prefix>pulse.dev/</TextField.Prefix>
	<TextField.Description>Teammates open the workspace at this address.</TextField.Description>
</TextField>
<TextField name="budget" type="number" defaultValue="250">
	<TextField.Label>Monthly budget</TextField.Label>
	<TextField.Prefix>$</TextField.Prefix>
</TextField>
<TextField name="threshold" type="number" defaultValue="800">
	<TextField.Label>Alert after</TextField.Label>
	<TextField.Suffix>ms</TextField.Suffix>
</TextField>

With a hint

Use at least 12 characters, mixing letters and numbers.

View code
tsx
<TextField type="password" name="password" autoComplete="new-password">
	<TextField.Label>Password</TextField.Label>
	<TextField.Description>Use at least 12 characters, mixing letters and numbers.</TextField.Description>
</TextField>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
color"brand" | "neutral" | "success" | "warning" | "danger"—NoSemantic color role for the control's focus ring. Defaults to "neutral" when omitted.
autoFocusboolean—NoNative autofocus. Defaults to true for the first invalid field of an enclosing Form's issues, landing keyboard focus on the problem with no client JavaScript; pass explicitly to override.
type"text" | "email" | "password" | "tel" | "url" | "search" | "number"—NoNative <input> type. Defaults to DEFAULT_TYPE.
namestring—NoNative name; it also finds the enclosing Form's issue for this field.
valuestring—No
defaultValuestring—No
placeholderstring—No
requiredboolean—No
disabledboolean—No
readOnlyboolean—No
autoCompletestring—No
patternstring—No
minLengthnumber—No
maxLengthnumber—No
childrenRemixNode—NoThe field's parts: .Label, .Description, .Error, .Prefix and .Suffix. The control follows the caption, the addons join it, and the rest keep their order.

Also accepts everything in Omit<TagProps<"div">, "prefix">.

Types

NameValuesWhat it decides
Color"brand" | "neutral" | "success" | "warning" | "danger"Semantic color role for the control's keyboard focus ring, each mapped to its matching --ui-* variables.
Type"text" | "email" | "password" | "tel" | "url" | "search" | "number"Native <input> type this field renders a single-line, text-like control for.
@sdxc/ui

Can’t find it? Contact us