Compose Svelted ships two text field variants that match the Material 3 specification.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/compose_svelted/llms.txt
Use this file to discover all available pages before exploring further.
TextField uses a filled surface with a bottom indicator line, and OutlinedTextField wraps the same internal BaseTextField with a full border. Both components are fully controlled — you own the value state and receive changes through onValueChange.
TextField
TextField is the filled-style input field. It renders a rounded container with a surfaceVariant background, a floating label that animates upward on focus or when the field has a value, and a bottom indicator line that shifts to the primary color when focused.
Props
The current text value of the field.
TextField is a controlled component — bind this to a reactive variable and update it through onValueChange.Called every time the input value changes. Receives the new string value.
Floating label text. Renders at full size inside the field when empty/unfocused, and animates to a small label above the input when focused or filled.
Placeholder text shown inside the input while the field is focused but empty.
When
false, the field is visually dimmed and non-interactive.Activates the error state: the label, indicator line, and supporting text all switch to the
error color token.Scale factor applied to the label when it floats to the top of the field. Defaults to
0.78 (78% of the original size).When
true renders a single-line <input>; when false renders a multi-line <textarea>.Typographic style applied to the input text. See the Text Style tokens reference.
Layout modifier applied to the outer field wrapper.
Corner radius of the field container. Defaults to
RoundedCornerShape(12) (12 px all corners).Helper or error message rendered below the field. Uses
error color when isError is true.When
true, the field is visible and focusable but its value cannot be changed by the user.Controls the vertical density of the field. Accepts
Density.Default (56 px height) or Density.Compact (44 px height).Color configuration object for every visual element of the field. Defaults to
TextFieldDefaults.filledColors(). See TextFieldDefaults for customisation.Named slots
| Slot | Description |
|---|---|
leadingIcon | Content rendered to the left of the label/input area (e.g., a search icon). |
trailingIcon | Content rendered to the right of the input area (e.g., a clear button). |
Basic example
Multi-line field
Error state example
With leading and trailing icons
OutlinedTextField
OutlinedTextField wraps BaseTextField in a bordered <div> instead of using a filled surface. It uses transparent as the container background and a visible border that transitions between outline (unfocused) and primary (focused) color tokens.
Props
OutlinedTextField accepts the same props as TextField. The only behavioral difference is that it defaults to TextFieldDefaults.outlinedColors() and tracks focus internally to animate the border color.
Current text value (controlled).
Value change callback.
Floating label text.
Placeholder shown while focused and empty.
Interactive state.
Error state — turns label, border, and supporting text to the error color.
Read-only display mode.
Single-line input vs. textarea.
Floating label scale factor.
Input typography style.
Layout modifier applied to the outer bordered wrapper.
Corner radius of the border.
Helper text below the field.
Vertical density of the field.
Color configuration object. Defaults to
TextFieldDefaults.outlinedColors().Named slots
| Slot | Description |
|---|---|
leadingIcon | Leading icon slot. |
trailingIcon | Trailing icon slot. |
Basic example
Error state
TextFieldDefaults
TextFieldDefaults provides the default TextFieldColors objects for each field style. Call the appropriate factory method to get a sensible baseline and override individual color properties as needed.
TextFieldDefaults.filledColors()
Returns a TextFieldColors object configured for TextField:
| Property | Resolved token |
|---|---|
container | surfaceVariant |
label | onSurfaceVariant |
placeholder | onSurfaceVariant |
text | onSurface |
cursor | primary |
indicatorFocused | primary |
indicatorUnfocused | onSurfaceVariant |
error | error |
TextFieldDefaults.outlinedColors()
Returns a TextFieldColors object configured for OutlinedTextField:
| Property | Resolved token |
|---|---|
container | transparent |
label | onSurfaceVariant |
placeholder | onSurfaceVariant |
text | onSurface |
cursor | primary |
indicatorFocused | primary |
indicatorUnfocused | outline |
borderFocused | primary |
borderUnfocused | outline |
error | error |
TextFieldColors interface
Passing custom colors
Override individual properties by spreading the defaults:Density
DensityToken controls the vertical height of the field, which is useful in data-dense UIs such as tables or forms with many fields.
Compact density example
Density.Comfortable is not currently defined in Density.ts. Only Density.Default and Density.Compact are available.