Skip to content

Input

Basic form input component, supports both input and textarea.

Basic Usage

Input content:
<template>
  <div>
    <div style="margin-bottom: 10px">Input content:{{ value }}</div>
    <b-input v-model="value" placeholder="Please enter some text..." class="input-item"></b-input>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref('')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Icon and Clearable

Set clearable to show a clear button. Use icon to set an icon.

<template>
  <b-space>
    <b-input v-model="value" icon="eye-fill" class="input-item"></b-input>
    <b-input v-model="value1" clearable class="input-item"></b-input>
  </b-space>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref('')
const value1 = ref('')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Disabled and Readonly

Set disabled to disable the input. Set readonly for read-only mode.

<template>
  <div>
    <b-input v-model="value" placeholder="disabled" disabled class="input-item"></b-input>
    <b-input v-model="value1" placeholder="readonly" readonly class="input-item"></b-input>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref('Disabled text')
const value1 = ref('Readonly input')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Combo Usage

Two methods are provided for inserting icons.

Props:

 

Slots:

 

prepend/append:

 
 
<template>
  <div>
    <p>Props:</p>
    <div>
      <b-input prefix="bulb-fill" clearable placeholder="Enter name" style="width: auto"></b-input>
      &nbsp;
      <b-input suffix="search" clearable placeholder="Enter text" style="width: auto"></b-input>
    </div>
    <p>Slots:</p>
    <div style="margin-top: 6px">
      <b-input placeholder="Enter name" style="width: auto">
        <template #prefix>
          <b-icon name="bulb-fill"></b-icon>
        </template>
      </b-input>
      &nbsp;
      <b-input placeholder="Enter text" clearable style="width: auto">
        <template #suffix>
          <b-icon name="search"></b-icon>
        </template>
      </b-input>
    </div>
    <p>prepend/append:</p>
    <div style="margin-top: 6px">
      <b-input placeholder="Enter text" style="width: auto" clearable>
        <template #prepend>
          <b-button>prepend</b-button>
        </template>
      </b-input>
      &nbsp;
      <b-input placeholder="Enter name" style="width: auto" clearable>
        <template #append>
          <b-button>append</b-button>
        </template>
      </b-input>
      &nbsp;
      <b-input placeholder="Enter name" style="width: auto" clearable>
        <template #prepend>
          <b-select v-model="type" clearable style="width: 100px">
            <b-option lable="email" value="email"></b-option>
            <b-option lable="phone" value="phone"></b-option>
          </b-select>
        </template>
        <template #append>
          <b-button>append</b-button>
        </template>
      </b-input>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const type = ref('')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Search state can be configured.

<template>
  <div>
    <b-input v-model="value" search placeholder="Please enter some text..." class="input-item"></b-input>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref('')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Password Input

When entering a password, show/hide toggle is usually needed. An icon toggle will be displayed.

<template>
  <div>
    <b-input v-model="value" show-password-toggle type="password" class="input-item"></b-input>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref('')
</script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Sizes

Three additional sizes are available: large, small, and mini.

<template>
  <b-row :gutter="10">
    <b-col span="6">
      <b-input size="large" clearable placeholder="large input"></b-input>
    </b-col>
    <b-col span="6">
      <b-input clearable placeholder="default input"></b-input>
    </b-col>
    <b-col span="6">
      <b-input size="small" clearable placeholder="small input"></b-input>
    </b-col>
    <b-col span="6">
      <b-input size="mini" clearable placeholder="mini input"></b-input>
    </b-col>
  </b-row>
</template>

Textarea

Set type="textarea" to enable textarea mode.

<template>
  <div flex="box:mean">
    <div class="input-item">
      <b-input
        type="textarea"
        :autosize="{ minRows: 2, maxRows: 6 }"
        placeholder="Auto size, draggable, max 6 rows"
      ></b-input>
    </div>
    <div class="input-item">
      <b-input type="textarea" :rows="4" placeholder="Resize disabled, default 4 rows" no-resize></b-input>
    </div>
  </div>
</template>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Word Count

Set show-word-count to enable the word count display.

0/10
0
<template>
  <div flex="box:mean">
    <div class="input-item">
      <b-input :maxlength="10" show-word-count></b-input>
    </div>
    <div class="input-item">
      <b-input type="textarea" :rows="2" no-resize show-word-count></b-input>
    </div>
  </div>
</template>

<script setup lang="ts"></script>

<style scoped>
.input-item {
  width: 300px;
  margin-right: 20px;
}
</style>

Props

ParameterDescriptionTypeOptionsDefault
typeInput typestringtext / password / textarea / url / email / date (Date) / number / tel
valueBound value, supports v-model two-way bindingString / Number
sizeInput sizelarge / small / default / minidefault
placeholderPlaceholder textString
clearableShow clear buttonBooleanfalse
disabledDisabled stateBooleanfalse
readonlyRead-only modeBooleanfalse
maxlengthMaximum input lengthNumber
iconSuffix icon, only effective in text typeString
prefixinputPrefix iconString
suffixinputSuffix iconString
searchWhether to show as a search inputBooleanfalse
rowsDefault number of rows for textarea. Only effective in textarea modeNumber2
autosizeAuto-resize height based on content. Only effective in textarea mode. Can pass an object, e.g.,Boolean/Objectfalse
numberConvert user input to Number typeBooleanfalse
autofocusAuto focusBooleanfalse
autocompleteNative autocomplete attribute. Accepted values: off, onStringoff
element-idSet an id on the form element. See Form usage.String
wrapNative wrap attribute. Accepted values: hard, soft. Only effective in textarea modeStringsoft
no-resizeDisable textarea resize. Only effective in textarea modeBooleanfalse
show-word-countShow word count. Only effective in textarea modeBooleanfalse
validate (Date)EventWhether to trigger validation. Mainly for form usage. Select and other components also use this internally, set to falseBooleantrue

Input events

Method NameDescriptionReturn Value
enterTriggers when Enter key is pressed
clickTriggers when the icon is clicked (requires icon prop)
changeTriggers when data changesevent
focusTriggers when input gains focus
blurTriggers when input loses focus
keyupNative keyup eventevent
keydownNative keydown eventevent
keypressNative keypress eventevent
searchAvailable when search is enabled. Triggers on search icon click or Enter key pressvalue
clearAvailable when clearable is enabled. Triggers when the clear button is clicked

Input slot

NameDescription
prependPrepend content. Only effective in text type
appendAppend content. Only effective in text type
prefixinputPrefix icon
suffixinputSuffix icon

Input methods

Method NameDescriptionReturn Value
focusManually focus the input