PXD
v0.2.1-dev

Input

Retrieve text input from a user.

Default

<template>
  <PInput class="max-w-sm" />
</template>

Sizes

<template>
  <PStack class="max-w-sm" direction="vertical">
    <PInput size="sm" placeholder="sm" />
    <PInput placeholder="md(default)" />
    <PInput size="lg" placeholder="lg" />
  </PStack>
</template>

Password

<script setup>
import { ref } from 'vue'

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

<template>
  <PInput class="max-w-sm" v-model="password" password placeholder="Enter your password" />
</template>

Clearable

<script setup>
import { ref } from 'vue'

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

<template>
  <PInput class="max-w-sm" v-model="password" clearable />
</template>

Min/Max length

<script setup>
import { ref } from 'vue'

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

<template>
  <PInput class="max-w-sm" v-model="value" min-length="2" max-length="10" clearable show-word-limit />
</template>

Prefix and suffix

<template>
  <PStack class="max-w-sm" gap="6" direction="vertical">
    <PInput>
      <template #prefix>
        <IconArrowCircleUp />
      </template>
    </PInput>

    <PInput>
      <template #suffix>
        <IconArrowCircleUp />
      </template>
    </PInput>

    <PInput>
      <template #prefix> https:// </template>

      <template #suffix> .com </template>
    </PInput>

    <PInput :default-prefix-style="false" :default-suffix-style="false">
      <template #prefix>
        <IconArrowCircleUp class="ml-3" />
      </template>

      <template #suffix>
        <IconArrowCircleUp class="mr-3" />
      </template>
    </PInput>
  </PStack>
</template>

Disabled

<template>
  <PStack class="max-w-sm" gap="6" direction="vertical">
    <PInput disabled>
      <template #prefix>
        <IconArrowCircleUp />
      </template>
    </PInput>

    <PInput disabled>
      <template #suffix>
        <IconArrowCircleUp />
      </template>
    </PInput>

    <PInput disabled>
      <template #prefix> https:// </template>

      <template #suffix> .com </template>
    </PInput>

    <PInput disabled :default-prefix-style="false" :default-suffix-style="false">
      <template #prefix>
        <IconArrowCircleUp class="ml-3" />
      </template>

      <template #suffix>
        <IconArrowCircleUp class="mr-3" />
      </template>
    </PInput>
  </PStack>
</template>

Error

<template>
  <PStack class="max-w-sm" gap="8" direction="vertical">
    <PInput error="An error message." size="sm" />
    <PInput error="An error message." />
    <PInput error="An error message." size="lg" />
  </PStack>
</template>

Props

NameTypeDefaultDescription
size'xs' | 'sm' | 'md' | 'lg'-Height, padding and font size, falling back to the config provider size
errorboolean | string-Show the error style, also applied when the word limit is exceeded
minnumber | string-Native min attribute of the underlying input
maxnumber | string-Native max attribute of the underlying input
align'left' | 'center' | 'right'leftHorizontal text alignment inside the field
readonlyboolean-Native readonly attribute, the value stays selectable
disabledboolean-Native disabled attribute, blocks editing and focus
requiredboolean-Native required attribute, the browser asks for a value before the form submits
passwordboolean-Mask the value and add a button to reveal it
autofocusboolean-Focus the input as soon as it is mounted
input-typestring-Native type attribute, when set it wins over password masking
input-mode'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'-Native inputmode attribute, drives the virtual keyboard
input-attrsRecord<string, string | number | boolean | undefined>-Extra attributes applied to the underlying input, such as role and aria-*
min-lengthnumber | string-Native minlength attribute, validated by the browser
max-lengthnumber | string-Native maxlength, lifted while composing and shown by the word limit
trim-overflowbooleanfalseTrim overflow value after composition ends when max-length is set.
clearableboolean-Show a clear button once the field holds a value
clear-valuestring | number | null-Value written back when clearing, an empty string by default
clear-on-press-escapebooleantrueClear the field when the Escape key is pressed
model-valuestring | number | null-Current input value, use v-model for two-way binding
placeholderstring-Placeholder text shown while the value is empty
prefix-classstring | any[] | object-Additional classes merged onto the prefix container
suffix-classstring | any[] | object-Additional classes merged onto the suffix container
select-on-focusboolean-Select the whole value when the field gains focus
default-prefix-stylebooleantrueApply the default padding, background and divider to the prefix container
default-suffix-stylebooleantrueApply the default padding, background and divider to the suffix container
show-word-limitboolean | string-Show the character counter, count / max when max-length is set
word-limit-position'inside' | 'outside'insidePlace the counter inside the field or below it

Events

NameTypeDescription
click(ev: MouseEvent) => voidEmitted when the field is clicked.
change(value: string, details: ChangeDetails) => voidEmitted when the value is committed by pressing Enter, by the native change event, or by clearing the field.
focus(ev: FocusEvent) => voidEmitted when the field gains focus.
blur(ev: FocusEvent) => voidEmitted when the field loses focus.
keydown(ev: KeyboardEvent) => voidEmitted when a key is pressed while the field is neither readonly nor disabled.
update:model-value(value: string) => voidEmitted on every input that is not part of an IME composition, and when a composition ends.
compositionstart(ev: CompositionEvent) => voidEmitted when an IME composition starts.
compositionupdate(ev: CompositionEvent) => voidEmitted while an IME composition is in progress.
compositionend(ev: CompositionEvent) => voidEmitted when an IME composition ends.

Slots

NameDescription
prefixPrefix slot
suffixSuffix slot

Methods

NameTypeDescription
blur() => voidRemove focus from the input element.
clear() => voidReset the value to clear-value and emit change with an empty string.
focus() => voidMove focus to the input element.
inputHTMLInputElement | undefinedThe native input element, for callers that must target it directly.
select() => voidSelect the whole value of the input element.

Source

Source