TextInput
TextInput
lets you create accessible text-based inputs like text
, email
, search
and password
with a simple API.
-->
TextInput
lets you create accessible text-based inputs like text
, email
, search
and password
with a simple API.
TextInput
has possibly the simplest markup you’ll ever for a form input field. The minimum you need is just name
and label
.
Just use the hint
and error
properties to add them.
Both hint texts and error messages are linked to the <input>
with aria-describedby
.
The error message even has a live region attached so screen readers read error messages when they appear.
Just use the before
or after
slots. Easy peasy.
We get all the tiny details right too. Try it out: Focus on the search input, then focus the search button.
You’ll see a nice-looking outline in both cases — and the outline is never includes the divider!
This is easy too. Just add the Stack
attribute and adjust the input
field to create sufficient padding, so the input doesn’t get covered by the overlapping element.
Oh yeah, try focusing on these ones too! The focus details is done right as well.
TextInput
creates an text-based input
element. The required properties are: name
and label
.
TextInput
creates an input with type="text"
by default. You can change the type
by adding a type
property. The following types are supported at this point:
text
email
search
password
url
You can create hint text for each TextInput
by adding a hint
property.
You can create error messages for each TextInput
by adding an error
property.
Use the value
property to set a default value.
Use the placeholder
property to add a placeholder.
Use readonly
and disabled
respectively to create and readonly and disabled states. These two states have a similar style (greyed out) but different behavior:
readonly
will send data to the server when the form is submitteddisabled
will not send data to the server when the form is submitted.All other attributes will be added directly to the input
element.
TextInput
contains two slots: before
and after
.
before
lets you create a prefix for the inputafter
lets you create a suffix for the inputIf you want before
and after
slot items to appear stacked above the input, you can use the Stack
prop.
When you do this:
TextInput
will not create a divider between items.padding
of the input
yourself by styling the input Field
. (See styling
).The contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can bind to the <input>
element with ref
. This is useful if you need the element when handling events.
The following events are supported by TextInput
right now:
input
change
focus
blur
keydown
keyup
keypress
click
You can listen to these the way Svelte handles event listeners.
We forward the above events manually because Svelte 4 doesn’t have automatic event-forwarding capability. All events will be forwarded automatically when we migrate to Svelte 5.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
TextInput
creates an text-based input
element. The required properties are: name
and label
.
TextInput
creates an input with type="text"
by default. You can change the type
by adding a type
property. The following types are supported at this point:
text
email
search
password
url
You can create hint text for each TextInput
by adding a hint
property.
You can create error messages for each TextInput
by adding an error
property.
Use the value
property to set a default value.
Use the placeholder
property to add a placeholder.
Use readonly
and disabled
respectively to create and readonly and disabled states. These two states have a similar style (greyed out) but different behavior:
readonly
will send data to the server when the form is submitteddisabled
will not send data to the server when the form is submitted.All other attributes will be added directly to the input
element.
TextInput
contains two slots: before
and after
.
before
lets you create a prefix for the inputafter
lets you create a suffix for the inputIf you want before
and after
slot items to appear stacked above the input, you can use the Stack
prop.
When you do this:
TextInput
will not create a divider between items.padding
of the input
yourself by styling the input Field
. (See styling
).The contents of this section will only work in a .svelte
file and not inside
an .astro
file.
You can bind to the <input>
element with ref
. This is useful if you need the element when handling events.
The following events are supported by TextInput
right now:
input
change
focus
blur
keydown
keyup
keypress
click
You can listen to these the way Svelte handles event listeners.
We forward the above events manually because Svelte 4 doesn’t have automatic event-forwarding capability. All events will be forwarded automatically when we migrate to Svelte 5.
TextInput
uses several styles from both Splendid Styles and Splendid Layouts. The easiest way to include all basic styles is to import all styles from both libraries:
But if you wish to include only the necessary styles for TextInput
, you can use the following rules:
TextInput
creates the following HTML when label
and name
are used:
If hint
is added, TextInput
creates an additional Hint
element and adds links the Hint
element to the <input>
with aria-describedby
.
If error
is added, TextInput
creates an additional Error
element (using <output>
). It also links the error element to the <input>
with aria-describedby
:
If both hint
and error
are added, TextInput
creates both hint and error elements, and links them both to the <input>
with aria-describedby
:
If you added before
or after
slots, TextInput
will create these elements inside InputGroup
, before or after the <input>
element.
If Stack
is not added, TextInput
will create a Divider
element between the <input>
and the slotted items.
If Stack
is added, TextInput
will not create the divider element.
The following properties can be used to add classes to TextInput
.
Property | Description |
---|---|
class | Class for the TextInput |
styles | Inline styles for the TextInput |
labelClass | Class for the label |
hintClass | Class for the hint element |
errorClass | Class for the error element |
inputGroupclass | Class for the input group |
fieldClass | Class for the <input> field |
All other custom properties will be passed directly into the <input>
element.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
TextInput
uses several styles from both Splendid Styles and Splendid Layouts. The easiest way to include all basic styles is to import all styles from both libraries:
But if you wish to include only the necessary styles for TextInput
, you can use the following rules:
TextInput
creates the following HTML when label
and name
are used:
If hint
is added, TextInput
creates an additional Hint
element and adds links the Hint
element to the <input>
with aria-describedby
.
If error
is added, TextInput
creates an additional Error
element (using <output>
). It also links the error element to the <input>
with aria-describedby
:
If both hint
and error
are added, TextInput
creates both hint and error elements, and links them both to the <input>
with aria-describedby
:
If you added before
or after
slots, TextInput
will create these elements inside InputGroup
, before or after the <input>
element.
If Stack
is not added, TextInput
will create a Divider
element between the <input>
and the slotted items.
If Stack
is added, TextInput
will not create the divider element.
The following properties can be used to add classes to TextInput
.
Property | Description |
---|---|
class | Class for the TextInput |
styles | Inline styles for the TextInput |
labelClass | Class for the label |
hintClass | Class for the hint element |
errorClass | Class for the error element |
inputGroupclass | Class for the input group |
fieldClass | Class for the <input> field |
All other custom properties will be passed directly into the <input>
element.
Name | Description |
---|---|
before | Inserts HTML before <input> |
after | Inserts HTML after <input> |
Use these properties to customize the TextInput
component.
Property | Type | Description |
---|---|---|
name | string | Name of the input field (required) |
label | string | Label for the element |
hint | string | Hint text |
error | string | Error text |
value | string | Input value |
placeholder | string | Placeholder text |
disabled | boolean | Adds the disabled state when present. |
readonly | boolean | Adds the readonly state when present. |
required | boolean | Adds the required state when present. |
ref | object | Reference for the <input> element |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Name | Description |
---|---|
before | Inserts HTML before <input> |
after | Inserts HTML after <input> |
Use these properties to customize the TextInput
component.
Property | Type | Description |
---|---|---|
name | string | Name of the input field (required) |
label | string | Label for the element |
hint | string | Hint text |
error | string | Error text |
value | string | Input value |
placeholder | string | Placeholder text |
disabled | boolean | Adds the disabled state when present. |
readonly | boolean | Adds the readonly state when present. |
required | boolean | Adds the required state when present. |
ref | object | Reference for the <input> element |