Use the v-model directive to control the value of the Input.
<script setup lang="ts">
const value = ref('')
</script>
<template>
<PInput v-model="value" />
</template>
Use the type prop to change the input type. Defaults to text.
Some types have been implemented in their own components such as Checkbox, Radio, InputNumber etc. and others have been styled like file for example.
<template>
<PInput type="file" />
</template>
Use the placeholder prop to set a placeholder text.
<template>
<PInput placeholder="Search..." />
</template>
Use the color prop to change the ring color when the Input is focused.
<template>
<PInput color="neutral" highlight placeholder="Search..." />
</template>
highlight prop is used here to show the focus state. It's used internally when a validation error occurs.Use the variant prop to change the variant of the Input.
<template>
<PInput color="neutral" variant="subtle" placeholder="Search..." />
</template>
Use the size prop to change the size of the Input.
<template>
<PInput size="xl" placeholder="Search..." />
</template>
Use the icon prop to show an Icon inside the Input.
<template>
<PInput icon="i-lucide:search" size="md" variant="outline" placeholder="Search..." />
</template>
Use the leading and trailing props to set the icon position or the leading-icon and trailing-icon props to set a different icon for each position.
<template>
<PInput trailing-icon="i-lucide:at-sign" placeholder="Enter your email" size="md" />
</template>
Use the avatar prop to show an Avatar inside the Input.
<template>
<PInput
:avatar="{
src: 'https://github.com/nuxt.png'
}"
size="md"
variant="outline"
placeholder="Search..."
/>
</template>
Use the loading prop to show a loading icon on the Input.
<template>
<PInput loading placeholder="Search..." />
</template>
Use the loading-icon prop to customize the loading icon. Defaults to i-lucide:loader-circle.
<template>
<PInput loading loading-icon="i-lucide:loader" placeholder="Search..." />
</template>
Use the disabled prop to disable the Input.
<template>
<PInput disabled placeholder="Search..." />
</template>
You can put a Button inside the #trailing slot to clear the Input.
<script setup lang="ts">
import { ref } from 'vue';
const value = ref('Click to clear');
</script>
<template>
<PInput
v-model="value"
placeholder="Type something..."
:pohon="{ trailing: 'pe-1' }"
>
<template
v-if="value?.length"
#trailing
>
<PButton
color="neutral"
variant="link"
size="sm"
icon="i-lucide:circle-x"
aria-label="Clear input"
@click="value = ''"
/>
</template>
</PInput>
</template>
You can put a Button inside the #trailing slot to copy the value to the clipboard.
<script setup lang="ts">
import { useClipboard } from '@vueuse/core';
import { ref } from 'vue';
const value = ref('npx nuxt module add pohon-ui');
const { copy, copied } = useClipboard();
</script>
<template>
<PInput
v-model="value"
:pohon="{ trailing: 'pr-0.5' }"
>
<template
v-if="value?.length"
#trailing
>
<PTooltip
text="Copy to clipboard"
:content="{ side: 'right' }"
>
<PButton
:color="copied ? 'success' : 'neutral'"
variant="link"
size="sm"
:icon="copied ? 'i-lucide:copy-check' : 'i-lucide:copy'"
aria-label="Copy to clipboard"
@click="copy(value)"
/>
</PTooltip>
</template>
</PInput>
</template>
You can put a Button inside the #trailing slot to toggle the password visibility.
<script setup lang="ts">
import { ref } from 'vue';
const show = ref(false);
const password = ref('');
</script>
<template>
<PInput
v-model="password"
placeholder="Password"
:type="show ? 'text' : 'password'"
:pohon="{ trailing: 'pe-1' }"
>
<template #trailing>
<PButton
color="neutral"
variant="link"
size="sm"
:icon="show ? 'i-lucide:eye-off' : 'i-lucide:eye'"
:aria-label="show ? 'Hide password' : 'Show password'"
:aria-pressed="show"
aria-controls="password"
@click="show = !show"
/>
</template>
</PInput>
</template>
<style>
/* Hide the password reveal button in Edge */
::-ms-reveal {
display: none;
}
</style>
You can use the Progress component to display the password strength indicator.
Enter a password. Must contain:
<script setup lang="ts">
import { computed, ref } from 'vue';
const show = ref(false);
const password = ref('');
function checkStrength(str: string) {
const requirements = [
{ regex: /.{8,}/, text: 'At least 8 characters' },
{ regex: /\d/, text: 'At least 1 number' },
{ regex: /[a-z]/, text: 'At least 1 lowercase letter' },
{ regex: /[A-Z]/, text: 'At least 1 uppercase letter' },
];
return requirements.map((req) => ({ met: req.regex.test(str), text: req.text }));
}
const strength = computed(() => checkStrength(password.value));
const score = computed(() => strength.value.filter((req) => req.met).length);
const color = computed(() => {
if (score.value === 0) {
return 'neutral';
}
if (score.value <= 1) {
return 'error';
}
if (score.value <= 2) {
return 'warning';
}
if (score.value === 3) {
return 'warning';
}
return 'success';
});
const text = computed(() => {
if (score.value === 0) {
return 'Enter a password';
}
if (score.value <= 2) {
return 'Weak password';
}
if (score.value === 3) {
return 'Medium password';
}
return 'Strong password';
});
</script>
<template>
<div class="space-y-2">
<PFormField label="Password">
<PInput
v-model="password"
placeholder="Password"
:color="color"
:type="show ? 'text' : 'password'"
:aria-invalid="score < 4"
aria-describedby="password-strength"
:pohon="{ trailing: 'pe-1' }"
class="w-full"
>
<template #trailing>
<PButton
color="neutral"
variant="link"
size="sm"
:icon="show ? 'i-lucide:eye-off' : 'i-lucide:eye'"
:aria-label="show ? 'Hide password' : 'Show password'"
:aria-pressed="show"
aria-controls="password"
@click="show = !show"
/>
</template>
</PInput>
</PFormField>
<PProgress
:color="color"
:indicator="text"
:model-value="score"
:max="4"
size="sm"
/>
<p
id="password-strength"
class="text-sm font-medium"
>
{{ text }}. Must contain:
</p>
<ul
class="space-y-1"
aria-label="Password requirements"
>
<li
v-for="(req, index) in strength"
:key="index"
class="flex gap-0.5 items-center"
:class="req.met ? 'text-success' : 'color-text-muted'"
>
<PIcon
:name="req.met ? 'i-lucide:circle-check' : 'i-lucide:circle-x'"
class="shrink-0 size-4"
/>
<span class="text-xs font-light">
{{ req.text }}
<span class="sr-only">
{{ req.met ? ' - Requirement met' : ' - Requirement not met' }}
</span>
</span>
</li>
</ul>
</div>
</template>
You can use the #trailing slot to add a character limit to the Input.
<script setup lang="ts">
import { ref } from 'vue';
const value = ref('');
const maxLength = 15;
</script>
<template>
<PInput
v-model="value"
:maxlength="maxLength"
aria-describedby="character-count"
:pohon="{ trailing: 'pointer-events-none' }"
>
<template #trailing>
<div
id="character-count"
class="text-xs color-text-muted tabular-nums"
aria-live="polite"
role="status"
>
{{ value?.length }}/{{ maxLength }}
</div>
</template>
</PInput>
</template>
You can use the Kbd component inside the #trailing slot to add a keyboard shortcut to the Input.
<script setup lang="ts">
import { defineShortcuts } from '#imports';
import { useTemplateRef } from 'vue';
const input = useTemplateRef('input');
defineShortcuts({
config:
{
'/': () => {
input.value?.inputRef?.focus();
},
},
});
</script>
<template>
<PInput
ref="input"
icon="i-lucide:search"
placeholder="Search..."
>
<template #trailing>
<PKbd value="/" />
</template>
</PInput>
</template>
There's no built-in support for masks, but you can use libraries like maska to mask the Input.
<script setup lang="ts">
import { vMaska } from 'maska/vue';
</script>
<template>
<div class="flex flex-col gap-2">
<PInput
v-maska="'#### #### #### ####'"
placeholder="4242 4242 4242 4242"
icon="i-lucide:credit-card"
/>
<div class="flex gap-2 items-center">
<PInput
v-maska="'##/##'"
placeholder="MM/YY"
icon="i-lucide:calendar"
/>
<PInput
v-maska="'###'"
placeholder="CVC"
/>
</div>
</div>
</template>
You can use the Input within a FormField component to display a label, help text, required indicator, etc.
<script setup lang="ts">
import { ref } from 'vue';
const email = ref('');
</script>
<template>
<PFormField
label="Email"
help="We won't share your email."
required
>
<PInput
v-model="email"
placeholder="Enter your email"
icon="i-lucide:at-sign"
/>
</PFormField>
</template>
You can use the Input within a FieldGroup component to group multiple elements together.
https://
<script setup lang="ts">
import { ref } from 'vue';
const value = ref('');
const domains = ['.com', '.dev', '.org'];
const domain = ref(domains[0]);
</script>
<template>
<PFieldGroup>
<PInput
v-model="value"
placeholder="nuxt"
:pohon="{
base: 'pl-14.5',
leading: 'pointer-events-none',
}"
>
<template #leading>
<p class="text-sm color-text-muted">
https://
</p>
</template>
</PInput>
<PSelectMenu
v-model="domain"
:items="domains"
/>
</PFieldGroup>
</template>
| Prop | Default | Type |
|---|
| Slot | Type |
|---|
| Event | Type |
|---|
When accessing the component via a template ref, you can use the following:
| Name | Type |
|---|---|
inputRef | Ref<HTMLInputElement | null> |
Below is the theme configuration skeleton for the PInput. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.
export default defineAppConfig({
pohon: {
input: {
slots: {
root: '',
base: '',
leading: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
trailing: '',
trailingIcon: ''
},
variants: {
fieldGroup: {
horizontal: {
root: '',
base: ''
},
vertical: {
root: '',
base: ''
}
},
size: {
xs: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
sm: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
md: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
lg: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
xl: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
}
},
variant: {
outline: '',
soft: '',
subtle: '',
ghost: '',
none: ''
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
type: {
file: ''
}
},
compoundVariants: [],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
};
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'
export default defineAppConfig({
pohon: {
input: {
slots: {
root: '',
base: '',
leading: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
trailing: '',
trailingIcon: ''
},
variants: {
fieldGroup: {
horizontal: {
root: '',
base: ''
},
vertical: {
root: '',
base: ''
}
},
size: {
xs: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
sm: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
md: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
lg: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
},
xl: {
base: '',
leading: '',
trailing: '',
leadingIcon: '',
leadingAvatarSize: '',
trailingIcon: ''
}
},
variant: {
outline: '',
soft: '',
subtle: '',
ghost: '',
none: ''
},
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
leading: {
true: ''
},
trailing: {
true: ''
},
loading: {
true: ''
},
highlight: {
true: ''
},
type: {
file: ''
}
},
compoundVariants: [],
defaultVariants: {
size: 'md',
color: 'primary',
variant: 'outline'
}
}
}
};