InputText.vue component is a versatile and customizable input field for Vue applications. It supports features like dynamic width, validation errors, read-only and disabled states, and customizable icons via slots.
Features
Customizable Width
Allows flexible adjustment of the input width.
Validation Error Handling
Supports displaying validation errors to guide users.
Disabled and Read-Only States
Manages disabled and read-only states for better control.
Left and Right Icon Slots
Provides slots for custom icons on the left and right of the input field.
Props
The value bound to the date input field.
Sets the width of the input as a percentage.
Displays an error message and applies error styling when provided.
Label for the input field. Supports placeholder-like styling for enhanced accessibility.
Add a datalist for permissible or recommended options available to choose from within the input field.
Events
Triggered when the user presses the Enter key while focused on the input.
Triggered when the input loses focus, passing the input’s value as an argument.
emit(value: string)Slots
Slot for placing an icon to the left of the input.
<template #iconLeft></template>Slot for placing an icon to the right of the input.
<template #iconRight></template>Usage
Basic Input
Input with Error
Disabled Input
Read-Only Input
Datalist Input
Input with Icons
Left Icon
Right Icon
Both Left and Right Icons
Advanced Features
Dynamic Width
Thewidth prop allows you to adjust the input’s width dynamically:
Handling Enter Key
Listen for theenter event to perform actions when the Enter key is pressed:
Handling Blur Event
Use theblur event to capture the input’s value when it loses focus:
Notes
- Error Handling: The
errorprop automatically styles the input and provides visual feedback for validation errors. - Accessibility: Labels are styled with placeholder-like effects but remain fully accessible for screen readers.
- Icon Integration: Icons can be easily integrated on either side of the input field using the
iconLeftandiconRightslots. - Dynamic Styling: The component supports external
classandstyleattributes for additional customization.