Skip to content

Input

WxInput — a single-line text field with v-model, affix slots, a clear button and validation states.

Clearable, with counter
12/60

Value: Landing page

Sizes
Prefix, suffix, validation state
@email
Disabled & readonly

Usage

vue
<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <wx-input v-model="title" placeholder="Title" clearable />
  <wx-input v-model="email" type="email" status="error" />
  <wx-input v-model="slug" show-count :maxlength="60">
    <template #prefix>/</template>
  </wx-input>
</template>

Props

PropTypeDefaultDescription
modelValuestring | number | undefined''v-model value
type'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url''text'Native input type
size'sm' | 'md' | 'lg''md'Control height and font size
status'default' | 'success' | 'warning' | 'error''default'Validation state
placeholderstringPlaceholder text
disabledbooleanfalseDisables the field
readonlybooleanfalseRead-only field
clearablebooleanfalseShows a clear button when filled
maxlengthnumberNative maxlength
showCountbooleanfalseRenders current / max (needs maxlength)
autocompletestringNative autocomplete
idstringgeneratedOverrides the id the label points at; WxFormItem supplies one
ariaLabelstringLabel when there is no visible <label>

Unknown attributes (name, id, required, …) fall through to the inner <input>, not the wrapper — with two exceptions. class and style stay on the wrapper, because that is the thing the caller can see: class="w-60" on a <wx-input> is asking for a narrower input, and a class that landed on the element inside it could not be reached from a parent's scoped CSS anyway.

Events

EventPayloadFires
update:modelValuestringOn every keystroke, and on clear
inputstringOn every keystroke, and on clear
changestringOn the native change event
focusFocusEventOn focus
blurFocusEventOn blur
clearWhen the clear button is pressed

Slots

SlotDescription
prefixContent before the input (icon, @)
suffixContent after the input

Exposed methods

focus(), blur(), select(), and input — a ref to the native element.

vue
<script setup lang="ts">
const field = ref()
onMounted(() => field.value?.focus())
</script>

<template>
  <wx-input ref="field" />
</template>

Accessibility

  • status="error" sets aria-invalid="true" on the input.
  • The clear button is tabindex="-1" with aria-label="Clear", so it never gets in the way of keyboard navigation; focus returns to the input after clearing.
  • Use ariaLabel when the field has no visible label.

Released under the MIT License.