Skip to content

Input

Neobrutalist-styled text input with variants, sizes, and v-model two-way binding.

Demo

Preview

变体

尺寸

状态

图标与装饰

https://
.com

辅助能力

0 / 24

v-model 绑定

值:

Installation

pnpm dlx brutx-vue@latest add input

Usage

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const value = ref('')
</script>

<template>
    <Input v-model="value" placeholder="Enter your name..." />
</template>

With Label

vue
<script setup>
import { ref } from 'vue'
import { Input, Label } from 'brutx-ui-vue'

const email = ref('')
</script>

<template>
    <div class="space-y-2">
        <Label for="email">Email</Label>
        <Input id="email" v-model="email" type="email" placeholder="you@example.com" />
    </div>
</template>

Disabled State

vue
<script setup>
import { Input } from 'brutx-ui-vue'
</script>

<template>
    <Input disabled placeholder="Disabled input" />
</template>

Readonly State

Set a readonly input via the readonly prop. In readonly state, the input is not editable but remains focusable for text selection. The cursor style is cursor-default, and opacity is not reduced (unlike disabled).

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const value = ref('Readonly content, selectable and copyable but not editable')
</script>

<template>
    <Input v-model="value" readonly />
</template>

Clearable

Add a clear button that appears on hover when the input has a value.

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const value = ref('Clear me!')
</script>

<template>
    <Input v-model="value" clearable @clear="value = ''" />
</template>

Password Toggle

Show a password visibility toggle button for password inputs.

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const password = ref('')
</script>

<template>
    <Input v-model="password" type="password" show-password placeholder="Enter password" />
</template>

Word Limit

Show character count when show-word-limit and maxlength are both set.

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const value = ref('')
</script>

<template>
    <Input v-model="value" maxlength="100" show-word-limit placeholder="Max 100 characters" />
</template>

Icons And Addons

Prefer the built-in prefixIcon, suffixIcon, prepend, and append APIs on Input for input adornments.

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'
import { Search } from '@lucide/vue'

const url = ref('')
</script>

<template>
    <Input :prefix-icon="Search" placeholder="Search projects" />

    <Input v-model="url" placeholder="Enter URL">
        <template #prepend>https://</template>
        <template #append>.com</template>
    </Input>
</template>

Variants

VariantDescription
defaultStandard border
errorError border with primary shadow on focus
successSuccess border with secondary shadow on focus

Sizes

SizeHeightPaddingFont Size
smh-9px-3 py-1text-sm
defaulth-11px-4 py-2text-base
lgh-14px-5 py-3text-lg

Props

PropTypeDefaultDescription
typeHTMLInputType 1'text'Input type
modelValuestringv-model binding value
variant'default' | 'error' | 'success''default'Input variant
size'sm' | 'default' | 'lg''default'Input size
disabledbooleanfalseWhether disabled
readonlybooleanfalseWhether readonly
placeholderstringPlaceholder text
maxlengthnumberMaximum input length
clearablebooleanfalseShow clear button on hover
showPasswordbooleanfalseShow password toggle button (for type="password")
showWordLimitbooleanfalseShow word count (requires maxlength)
prefixIconComponentPrefix icon
suffixIconComponentSuffix icon
errorMessagestringError message text, only displayed when variant="error", uses role="alert" for screen reader announcement
ariaLabelstringARIA label
ariaLabelledbystringARIA label reference ID
ariaDescribedbystringARIA description reference ID
ariaInvalidbooleanARIA invalid state
ariaRequiredbooleanARIA required state
classstringCustom CSS class

1 HTMLInputType is a union of all standard types supported by HTMLInputElement.type: 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week'

Events

EventPayloadDescription
update:modelValuestringTriggered when value changes
clearTriggered when clear button is clicked

Slots

SlotDescription
prependContent before the input (e.g., URL protocol)
appendContent after the input (e.g., domain)

Exposed Methods (defineExpose)

Access the component instance via ref to call the following methods:

MethodDescription
focus()Focus the input
blur()Remove focus
select()Select all text in the input
vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const inputRef = ref(null)
function handleFocus() {
    inputRef.value?.focus()
}
</script>

<template>
    <Input ref="inputRef" placeholder="Click button to focus" />
    <button @click="handleFocus">Focus Input</button>
</template>

Accessibility

Enhance input accessibility with ARIA attributes for assistive technologies (e.g. screen readers):

vue
<script setup>
import { ref } from 'vue'
import { Input } from 'brutx-ui-vue'

const email = ref('')
</script>

<template>
    <Input
        v-model="email"
        type="email"
        aria-label="Email address"
        aria-required="true"
        aria-invalid="false"
        placeholder="you@example.com"
    />
</template>

Brute force builds.