This browser is not supported. The glass needs a Chromium browser or Electron. Why

Text fields

TextField, SecureField and TextEditor are real input and textarea elements, drawn with the iOS caret, selection, handles and glass edit menu.

import { SecureField, TextEditor, TextField } from "@adamexu/glass";

Fields

Autofill, IME, undo, spell checking and native selection are the browser's. title is the placeholder (unless prompt is given) and the accessible name. Return in a one-line field calls onSubmit and ends editing; composition never submits. A vertical field grows with its text up to its lineLimit, then scrolls.

press Return in Search
const [query, setQuery] = useState("");
const [submitted, setSubmitted] = useState<string | null>(null);

<TextField title="Name" autoComplete="name" />
<TextField
  title="Search"
  textFieldStyle="roundedBorder"
  text={query}
  onTextChange={setQuery}
  onSubmit={() => setSubmitted(query)}
/>
<SecureField title="Password" textFieldStyle="roundedBorder" autoComplete="current-password" />
<TextField title="Notes" axis="vertical" lineLimit={[2, 5]} />

In a Form

The default style is plain, which is how a field sits in a Form row. A label is drawn 8 px before the field, as LabeledContent. A TextEditor has no placeholder, as in SwiftUI, and grows with its text from minHeight.

const [values, setValues] = useState(EMPTY);
const set = (patch) => setValues((v) => ({ ...v, ...patch }));

<NavigationStack
  root={
    <NavigationPage title="Input" toolbar={<ToolbarItem title="Clear" icon={X} onAction={() => setValues(EMPTY)} />}>
      <Form>
        <Section header="Text Field">
          <TextField title="Name" text={values.name} onTextChange={(name) => set({ name })} autoComplete="name" />
          <TextField title="Email" text={values.email} onTextChange={(email) => set({ email })} inputMode="email" autoComplete="email" autoCapitalize="none" />
        </Section>
        <Section header="Secure Field">
          <SecureField title="Password" text={values.password} onTextChange={(password) => set({ password })} autoComplete="current-password" />
        </Section>
        <Section header="Multiline Text Field">
          <TextField title="Bio" text={values.bio} onTextChange={(bio) => set({ bio })} axis="vertical" lineLimit={[3, 6]} />
        </Section>
        <Section header="Text Editor">
          <TextEditor text={values.notes} onTextChange={(notes) => set({ notes })} minHeight={120} aria-label="Notes" />
        </Section>
      </Form>
    </NavigationPage>
  }
/>

Props

TextField

PropTypeDefaultDescription
textstring-Controlled text: SwiftUI's text: binding.
defaultValuestring""Initial text when uncontrolled.
onTextChange(text: string) => void-Every edit.
tintstringcaret blueCaret, handles and selection.
disabledbooleanfalseTakes no touches. It looks the same, as on iOS.
autoCompletestring-SwiftUI's .textContentType, as the browser's autofill names it.
inputMode"text" | "email" | "url" | "numeric" | "decimal" | "tel" | "search"-SwiftUI's .keyboardType, for on-screen keyboards.
autoCapitalize"none" | "sentences" | "words" | "characters"-.textInputAutocapitalization.
autoCorrectboolean-false: autocorrect="off" and spellCheck off.
onSubmit() => void-Return in a one-line field, which also ends editing. A vertical field and an editor take Return as a new line.
editMenubooleantrueThe glass text-edit menu (never on a secure field).
name, id, autoFocusstring, string, boolean-On the element.
onFocus, onBlur() => void-Editing begins and ends.
aria-labelstring-The accessible name; title otherwise.
className, stylestring, CSSProperties-On the field's box.
titlestring-The placeholder, unless prompt is given, and the accessible name.
promptstring-The placeholder in place of the title.
labelReactNode-LabeledContent's label, drawn 8 px before the field.
textFieldStyle"automatic" | "plain" | "roundedBorder""automatic"automatic is plain.
axis"horizontal" | "vertical""horizontal"vertical is a <textarea> that grows with its text.
lineLimitnumber | readonly [number, number]-Vertical only: rows jump (no animation); past the most it scrolls.

SecureField

PropTypeDefaultDescription
all of TextField's-Except axis and lineLimit. A real type="password" input; no edit menu.

TextEditor

PropTypeDefaultDescription
textstring-Controlled text: SwiftUI's text: binding.
defaultValuestring""Initial text when uncontrolled.
onTextChange(text: string) => void-Every edit.
tintstringcaret blueCaret, handles and selection.
disabledbooleanfalseTakes no touches. It looks the same, as on iOS.
autoCompletestring-SwiftUI's .textContentType, as the browser's autofill names it.
inputMode"text" | "email" | "url" | "numeric" | "decimal" | "tel" | "search"-SwiftUI's .keyboardType, for on-screen keyboards.
autoCapitalize"none" | "sentences" | "words" | "characters"-.textInputAutocapitalization.
autoCorrectboolean-false: autocorrect="off" and spellCheck off.
editMenubooleantrueThe glass text-edit menu (never on a secure field).
name, id, autoFocusstring, string, boolean-On the element.
onFocus, onBlur() => void-Editing begins and ends.
aria-labelstring-The accessible name; title otherwise.
className, stylestring, CSSProperties-On the field's box.
minHeightnumber-SwiftUI's .frame(minHeight:): grows with its text from here.
heightnumber-.frame(height:): fixed, scrolls inside.

What is drawn

  • A 2 px caret that blinks in iOS's discrete steps: 1 s, restarted solid by any move or key, first shown 180 ms after focus, gone at once on blur.
  • The selection fill, line-tall and out to the text view's edge on wrapped lines, and its handles.
  • A secure field's discs. The last character typed shows for 2 s (not the first into an empty field).

The edit menu

The text-edit menu is glass. A press-and-lift that makes a selection opens Cut, Copy, AutoFill, Look Up and a chevron (Cut, Copy, Paste, AutoFill when there is something to paste); a tap on the caret where it already stood opens Select, Select All, (Paste,) AutoFill 305 ms later. Paste shows only when this page cut or copied text, or the clipboard can be read without a prompt. The chevron morphs the capsule into a menu of the rest: Look Up, Translate and Search Web open a search page in a new tab; Share is the browser's share sheet; AutoFill is drawn off. The browser's own context menu stays on a secondary click.

Accessibility

The accessible name is aria-label, else title. disabled looks the same, as on iOS.

SwiftUI

SwiftUI@adamexu/glass
TextField("Name", text: $name)<TextField title="Name" text onTextChange>
TextField("Name", text:, prompt: Text("..."))prompt="..."
TextField(..., axis: .vertical).lineLimit(3...6)<TextField axis="vertical" lineLimit={[3, 6]}>
.textFieldStyle(.roundedBorder / .plain)textFieldStyle="roundedBorder" / "plain"
LabeledContent("Label") { TextField(...) }<TextField label="Label">
.onSubmit { }onSubmit
.textContentType(.emailAddress) / .keyboardType(.emailAddress)autoComplete="email" / inputMode="email"
.textInputAutocapitalization(.never) / .autocorrectionDisabled()autoCapitalize="none" / autoCorrect={false}
.tint(c) on a fieldtint={c}
SecureField("Password", text:)<SecureField title="Password" text onTextChange>
TextEditor(text:).frame(minHeight: 120) / .frame(height: 80)<TextEditor minHeight={120}> / height={80}
.disabled(true) on a fielddisabled