Input
An input component that allows users to enter and edit text.
Showcase
<LnxInput v-model="..." <-- Pass a reactive variable here to bind its value @update:modelValue="..." <-- Two way binding of the component @input="..." <-- Emitted on every keystroke on the input @change="..." <-- Emitted when the value of the input changes (on blur, for example) > Enter something <template #error> This is an error message </template> <template #helper> This is a helper message </template> </LnxInput>
v-model
string | numberBinds the value of the input to the reactive variable used as prop Default value: undefinedisClearable
booleanIndicates if a button should render to quickly clear the input Default value: falsecustomValidity
stringThe error message of the input. It is the default value for the `error` slot Default value: undefinedWhen to use
- For short, free text: names, emails, numbers or passwords.
- When there is a fixed list of answers, use a Select.
- For dates, use a DatePicker, and for verification codes an InputOTP.
Examples
Label and helper
The default slot is the label. Use the helper slot for a hint below the field.
We only use it to send you the receipt
vue
<LnxInput v-model="email" type="email" placeholder="ada@example.com">
Email
<template #helper>We only use it to send you the receipt</template>
</LnxInput>1
2
3
4
2
3
4
Size
lnx-size-small and lnx-size-large resize a field, or every field and button inside a container, so they keep lining up. See Sizing for other sizes.
vue
<div class="lnx-size-small" style="display: flex; gap: 8px; align-items: end">
<LnxInput placeholder="Search" />
<LnxButton>Filter</LnxButton>
</div>1
2
3
4
2
3
4
Search
is-clearable adds a button that empties the field.
vue
<LnxInput v-model="search" type="search" placeholder="Search projects" is-clearable>
Search
</LnxInput>1
2
3
2
3
Password
With type="password", a button lets the user show what they typed.
vue
<LnxInput v-model="password" type="password">
Password
</LnxInput>1
2
3
2
3
Error
Set has-error and the message in custom-validity, or in the error slot for richer content. The message is also set as the native validity of the input, so forms won't submit while it is shown.
This username is already taken
vue
<LnxInput v-model="username" has-error custom-validity="This username is already taken">
Username
</LnxInput>1
2
3
2
3
API
Props
| Prop | Type | Description |
|---|---|---|
v-model | string | number | Binds the value of the input to the reactive variable used as prop |
is-clearable | boolean | Indicates if a button should render to quickly clear the input Default: false |
is-loading | boolean | When loading, it is disabled and shows a different content Default: false |
has-error | boolean | Indicates if it should show the error slot Default: false |
custom-validity | string | The error message of the input. It is the default value for the error slot |
Native attributes
| Attribute | Type | Description |
|---|---|---|
type | Input type | Changes the input type Default: "text" |
placeholder | string | Changes the placeholder of the input |
readonly | boolean | Prevents the input to be edited Default: false |
disabled | boolean | Disables all actions on the input Default: false |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | string | number | Two way binding of the component |
input | InputEvent | Emitted on every keystroke on the input |
change | Event | Emitted when the value of the input changes (on blur, for example) |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | Label content of the input |
icon | — | Content to be displayed at the right of the input value |
error | — | Message to be shown when the input has an error |
helper | — | Message to be shown below the input to add extra context |
overlay | — | Content laid over the input box, whatever the label and messages around it. The select shows its selected option here |