# Text field

Source: https://ecosphere.dev/docs/forms/text-field (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

Labelled inputs with required marks, one line of help, and the two-up field grid.

`import { EcoTextField, EcoField, EcoFieldGrid } from "vue-ecosphere"`

## Field

A label, a required mark and an example placeholder.

Vue (vue-ecosphere):

```vue
<EcoTextField v-model="email" label="Email" required type="email"
  placeholder="john@example.com" autocomplete="off" first />
```

React (react-ecosphere):

```tsx
const [email, setEmail] = useState("");

<EcoTextField value={email} onChange={setEmail} label="Email" required type="email"
  placeholder="john@example.com" autoComplete="off" first />
```

## Filled

Vue (vue-ecosphere):

```vue
<EcoTextField v-model="name" label="Name" first />
```

React (react-ecosphere):

```tsx
const [name, setName] = useState("Kiara Casmer");

<EcoTextField value={name} onChange={setName} label="Name" first />
```

## Grid

fgrid puts two fields side by side.

Vue (vue-ecosphere):

```vue
<EcoFieldGrid first>
  <EcoTextField v-model="title" label="Title" required placeholder="Engineer" />
  <EcoTextField v-model="company" label="Company" required placeholder="Northwind" />
</EcoFieldGrid>
```

React (react-ecosphere):

```tsx
const [title, setTitle] = useState("");
const [company, setCompany] = useState("");

<EcoFieldGrid first>
  <EcoTextField value={title} onChange={setTitle} label="Title" required placeholder="Engineer" />
  <EcoTextField value={company} onChange={setCompany} label="Company" required placeholder="Northwind" />
</EcoFieldGrid>
```

## Hint and error

One line of help. The error replaces the hint while the value is wrong — add a domain to see the hint come back.

Vue (vue-ecosphere):

```vue
<EcoTextField v-model="handle" label="Email" icon="mail-line"
  hint="The address every notification goes to."
  :error="/@[^@\s]+\.[a-z]{2,}$/i.test(handle) ? undefined : 'That address is missing a domain, like .com.'" first />
```

React (react-ecosphere):

```tsx
const [handle, setHandle] = useState("h.cole@example");

<EcoTextField value={handle} onChange={setHandle} label="Email" icon="mail-line"
  hint="The address every notification goes to."
  error={/@[^@\s]+\.[a-z]{2,}$/i.test(handle) ? undefined : "That address is missing a domain, like .com."} first />
```

## Password with reveal

The eye button swaps the input between password and text; the end of the box is its, so iconEnd is ignored.

Vue (vue-ecosphere):

```vue
<EcoTextField v-model="password" label="Password" type="password" reveal
  autocomplete="current-password" first />
```

React (react-ecosphere):

```tsx
const [password, setPassword] = useState("");

<EcoTextField value={password} onChange={setPassword} label="Password" type="password" reveal
  autoComplete="current-password" first />
```

## Your own control in a field

EcoField wraps any control with the label and help line.

Vue (vue-ecosphere):

```vue
<EcoField label="Workspace" for="ws" hint="Shown in the sidebar." first>
  <input id="ws" v-model="own" class="input" />
</EcoField>
```

React (react-ecosphere):

```tsx
const [own, setOwn] = useState("Northwind");

<EcoField label="Workspace" htmlFor="ws" hint="Shown in the sidebar." first>
  <input id="ws" className="input" value={own} onChange={(e) => setOwn(e.target.value)} />
</EcoField>
```

## EcoTextField

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string` | "" | The input's value. |
| `label` | `string` | — | Field label (field__l), wired to the input with for/id. |
| `required` | `boolean` | false | Adds the req mark after the label. |
| `hint` | `string` | — | One line of help: the format or the range. |
| `error` | `string` | — | Replaces the hint and sets aria-invalid. Never stack the two. |
| `invalid` | `boolean` | false | Invalid without a message. |
| `type` | `"text" \| "email" \| "password" \| "tel" \| "url" \| "search" \| "number"` | "text" | Native input type. |
| `placeholder` | `string` | — | An example value, never the label. |
| `icon` | `string` | — | Leading glyph inside the box (ifield + ifield__ico). Inert. |
| `iconEnd` | `string` | — | Trailing glyph inside the box (ifield--end). Ignored while reveal shows its button. |
| `reveal` | `boolean` | false | With type="password": an eye button at the end of the box shows and hides the value (aria-pressed while shown). |
| `showLabel / hideLabel` | `string` | "Show password" / "Hide password" | Accessible name of the reveal button while the value is hidden / shown. |
| `first` | `boolean` | false | First field in its container: drops the top margin (field--first). |
| `disabled / readonly` | `boolean` | false | Pair disabled with a hint that says why. |
| `id` | `string` | — | Input id; generated when omitted. |
| `…attrs` | `—` | — | name, autocomplete, inputmode and listeners go to the <input>; class/style to the field. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `string` | "" | The input's value. |
| `label` | `string` | — | Field label (field__l), wired to the input with for/id. |
| `required` | `boolean` | false | Adds the req mark after the label. |
| `hint` | `string` | — | One line of help: the format or the range. |
| `error` | `string` | — | Replaces the hint and sets aria-invalid. Never stack the two. |
| `invalid` | `boolean` | false | Invalid without a message. |
| `type` | `"text" \| "email" \| "password" \| "tel" \| "url" \| "search" \| "number"` | "text" | Native input type. |
| `placeholder` | `string` | — | An example value, never the label. |
| `icon` | `string` | — | Leading glyph inside the box (ifield + ifield__ico). Inert. |
| `iconEnd` | `string` | — | Trailing glyph inside the box (ifield--end). Ignored while reveal shows its button. |
| `reveal` | `boolean` | false | With type="password": an eye button at the end of the box shows and hides the value (aria-pressed while shown). |
| `showLabel / hideLabel` | `string` | "Show password" / "Hide password" | Accessible name of the reveal button while the value is hidden / shown. |
| `first` | `boolean` | false | First field in its container: drops the top margin (field--first). |
| `disabled / readOnly` | `boolean` | false | Pair disabled with a hint that says why. |
| `id` | `string` | — | Input id; generated when omitted. |
| `…rest` | `—` | — | name, autoComplete, inputMode, other input props and the ref go to the <input>; className/style to the field. |

## EcoField

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label / required / hint / error / first` | `—` | — | As on EcoTextField. |
| `for` | `string` | — | Id of your control: renders a <label for>. Without it the label is a <span>. |
| `labelId / describedId` | `string` | — | Ids for aria-labelledby and aria-describedby on your control. |
| `slots` | `default · label · hint · error · foot · after` | — | The control goes in the default slot; foot replaces the hint/error line. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label / required / hint / error / first` | `—` | — | As on EcoTextField. |
| `htmlFor` | `string` | — | Id of your control: renders a <label for>. Without it the label is a <span>. |
| `labelId / describedId` | `string` | — | Ids for aria-labelledby and aria-describedby on your control. |
| `children / label / hint / error / foot / after` | `ReactNode` | — | The control goes in children; label, hint and error take nodes; foot replaces the hint/error line; after renders below it. |

## EcoFieldGrid

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `first` | `boolean` | false | First thing in its container: drops the top margin (fgrid--first). |
| `default slot` | `—` | — | Two fields; their own top margins are dropped inside the grid. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `first` | `boolean` | false | First thing in its container: drops the top margin (fgrid--first). |
| `children` | `—` | — | Two fields; their own top margins are dropped inside the grid. |
