--- title: TextField description: >- The `TextField` component captures single-line text input. Use it to collect short, free-form information like names, titles, or identifiers. The component supports various input configurations including placeholders, character limits, and validation. For multi-line text entry, use the [`TextArea`](/docs/api/pos-ui-extensions/2025-10/polaris-web-components/forms/textarea) component. api_version: 2025-10 api_name: pos-ui-extensions source_url: html: >- https://shopify.dev/docs/api/pos-ui-extensions/latest/polaris-web-components/forms/textfield md: >- https://shopify.dev/docs/api/pos-ui-extensions/latest/polaris-web-components/forms/textfield.md --- # Text​Field The `TextField` component captures single-line text input. Use it to collect short, free-form information like names, titles, or identifiers. The component supports various input configurations including placeholders, character limits, and validation. For multi-line text entry, use the [`TextArea`](https://shopify.dev/docs/api/pos-ui-extensions/2025-10/polaris-web-components/forms/textarea) component. ## Properties Configure the following properties on the `TextField` component. * details string The additional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user. This will also be exposed to screen reader users. * disabled boolean Default: false Whether the field is disabled, preventing user interaction. Use when the field is temporarily unavailable due to application state, permissions, or dependencies. * error string An error message to indicate a problem to the user. The field will be given specific stylistic treatment to communicate issues that must be resolved immediately. * id string A unique identifier for the element used for targeting with CSS, JavaScript, or accessibility features. * label string The content to use as the field label that describes the text information being requested. * maxLength number Default: Infinity The maximum number of characters allowed in the text field. * placeholder string A short hint that provides guidance about the expected value of the field. * required boolean Default: false Whether the field needs a value. This requirement adds semantic value to the field but doesn't cause an error to appear automatically. Use the `error` property to present validation errors. * value string The current text content entered in the field. An empty string means no text is entered. ## Slots The `TextField` component supports slots for additional content placement within the field. Learn more about [using slots](https://shopify.dev/docs/api/polaris/using-polaris-web-components#slots). * accessory HTMLElement The additional content to be displayed in the field. Commonly used to display clickable text or action elements. Only `Button` and `Clickable` components with text content only are supported in this slot. Use the `slot="accessory"` attribute to place elements in this area. ## Events The `TextField` component provides event callbacks for handling user interactions. Learn more about [handling events](https://shopify.dev/docs/api/polaris/using-polaris-web-components#handling-events). * blur (event: CallbackEvent<"s-text-field">) => void Called when the element loses focus. * change (event: CallbackEvent<"s-text-field">) => void Called after editing completes, typically on blur. * focus (event: CallbackEvent<"s-text-field">) => void Called when the element receives focus. * input (event: CallbackEvent<"s-text-field">) => void Called when the user makes any changes in the field. ### CallbackEvent Represents the event object passed to callback functions when interactive events occur. Contains metadata about the event, including the target element, event phase, and propagation behavior. * bubbles Whether the event bubbles up through the DOM tree. ```ts boolean ``` * cancelable Whether the event can be canceled. ```ts boolean ``` * composed Whether the event will trigger listeners outside of a shadow root. ```ts boolean ``` * currentTarget The element that the event listener is attached to. ```ts HTMLElementTagNameMap[T] ``` * detail Additional data associated with the event. ```ts any ``` * eventPhase The current phase of the event flow. ```ts number ``` * target The element that triggered the event. ```ts HTMLElementTagNameMap[T] | null ``` ```ts interface CallbackEvent { /** * The element that the event listener is attached to. */ currentTarget: HTMLElementTagNameMap[T]; /** * Whether the event bubbles up through the DOM tree. */ bubbles?: boolean; /** * Whether the event can be canceled. */ cancelable?: boolean; /** * Whether the event will trigger listeners outside of a shadow root. */ composed?: boolean; /** * Additional data associated with the event. */ detail?: any; /** * The current phase of the event flow. */ eventPhase: number; /** * The element that triggered the event. */ target: HTMLElementTagNameMap[T] | null; } ``` ### Examples * #### Capture text input with a text field ##### Description Capture single-line text input using a \`TextField\` component with validation support. This example shows a basic text field with label and placeholder text. ##### Default ```html ``` ## Preview ![](https://shopify.dev/images/templated-apis-screenshots/pos-ui-extensions/2025-10/text-field-default.png) ## Best practices * **Use for single-line text input:** Choose `TextField` for short values like names, titles, or identifiers. For multi-line content, use [`TextArea`](https://shopify.dev/docs/api/pos-ui-extensions/2025-10/polaris-web-components/forms/textarea). * **Show character limit feedback:** When approaching `maxLength`, display remaining characters in the `details` text. * **Write descriptive labels:** Use specific labels like "Product Name" or "Reference Code" rather than generic terms. ## Limitations The `accessory` slot supports only [`Button`](https://shopify.dev/docs/api/pos-ui-extensions/2025-10/polaris-web-components/actions/button) and [`Clickable`](https://shopify.dev/docs/api/pos-ui-extensions/2025-10/polaris-web-components/actions/clickable) components with text content only—other component types or complex layouts can't be used for field accessories. ## Examples Learn how to add accessory buttons, configure validation properties, and handle events. ### Examples * #### Add accessory buttons ##### Description Add action buttons to the text field using the accessory slot for quick actions like clearing text or submitting input. This example shows how to use \[\`s-button\`]\(/docs/api/pos-ui-extensions/2025-10/polaris-web-components/actions/button) and \[\`s-clickable\`]\(/docs/api/pos-ui-extensions/2025-10/polaris-web-components/actions/clickable) components with text content in the accessory slot, enabling inline actions without leaving the input context. ##### Default ```jsx console.log('Apply discount')}> Apply ; ``` * #### Configure validation and guidance ##### Description Configure common \`TextField\` properties for validation, character limits, and user guidance. This example demonstrates using props like \`maxlength\`, \`required\`, \`helperText\`, and \`error\` to create a well-guided input experience with proper validation feedback. ##### Default ```jsx setSku(event.currentTarget.value)} /> ``` * #### Handle input events ##### Description Subscribe to \`TextField\` events including \`onInput\`, \`onFocus\`, \`onBlur\`, and \`onChange\` to respond to user interactions. This example shows how to handle different input events for real-time validation, autosave functionality, or dynamic form behavior. ##### Default ```jsx { console.log('Input:', event.currentTarget.value); console.log('Current error:', event.currentTarget.error); }} onFocus={(event) => { console.log('Focused with value:', event.currentTarget.value); }} onBlur={(event) => { console.log('Blurred with value:', event.currentTarget.value); }} onChange={(event) => { console.log('Changed to:', event.currentTarget.value); }} /> ```