WlInput

Text field with prefix/suffix slots.
Components / Inputs v0.1.0

Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.

Settings

size

Field size.

density

Compact mode reduces field height.

type

Input element type attribute.

placeholder

Placeholder.

Error state.

Disables the field.

Show a clear action for the current value.

Indicate pending work supplied by the application.

Display the text length counter and connect it to the control description.

Props pt, models, handlers and slots can be edited in the SFC. See their descriptions in API.

Example

Focus: outside the example · pointer: outside the example

Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.

Code for your application

Vue SFC · current settings
<script setup lang="ts">
import { WlIcon, WlInput } from "legato-ui";
import { ref } from "vue";
const value = ref("Team material");
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlInput
      v-model="value"
      aria-label="Material title"
      placeholder="Title"
      :pt="{ input: { 'data-example': 'material-title' } }"
      
    ><template #prefix><WlIcon name="file" /></template></WlInput>
  </div>
</template>

Sizes, slots and validation

Compare sizes and density, prefix/suffix, an associated error, disabled and clearing text.

Sizes and density

Slots and states

₽
The icon and unit of measurement supplement the label.
Enter a username.

Title: Team plan. Cost: 1200.

Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlField, WlIcon, WlInput } from "legato-ui";
import { ref } from "vue";
const title = ref("Team plan");
const amount = ref("1200");
const login = ref("");
</script>

<template>
  <div class="wl-stack" data-space="xl" data-input-example="WlInput">
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-title">{{ "Sizes and density" }}</h3>
      <div class="wl-grid" data-space="lg">
        <WlField
          v-for="size in ['sm', 'md', 'lg'] as const"
          :id="`docs-input-${size}`"
          :key="size"
          v-slot="{ id }"
          :label="`${'Title, '}${size}`"
        >
          <WlInput :id="id" v-model="title" :size="size" />
        </WlField>
        <WlField id="docs-input-compact" v-slot="{ id }" label="Compact field">
          <WlInput :id="id" v-model="title" density="compact" />
        </WlField>
      </div>
    </section>
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-title">{{ "Slots and states" }}</h3>
      <div class="wl-grid" data-space="lg">
        <WlField
          id="docs-input-cost"
          v-slot="{ id, ariaDescribedby }"
          label="Cost"
          hint="The icon and unit of measurement supplement the label."
        >
          <WlInput
            :id="id"
            v-model="amount"
            inputmode="decimal"
            :aria-describedby="ariaDescribedby"
          >
            <template #prefix><WlIcon name="file" :size="16" /></template>
            <template #suffix><span class="wl-text-small">₽</span></template>
          </WlInput>
        </WlField>
        <WlField
          id="docs-input-login"
          v-slot="{ id, ariaDescribedby, invalid, required }"
          label="Username"
          :error="login.trim() ? undefined : 'Enter a username.'"
          required
        >
          <WlInput
            :id="id"
            v-model="login"
            :invalid="invalid"
            :required="required"
            :aria-describedby="ariaDescribedby"
            placeholder="For example, dmitry"
          />
        </WlField>
        <WlField id="docs-input-disabled" v-slot="{ id }" label="Unavailable field">
          <WlInput :id="id" model-value="The title is set by an administrator" disabled />
        </WlField>
      </div>
      <WlButton size="sm" @click="title = ''; amount = ''; login = ''">{{ "Clear fields" }}</WlButton>
      <p class="wl-text-small" role="status">{{ "Title:" }} {{
        title || "not set"
      }}{{ ". Cost:" }} {{ amount || "not set" }}.</p>
    </section>
  </div>
</template>