--- title: "MazInput" description: "MazInput is a standalone component that replaces the standard html input text with a beautiful design system. Many options like colors, sizes, disabled, loading, error, warning, valid states, error messages and icons are included." package: "maz-ui" url: "https://maz-ui.com/components/maz-input" --- # MazInput > MazInput is a standalone component that replaces the standard html input text with a beautiful design system. Many options like colors, sizes, disabled, loading, error, warning, valid states, error messages and icons are included. - Package: `maz-ui` - Import: `import MazInput from 'maz-ui/components/MazInput'` - Nuxt: auto-imported by `@maz-ui/nuxt`, no import needed in a Nuxt app - Web: https://maz-ui.com/components/maz-input > Before use it, you should install the MazUi plugin in your project, follow instructions in [Getting Started](../guide/getting-started.md) ## Basic usage ```vue ``` ## Top label ```html ``` ## Assistive text ```html ``` ## Password ```html ``` ## Placeholder ```html ``` ## Required ```html ``` ## Disabled ```html ``` ## Hint > Will replace the label, useful to display short message ```html ``` ## Icons ### Use icon name **Details: View code** When you use the properties `end-icon`, `start-icon` or `icon` with the icon name (string), the component uses `` component. Check out how [MazIcon](./maz-icon.md) works, see all available icons and download them to put them in your public folder. ```html ``` ### Use your own SVG icons **Details: View code** ```html ``` ### Use [vite-svg-loader](https://github.com/jpkleemans/vite-svg-loader) **Details: View code** ```vue ``` ### Pass a full `MazIconProps` object `startIcon` and `endIcon` also accept a full `MazIconProps` object - pass the same shape `` accepts to override the size, set a `` for screen readers, attach `svgAttributes`, etc. **Details: View code** ```vue <script lang="ts" setup> import MazInput from 'maz-ui/components/MazInput' import { MazBanknotes } from '@maz-ui/icons/raw/MazBanknotes' import { ref } from 'vue' const inputValue = ref('value') </script> <template> <MazInput v-model="inputValue" label="amount" :start-icon="{ icon: MazBanknotes, size: 'lg', title: 'Amount in USD', }" /> </template> ``` ## Auto focus > Will focus automatically the component ```html <MazInput v-model="inputValue" label="label auto-focus" auto-focus /> ``` ## Debounce > The value emit by the input will be delayed, usefull for searching > > The attribute `debounce` is in milliseconds > > If the debounce is true, the default debounce delay is 500ms ```html <MazInput v-model="inputValue" label="label debounce" :debounce="1000" /> ``` ## Sizes > Use the attribute `size` with a value in ```vue <script setup lang="ts"> const sizes = ['mini', 'xs', 'sm', 'md', 'lg', 'xl'] </script> <template> <MazInput v-for="size in sizes" :key="size" v-model="inputValue" :label="size" :size="size" /> </template> ``` **Note: Zoom on iOS** iOS zooms the page when a focused field has a font size below `16px` (most sizes with a `14px` `base-font-size`). This applies to every form field: `MazInput` and the components built on it, `MazTextarea`, `MazInputCode`... To prevent it without changing the design of the fields, enable the `general.preventIosInputZoom` option of [@maz-ui/nuxt](../ecosystem/nuxt.md), or call [preventIosInputZoom](../ecosystem/utils/prevent-ios-input-zoom.md) from `@maz-ui/utils` in a Vue app. ## Colors **Tip:** Click on each input to show colors ```vue <script setup> const colors = ['primary', 'secondary', 'info', 'success', 'warning', 'destructive', 'accent', 'contrast'] </script> <template> <MazInput v-for="name in colors" :key="name" v-model="inputValue" :label="name" :color="name" /> </template> ``` ## Rounded Size Use the attribute `rounded-size` with a value in `'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full'` ```html <MazInput rounded-size="none" placeholder="Rounded input" /> <MazInput rounded-size="sm" placeholder="Rounded input" /> <MazInput rounded-size="md" placeholder="Rounded input" /> <MazInput rounded-size="lg" placeholder="Rounded input" /> <MazInput rounded-size="xl" placeholder="Rounded input" /> <MazInput rounded-size="full" placeholder="Rounded input" /> ``` ## State **destructive** ```html <MazInput v-model="inputValue" label="Label" error /> ``` **Warning** ```html <MazInput v-model="inputValue" label="Label" warning /> ``` **Success** ```html <MazInput v-model="inputValue" label="Label" success /> ``` ## MazInput API `import MazInput from 'maz-ui/components/MazInput'` ### Props - `model-value` (`T`, `v-model`): The current value of the input field. This prop is used for two-way data binding with v-model. - `placeholder` (`string`): Text displayed when the input is empty to guide the user. - `label` (`string`): Floating label that appears inside the input and moves up when focused or filled. Provides better UX than traditional placeholders. - `top-label` (`string`): Static label displayed above the input field. Unlike the floating label, this remains fixed. - `assistive-text` (`string`): Helper text displayed below the input to provide additional context or validation feedback. - `color` (`"primary" | "secondary" | "accent" | "info" | "success" | "warning" | "destructive" | "contrast" | "transparent"`, default: `"primary"`): Theme color that affects the border and focus states of the input. - `type` (`InputTypeHTMLAttribute`, default: `"text"`): HTML input type attribute that determines the input behavior and validation. Values: `'text'`, `'password'`, `'email'`, `'number'`, `'tel'`, `'url'`, `'search'`, `'date'`, `'time'`, `'datetime-local'`, `'month'`, `'week'` (non exhaustive). - `required` (`boolean`, default: `false`): Makes the input field mandatory for form submission. - `disabled` (`boolean`, default: `false`): Disables the input field, preventing user interaction and form submission. - `readonly` (`boolean`): Makes the input field read-only, allowing selection but preventing modification. - `id` (`string`): Unique identifier for the input element, used for form labels and accessibility. - `error` (`boolean`, default: `false`): Applies error styling (red border and text) to indicate validation failure. - `success` (`boolean`, default: `false`): Applies success styling (green border and text) to indicate successful validation. - `warning` (`boolean`, default: `false`): Applies warning styling (orange border and text) to indicate potential issues. - `hint` (`string`): Alternative text that replaces the label when provided. Useful for contextual hints. - `input-classes` (`string`): Additional CSS classes to apply specifically to the input wrapper element. - `border` (`boolean`, default: `true`): Controls whether the input has a visible border. Set to false for borderless inputs. - `inputmode` (`"none" | "text" | "search" | "url" | "email" | "tel" | "numeric" | "decimal"`, default: `"text"`): HTML inputmode attribute that provides hints for virtual keyboards on mobile devices. - `size` (`"xs" | "sm" | "md" | "lg" | "xl" | "mini"`): Controls the height and text size of the input component. - `debounce` (`number | boolean`, default: `false`): Enables input debouncing to limit the frequency of value updates. When true, uses 500ms delay. When a number, uses that value as delay in milliseconds. - `auto-focus` (`boolean`, default: `false`): Automatically focuses the input when the component mounts. - `border-active` (`boolean`, default: `false`): When true, shows the colored border immediately instead of only on focus. - `start-icon` (`MazIconLike`): Icon displayed on the inline-start edge of the input (left in LTR, right in RTL). Accepts a bare value (Vue component, raw SVG string, URL or `data:` URI) or a full `MazIconProps` object for fine-grained control (size, title, svgAttributes, fallback, …). - `end-icon` (`MazIconLike`): Icon displayed on the inline-end edge of the input (right in LTR, left in RTL). Accepts a bare value or a full `MazIconProps` object. - `rounded-size` (`MazRoundedSize`, default: `'md'`): Controls the border radius of the input component. Values: `'none'`, `'sm'`, `'md'`, `'lg'`, `'xl'`, `'full'` (non exhaustive). - `block` (`boolean`): Makes the input expand to the full width of its container. - `name` (`string`): The name of the input field. Used for form submission and validation. - `autocomplete` (`string`): The autocomplete attribute for the input field. Used for form submission and validation. - `loading` (`boolean`, default: `false`): Loading state for the input field. Used to show a loading spinner. ### Events - `@update:model-value` (payload: `value?: T | undefined`): Triggered when the input value changes, used for v-model two-way binding. This event is debounced if the debounce prop is enabled - `@click` (payload: `event: Event`): Triggered when the user clicks on the input field - `@blur` (payload: `event: Event`): Triggered when the input field loses focus (user clicks outside or tabs away) - `@change` (payload: `event: Event`): Triggered when the input value changes and the field loses focus. Different from input event which fires on every keystroke - `@focus` (payload: `event: Event`): Triggered when the input field gains focus (user clicks or tabs into the field) - `@input` (payload: `event: Event`): Triggered on every keystroke or input interaction (real-time input changes). This is the raw input event, not debounced ### Slots - `#start-icon`: Custom content for the inline-start edge of the input field (left in LTR, right in RTL). - `#end-icon`: Custom content for the inline-end edge of the input field (right in LTR, left in RTL). - `#loader`: Loader slot.