Input
A single-line native input with string/number v-model support. HTML attributes and native listeners fall through to the input. Use specialized controls for files, choices and multiline text. Template-only examples are fragments that assume an Input import in the surrounding component.
Import
import { Input } from '@gxp-dev/app-ui'
Usage
Basic
<script setup lang="ts">
import { ref } from 'vue'
import { Input } from '@gxp-dev/app-ui'
const value = ref('')
</script>
<template>
<Input v-model="value" placeholder="Enter text..." />
</template>
Without v-model
<script setup lang="ts">
import { Input } from '@gxp-dev/app-ui'
const handleInput = (value: string | number) => {
// Update application state here; avoid logging sensitive field values.
void value
}
</script>
<template>
<Input
default-value="Initial value"
@update:model-value="handleInput"
/>
</template>
Input Types
Pass a text-compatible type as a native attribute:
<template>
<div class="space-y-4">
<Input type="text" placeholder="Text input" />
<Input type="email" placeholder="Email address" />
<Input type="password" placeholder="Password" />
<Input type="number" placeholder="Number" />
<Input type="tel" placeholder="Phone number" />
<Input type="url" placeholder="Website URL" />
<Input type="search" placeholder="Search..." />
</div>
</template>
File selection
Use FileUploader for its file/dropzone events, or a native <input type="file" @change="handleFiles"> and read the element's files list. The generic AppUI Input is implemented with a text v-model; its string/number value is not a FileList or an upload. Browsers do not allow assigning a non-empty file input value programmatically. Validate file types and sizes in the backend as well as the UI.
States
Disabled
<template>
<Input disabled placeholder="Disabled input" />
<Input disabled default-value="Disabled with value" />
</template>
Read-only
<template>
<Input readonly default-value="Read-only value" />
</template>
Required
<template>
<form @submit.prevent>
<Input required placeholder="Required field" />
<button type="submit">Submit</button>
</form>
</template>
With Labels
Basic Label
<template>
<div class="space-y-2">
<label for="email" class="text-sm font-medium">
Email Address
</label>
<Input id="email" type="email" placeholder="you@example.com" />
</div>
</template>
With Helper Text
<template>
<div class="space-y-2">
<label for="username" class="text-sm font-medium">
Username
</label>
<Input id="username" placeholder="johndoe" />
<p class="text-sm text-muted-foreground">
This will be your public display name.
</p>
</div>
</template>
With Error Message
<script setup lang="ts">
import { ref, computed } from 'vue'
import { Input } from '@gxp-dev/app-ui'
const email = ref('')
const touched = ref(false)
// Minimal visual demo only; use native constraint validation and backend validation.
const isValid = computed(() => email.value.includes('@'))
</script>
<template>
<div class="space-y-2">
<label for="email" class="text-sm font-medium">
Email
</label>
<Input
id="email"
v-model="email"
type="email"
:aria-invalid="touched && !isValid"
aria-describedby="email-validation-error"
:class="{ 'border-red-500 focus-visible:ring-red-500': touched && !isValid }"
@blur="touched = true"
/>
<p v-if="touched && !isValid" id="email-validation-error" class="text-sm text-red-500">
Please enter a valid email address.
</p>
</div>
</template>
With Icons
Icon on Left
<script setup>
import { Input } from '@gxp-dev/app-ui'
import { Search } from 'lucide-vue-next'
</script>
<template>
<div class="relative">
<Search class="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input class="pl-10" placeholder="Search..." />
</div>
</template>
Icon on Right
<script setup>
import { Input } from '@gxp-dev/app-ui'
import { Mail } from 'lucide-vue-next'
</script>
<template>
<div class="relative">
<Input type="email" placeholder="Email" class="pr-10" />
<Mail class="absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
</div>
</template>
Password with Toggle
<script setup lang="ts">
import { ref } from 'vue'
import { Input, Button } from '@gxp-dev/app-ui'
import { Eye, EyeOff } from 'lucide-vue-next'
const password = ref('')
const showPassword = ref(false)
</script>
<template>
<div class="relative">
<Input
v-model="password"
aria-label="Password"
:type="showPassword ? 'text' : 'password'"
placeholder="Enter password"
class="pr-10"
/>
<Button
type="button"
variant="ghost"
size="icon"
class="absolute right-0 top-0 h-full px-3 hover:bg-transparent"
:aria-label="showPassword ? 'Hide password' : 'Show password'"
:aria-pressed="showPassword"
@click="showPassword = !showPassword"
>
<Eye v-if="!showPassword" class="h-4 w-4" />
<EyeOff v-else class="h-4 w-4" />
</Button>
</div>
</template>
Validation Attributes
Character Limits
<script setup lang="ts">
import { ref, computed } from 'vue'
import { Input } from '@gxp-dev/app-ui'
const bio = ref('')
const maxLength = 100
const remaining = computed(() => maxLength - bio.value.length)
</script>
<template>
<div class="space-y-2">
<Input
v-model="bio"
:maxlength="maxLength"
placeholder="Short bio"
/>
<p class="text-sm text-muted-foreground text-right">
{{ remaining }} characters remaining
</p>
</div>
</template>
Pattern Validation
<template>
<!-- US Phone number -->
<Input
type="tel"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
placeholder="123-456-7890"
/>
<!-- Zip code -->
<Input
pattern="[0-9]{5}"
placeholder="12345"
/>
</template>
Number Constraints
<template>
<Input
type="number"
min="0"
max="100"
step="5"
placeholder="0-100, step 5"
/>
</template>
Custom Styling
Via Class Prop
<template>
<Input class="rounded-full" placeholder="Rounded input" />
<Input class="border-2 border-primary" placeholder="Thick border" />
<Input class="bg-muted" placeholder="Muted background" />
</template>
Full Width
<template>
<Input class="w-full" placeholder="Full width input" />
</template>
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | string | number | - | Bound value (v-model) |
defaultValue | string | number | - | Initial value when uncontrolled |
class | HTMLAttributes['class'] | - | Vue string, array or object class binding |
The component declares these three props. Native attributes such as type (browser default: text), placeholder, disabled, readonly, required, id, name, maxlength, min, max, pattern and autocomplete pass through to the input. Use default-value or v-model for its value instead of mixing a separate value attribute with the component's internal model.
Events
update:modelValue is the declared component event, with a string | number payload. Native @input, @change, @focus and @blur listeners receive DOM events from the input. See the generated contract for the current declared API.
Slots
None - Input is a self-closing element.
Exports
export { Input } from '@gxp-dev/app-ui'
Accessibility
- Uses a native
<input>; the host supplies an accessible label and error/help associations - Associates with
<label>viaidattribute - Supports all ARIA attributes (
aria-label,aria-describedby, etc.) - Focus ring visible for keyboard navigation
ARIA Example
<template>
<div>
<label id="email-label">Email Address</label>
<Input
aria-labelledby="email-label"
aria-describedby="email-hint email-error"
/>
<p id="email-hint">Use the address associated with your account.</p>
<p id="email-error" role="alert">Invalid email format.</p>
</div>
</template>
Examples
Login form preview
This example only previews a loading state. It sends no credentials, creates no account/session, and does not authenticate with GxP. Implement the intended authentication flow separately.
<script setup lang="ts">
import { ref } from 'vue'
import { Input, Button } from '@gxp-dev/app-ui'
const email = ref('')
const password = ref('')
const isLoading = ref(false)
const handleSubmit = async () => {
isLoading.value = true
// Local timing demo only; replace with the intended authentication integration.
await new Promise(r => setTimeout(r, 1000))
isLoading.value = false
}
</script>
<template>
<form @submit.prevent="handleSubmit" class="space-y-4 max-w-sm">
<div class="space-y-2">
<label for="email" class="text-sm font-medium">Email</label>
<Input
id="email"
v-model="email"
type="email"
placeholder="you@example.com"
required
:disabled="isLoading"
/>
</div>
<div class="space-y-2">
<label for="password" class="text-sm font-medium">Password</label>
<Input
id="password"
v-model="password"
type="password"
required
:disabled="isLoading"
/>
</div>
<Button type="submit" class="w-full" :disabled="isLoading">
{{ isLoading ? 'Previewing...' : 'Preview sign-in UI' }}
</Button>
</form>
</template>
Search Input
<script setup lang="ts">
import { onUnmounted, ref, watch } from 'vue'
import { Input, Button } from '@gxp-dev/app-ui'
import { Search, X } from 'lucide-vue-next'
const query = ref('')
// Debounced local preview; replace the assignment with your search integration.
const previewQuery = ref('')
let timer: ReturnType<typeof setTimeout> | undefined
watch(query, (value) => {
clearTimeout(timer)
timer = setTimeout(() => { previewQuery.value = value }, 300)
})
onUnmounted(() => clearTimeout(timer))
</script>
<template>
<div class="relative max-w-md">
<Search class="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
v-model="query"
type="search"
placeholder="Search..."
aria-label="Search"
class="pl-10 pr-10"
/>
<Button
v-if="query"
type="button"
variant="ghost"
size="icon"
class="absolute right-0 top-0 h-full px-3 hover:bg-transparent"
aria-label="Clear search"
@click="query = ''"
>
<X class="h-4 w-4" />
</Button>
<p role="status">Local search preview: {{ previewQuery }}</p>
</div>
</template>