# Text field

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FfvdA09tsV12OPZ2js1uh%2FFrame%2045.png?alt=media&#x26;token=884d7a25-fe79-49fb-95c2-ba31e546ee31" alt=""><figcaption></figcaption></figure>

## Overview

Text fields are essential components for collecting short, structured inputs like usernames or emails in a form or interface. They focus on precision and clarity.

{% embed url="<https://www.figma.com/design/4NwKhd4dwRhRF5Zpiooi69/Components?node-id=2-252140&t=0Thv0LIO2gFzE3eo-4>" %}

## When to use

* Use text fields when collecting short, structured data like names, emails, passwords, or addresses.&#x20;
* Ideal for login forms, search bars, and settings pages where concise input is required.&#x20;
* In registration forms or surveys where users need to enter short, specific pieces of information.&#x20;
* Use text fields when form validation is essential, such as for email or phone number formats.&#x20;
* When requiring short user input for querying data or filtering results, a text field is optimal for efficiency.

## When not to use

* Avoid using text fields for multi-line or detailed input. A text area would be more appropriate for longer entries.&#x20;
* Do not use text fields when the input requires complex formatting, such as rich-text editing, since they support only single-line plain text.&#x20;
* Avoid text fields for date selection, numeric range selection, or other structured data inputs where a more specialized input component would improve usability.&#x20;
* If the user must input a large amount of data at once, such as long descriptions or comments, opt for a text area instead.

## Types

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FyTOm0xqRWhVlrA78YWN4%2Fvariants.png?alt=media&#x26;token=761de73b-aae6-4e49-b375-1238449c64c5" alt=""><figcaption></figcaption></figure>

## Anatomy

1. **Label:** Provides context for the input field by indicating what the user should enter.&#x20;
2. **Slot:** An optional, swappable element that can be replaced with other components, providing flexibility for different types of content.&#x20;
3. **Icon Leading:** Optional icon placed on the left side of the text field for visual cues (e.g., search or email icons).&#x20;
4. **Tag:** A small element that provides additional context or metadata about the input (e.g., a required label or field type)&#x20;
5. **Placeholder Text:** An example displayed inside the field before the user begins typing.&#x20;
6. **Count:** Displays character count or input limit, helping users understand how much they can type.&#x20;
7. **Button:** An optional button placed inside the text field for additional functionality.&#x20;
8. **Icon Trailing:** Optional icon on the right side of the text field that may trigger actions (e.g., clear input or show password).&#x20;
9. **Support Message:** Text that provides additional information, such as input validation or instructions.&#x20;
10. **Hint:** Small additional information to assist the user in understanding what to enter.

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FzXdBnaTu2yGh1l7znNnr%2Fanatomy.png?alt=media&#x26;token=87cf63cf-22aa-4b21-854c-65821b8846d6" alt=""><figcaption></figcaption></figure>

## Styles

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FCtldbzidvXrOOkSVzui9%2Fstyle.png?alt=media&#x26;token=edffd5e6-b250-4419-a135-3cdd3a2a5f7e" alt=""><figcaption></figcaption></figure>

## States

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FhmQ6k2aMPArLdoDjlI3Z%2Fstate.png?alt=media&#x26;token=d58ad878-eb2f-482f-914a-65cd93f1d9a1" alt=""><figcaption></figcaption></figure>

## Size

<figure><img src="https://1456965416-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOHrijNlCiWxhWuZ7eBdg%2Fuploads%2FVlzcNqJf8iOnlfl4JBj9%2Fsize.png?alt=media&#x26;token=4cd6cef2-968a-4ee2-8547-fdc687b94b4e" alt=""><figcaption></figcaption></figure>

| Size   | Text (px) | Icon (px) | Corner (px) | Container Height (px) |
| ------ | --------- | --------- | ----------- | --------------------- |
| Small  | 14        | 20        | 8           | 32                    |
| Medium | 14        | 20        | 8           | 42                    |
| Large  | 16        | 24        | 8           | 50                    |

## Accessibility

* **Label Association:** Ensure the text field’s label is clearly visible and associated using for screen readers.&#x20;
* **Keyboard Navigation:** Text fields should be focusable and operable with keyboard navigation, with a distinct visual indicator.&#x20;
* **Clear Instructions:** Placeholder text should be descriptive but not used as the main label. Always provide a clear label above the field.&#x20;
* **Color Contrast:** Make sure the text field, icons, and placeholder text meet WCAG standards for color contrast to assist visually impaired users.&#x20;
* **Screen Reader Feedback:** Provide character limits or error messages in a format that can be read by screen readers for real-time user feedback.

## Example

* **Log-in Forms:** Use text fields for capturing user credentials like username and password.&#x20;
* **Search Bars:** Commonly used for entering search queries in search bars across websites or applications.&#x20;
* **Short Input Forms:** Ideal for forms requiring short inputs, such as first name, email, or phone number.&#x20;
* **Filtering:** Great for allowing users to enter filtering criteria, such as in a settings page or search filters.&#x20;
* **One-Line Data Entries:** Suitable for inputs where users need to provide single pieces of data, like postal codes or IDs.
