Skip to content

Search documentation

Search guides, examples, and component APIs.

Quick links
↑↓ NavigateEnter OpenEsc Close
Get started

Documentation navigation

Components / Forms

PasswordInput

A native password field with a localized visibility toggle.

Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.

Interactive showcase

Install

Run in your project
bunx --bun @getweini/cli@latest add password-input

Start with this example

Import the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.

Vue
<script setup lang="ts">
import { ref } from 'vue'
import PasswordInput from './components/ui/password-input/PasswordInput.vue'

const password = ref('')
const messages = { showPassword: 'Show password', hidePassword: 'Hide password' }
</script>

<template>
  <label for="account-password">Password</label>
  <PasswordInput
    id="account-password"
    v-model="password"
    name="password"
    autocomplete="current-password"
    :messages="messages"
  />
</template>

The native input handles validation, autocomplete, focus, and form submission. The trailing button changes visibility without moving focus. Connect your help and error text with aria-describedby.

When to use it

Sign in

Use password manager autocomplete while allowing temporary visibility.

Create credentials

Show application-owned password guidance beside a new-password field.

More examples

Current password

The visibility button keeps focus in the field.

Current password
<script setup lang="ts">
import { ref } from 'vue'
import PasswordInput from './components/ui/password-input/PasswordInput.vue'

const password = ref('')
const messages = { showPassword: 'Show password', hidePassword: 'Hide password' }
</script>
<template>
  <label for="password">Password</label>
  <PasswordInput
    id="password"
    v-model="password"
    name="password"
    autocomplete="current-password"
    :messages="messages"
    required
  />
</template>

New password with help

The application supplies its own password rules.

New password with help
<script setup lang="ts">
import { ref } from 'vue'
import PasswordInput from './components/ui/password-input/PasswordInput.vue'

const password = ref('')
const messages = { showPassword: 'Show password', hidePassword: 'Hide password' }
</script>
<template>
  <label for="new-password">New password</label>
  <PasswordInput
    id="new-password"
    v-model="password"
    autocomplete="new-password"
    :messages="messages"
    aria-describedby="password-help"
    required
  />
  <p id="password-help">Use at least 12 characters.</p>
</template>

Complete API

Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.

PasswordInput

Complete API for PasswordInput
NameType or signatureDefaultWhat it does
rootClasspropClassValueNot setClasses applied to the outer component wrapper.
rootStylepropStyleValueNot setStyles applied to the outer component wrapper.
idpropstring | undefinedNot setGive the control an ID so a label or description can refer to it.
sizepropControlSize | undefined"md"Choose the visual size. Medium is the usual default where available.
invalidpropboolean | undefinedNot setShow the invalid state; also provide a visible error message.
disabledpropboolean | undefinedNot setPrevent interaction and show the disabled state.
readonlypropboolean | undefinedNot setShow the value while preventing edits.
defaultVisiblepropboolean | undefinedfalseStarting visibility when the parent does not control it.
messagespropPasswordInputMessagesRequiredSupply the text this component displays for its built-in actions and states.
modelValuemodelstring | undefinedNot setCurrent value. Use v-model to keep it in sync with your page.
modelModifierspropPartial<Record<"trim" | "lazy", true>> | undefinedNot setControls the model modifiers behavior of PasswordInput.
update:modelValueevent[value: string | undefined]—Requests a new model value from the parent.
errorslot{ message: string; messages: string[]; }OptionalContent for the error area of PasswordInput.
elementexposedHTMLInputElement | null—Reference to the underlying HTML element.
focusexposed() => void | undefined—Move keyboard focus to this control.
hideexposed() => void—Access hide from a component template ref.
showexposed() => void—Access show from a component template ref.
Public type definitions
Public types
// packages/frameworks/vue/components/password-input/types.ts
// ------- IMPORTS -------

import type { ControlSize } from '@getweini/vue/types'
import type { HTMLAttributes } from 'vue'

// ------- TYPES -------

export interface PasswordInputMessages {
  showPassword: string
  hidePassword: string
}

export interface PasswordInputProps {
  rootClass?: HTMLAttributes['class']
  rootStyle?: HTMLAttributes['style']
  id?: string
  size?: ControlSize
  invalid?: boolean
  disabled?: boolean
  readonly?: boolean
  defaultVisible?: boolean
  messages: PasswordInputMessages
}


// packages/frameworks/vue/dist/types/index.d.ts
export type { ButtonOptions, ButtonProps } from './button';
export type ControlSize = 'sm' | 'md' | 'lg';
export interface SelectOption<T = unknown> {
    label: string;
    value: T;
    disabled?: boolean;
}
/** Application-owned copy. Bind translated strings reactively when the locale changes. */
export interface ListboxMessages {
    /** Popup name when no aria-label or aria-labelledby is supplied. */
    listboxLabel: string;
    empty: string;
    clearSelection: string;
}
export interface ListboxProps<T> {
    options: readonly SelectOption<T>[];
    messages: ListboxMessages;
    id?: string;
    disabled?: boolean;
    required?: boolean;
    invalid?: boolean;
    name?: string;
    form?: string;
    placeholder?: string;
    size?: ControlSize;
    clearable?: boolean;
    gap?: number;
    /** Supply stable equality for object values. Values must be unique. */
    by?: (a: T, b: T) => boolean;
    /** Required for meaningful form submission of object values. */
    serialize?: (value: T) => string;
}


// packages/frameworks/vue/dist/types/button.d.ts
import type { Component } from 'vue';
/** Options shared by button implementations across frameworks. */
export interface ButtonOptions<Variant extends string = string, Size extends string = string> {
    variant?: Variant;
    size?: Size;
    disabled?: boolean;
    loading?: boolean;
    type?: 'button' | 'submit' | 'reset';
}
/** Vue-specific target options extend the reusable button contract. */
export interface ButtonProps<Variant extends string = 'default' | 'secondary' | 'outline' | 'ghost' | 'destructive', Size extends string = 'sm' | 'md' | 'lg'> extends ButtonOptions<Variant, Size> {
    as?: 'button' | 'a' | Component;
    asChild?: boolean;
}

Implementation notes

  • rootClass and rootStyle style the visible wrapper; native attributes belong to the input.
  • The model supports .trim and .lazy modifiers.
  • Visibility changes the input type; it does not validate password strength.
  • Use current-password or new-password autocomplete to help password managers.

Accessibility and localization

  • Translate both visibility action labels and associate any rules or errors with aria-describedby.

Source contract and editing guidance