# Textinput

> A Textinput widget to allow user to enter string chains

import textinputPlaceholderJson
from '../../../../../public/template/widgets/textinput/textinput-placeholder.json?raw';

Textinput widgets are [Input Fields](https://golemui.com/dx/widgets-reference/input-fields/overview.md) that allow the user to enter string chains.


```ts title="textinput.ts"

export default [
  gui.inputs.textInput('listName', {
    label: 'First Name',
  }),
];
```

_Live demo on the docs page. Form definition: [textinput.ts](https://golemui.com/template/widgets-dx/textinput/textinput.ts)._

## Props

Use this `props` to customize your Textinput widget.

| prop           | type   | description                                                       |
| -------------- | ------ | ----------------------------------------------------------------- |
| `autocomplete` | string | `'on'`, `'off'`, or a space-separated list of W3C autofill tokens |
| `hint`         | string | A description to display below the text input                     |
| `icon`         | string | A css class to display an icon                                    |
| `placeholder`  | string | A placeholder text to display when the text input has no value    |

### Placeholder

Use the property `placeholder` to add a placeholder.


```ts title="textinput.ts"

export default [
  gui.inputs.textInput('listName', {
    placeholder: 'Enter your first name',
    label: 'First Name',
  }),
];
```

_Live demo on the docs page. Form definition: [textinput-placeholder.ts](https://golemui.com/template/widgets-dx/textinput/textinput-placeholder.ts)._

### Hint

<Aside>A `label` is required for the `hint` to be displayed.</Aside>

Use the property `hint` to add a description.


```ts title="textinput.ts"

export default [
  gui.inputs.textInput('password', {
    hint: 'Your street address as stated in your Document ID',
    label: 'Street Address',
  }),
];
```

_Live demo on the docs page. Form definition: [textinput-hint.ts](https://golemui.com/template/widgets-dx/textinput/textinput-hint.ts)._

### Icon

Use the property `icon` to add an icon to the `textinput`. The value of `icon` represents a set of CSS classes separated by spaces.


```ts title="textinput.ts"

export default [
  gui.inputs.textInput('phoneNumber', {
    icon: 'phone_callback',
    label: 'Phone Number',
  }),
  gui.inputs.textInput('email', {
    icon: 'alternate_email',
    label: 'Email',
  }),
];
```

_Live demo on the docs page. Form definition: [textinput-icon.ts](https://golemui.com/template/widgets-dx/textinput/textinput-icon.ts)._

## Styling

Textinputs can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables and a quick description of what you will style.

| CSS Variable                | Description                             |
| --------------------------- | --------------------------------------- |
| `--gui-space-gap--inner`    | Label gap and margin bottom             |
| `--gui-padding`             | Input padding                           |
| `--gui-color-border`        | Input border color                      |
| `--gui-radius`              | Input radius                            |
| `--gui-color-bg`            | Input background color                  |
| `--gui-color-fg`            | Input text color                        |
| `--gui-color-primary`       | Input border color and outline on focus |
| `--gui-color-error`         | Input border color when invalid         |
| `--gui-space-gap`           | Icon left padding                       |
| `--gui-icon-space-gap`      | Icon right padding                      |
| `--gui-font-size--small`    | Hint font size                          |
| `--gui-color-fg--secondary` | Hint font color                         |

### Anatomy

This is the anatomy of the Textinput Widget in case you want to use your CSS styles.


```html title="textinput.html"
<gui-textinput-input class="gui-textinput gui-field">
  <gui-textinput class="gui-field">
    <label class="gui-label" for="fieldUid" id="fieldUid_label">
      <span class="gui-label__text">Label</span>
      <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
    </label>

    <div class="gui-widget">
      <input
        type="text"
        id="fieldUid"
        class="gui-widget-input gui-textinput--icon"
        placeholder="Custom placeholder"
        aria-describedby="fieldUid_hint"
      />
      <span
        aria-hidden="true"
        class="gui-widget-icon phone_callback"
        data-icon="phone_callback"
      ></span>
    </div>

    <div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div>
  </gui-textinput>
</gui-textinput-input>
```
