Input
View as MarkdownA text input component that works with Field, with optional word count and screen reader announcements.
Features
Permalink to heading "Features"- Works standalone or nested directly inside
ui:field.root- nofield.controlwrapper needed - Optional
transformcallback to sanitize/reformat the value as the user types, with cursor position preserved - Optional
wordCountpart rendering a translatable "42 / 250 characters" style counter, driven bymaxLength - Word count updates are announced to screen readers by default through the page's shared live region, debounced so it doesn't spam assistive tech on every keystroke - pass
announce="{false}"to turn it off
<primitives:input.root>
<primitives:input.label />
<primitives:input.input />
<primitives:input.wordCount />
</primitives:input.root>
Installation
Permalink to heading "Installation"typo3 ui:add input
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"With Field
Permalink to heading "With Field"Nest ui:input.root directly inside ui:field.root - it inherits name, disabled, required, invalid and aria-describedby automatically, the same way ui:select/ui:numberInput do. Use the primitive's own label part (nested inside root) rather than field.label - it targets the right control automatically.
With Word Count
Permalink to heading "With Word Count"Pass maxLength and add the wordCount part wherever you want it - it doesn't need to be a direct sibling of input.
With a Transform Callback
Permalink to heading "With a Transform Callback"transform runs on every native input event, before the value is committed - return the value that should actually be written back to the input, with cursor position preserved across the rewrite. Because a real function can't cross the PHP → client JSON boundary, this can only be set by constructing Input yourself in a custom entry file, rather than as a Fluid prop. Type lowercase below - it's uppercased as you type:
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives.
input.root
Permalink to heading "input.root"Provides shared input state and wraps all related parts. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
type | stringThe HTML input type attribute, e.g. text, email, password, search, tel, url. | No | 'text' |
placeholder | stringPlaceholder text shown when the input is empty. | No | - |
autocomplete | stringHints for browser autofill, e.g. email, tel, given-name, street-address. See the [HTML spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill) for the full list of tokens. | No | - |
name | stringThe name attribute of the input. Useful for form submission. Inherited from a surrounding field when available. | No | - |
disabled | booleanWhether the input is disabled. Inherited from a surrounding field when available. | No | - |
invalid | booleanWhether the input value is invalid. Inherited from a surrounding field when available. | No | - |
required | booleanWhether the input is required. Inherited from a surrounding field when available. | No | - |
readOnly | booleanWhether the input is readonly. Inherited from a surrounding field when available. | No | - |
defaultValue | stringThe initial value of the input when rendered. Use when you don't need to control the value of the input. Inherited from a surrounding field when available. | No | '' |
maxLength | integerThe maximum number of characters allowed. Also drives the wordCount part, e.g. '42 / 250 characters'. | No | - |
pattern | stringA regular expression the input's value is checked against on form submission. | No | - |
inputMode | Enum\InputModeHints at the type of data that might be entered by the user and the keyboard shown on mobile devices, e.g. numeric, email, tel. | No | - |
translations | arraySpecifies the localized word count string. Use `f:translate` for per-template localization overrides when needed. | No | - |
announce | booleanWhether the word count is announced to assistive tech as the user types. Set to false to stay silent. | No | true |
announceDebounce | integerMilliseconds to debounce word count announcements by, so rapid typing doesn't spam assistive tech. Set to 0 to announce every change immediately. | No | 600 |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-invalid | Present when invalid |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
input.label
Permalink to heading "input.label"Labels the input. Renders a <label> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-invalid | Present when invalid |
data-disabled | Present when disabled |
data-required | Present when required |
input.input
Permalink to heading "input.input"The editable input. Renders an <input> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-invalid | Present when invalid |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
input.wordCount
Permalink to heading "input.wordCount"Displays the character count, e.g. '42 / 250 characters'. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Machine options
Permalink to heading "Machine options"| Name | Description | Default |
|---|---|---|
id | stringThe unique identifier of the input. | - |
ids | Record<string, string> | undefinedThe ids of the parts other elements reference: input (the for of its label) and wordCount. | - |
name | string | undefinedThe name of the input, as it is submitted with the form. Taken from the closest field. | - |
disabled | boolean | undefinedWhether the input is disabled. Taken from the closest field. | - |
readOnly | boolean | undefinedWhether the input is read-only. Taken from the closest field. | - |
required | boolean | undefinedWhether the input is required. Taken from the closest field. | - |
invalid | boolean | undefinedWhether the input is invalid. Taken from the closest field. | - |
defaultValue | string | undefinedThe initial value of the input. | - |
maxLength | number | undefinedThe most characters allowed. It also drives the word count, e.g. 42 / 250 characters. | - |
pattern | string | undefinedA regular expression the value has to match. | - |
inputMode | JSX.HTMLAttributes<HTMLInputElement>['inputMode'] | undefinedThe kind of virtual keyboard to show on devices that have one. | - |
translations | InputTranslations | undefinedThe localized texts of the input. | - |
announce | boolean | undefinedWhether the word count is announced to assistive tech. Set to false to stay silent. | true |
announceDebounce | number | undefinedMilliseconds to debounce word count announcements by, so rapid typing doesn't spam assistive tech on every keystroke. Set to 0 to announce every change immediately. | 600 |
transform | ((value: string, event: Event) => string) | undefinedRuns on every native input event, before the value is committed. Return the value to write back to the input, e.g. uppercased or digits only. The cursor position is kept. It cannot be set from a Fluid template, only by constructing Input in your own entry file. | - |
onValueChange | ((details: { value: string }) => void) | undefinedCalled when the value changes. | - |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
value | string | The current value of the input. |
count | number | The number of characters in the value. |
countText | string | null | The word count text, e.g. 42 / 250 characters. null without maxLength or when the text is turned off. |
disabled | boolean | Whether the input is disabled. |
readOnly | boolean | Whether the input is read-only. |
required | boolean | Whether the input is required. |
invalid | boolean | Whether the input is invalid. |
name | string | undefined | The name of the input. |
maxLength | number | undefined | The most characters allowed. |