Searchbox

Demos

Stylistic variants

Available stylistic values for the ui prop: primary.

<template>
<article>
  <veui-searchbox/>
  <veui-searchbox ui="primary"/>
</article>
</template>

<script>
import { Searchbox } from 'veui'

export default {
  components: {
    'veui-searchbox': Searchbox
  }
}
</script>

Size variants

Available size values for the ui prop: large/small.

<template>
<article>
  <veui-searchbox ui="large"/>
  <veui-searchbox/>
  <veui-searchbox ui="small"/>
</article>
</template>

<script>
import { Searchbox } from 'veui'

export default {
  components: {
    'veui-searchbox': Searchbox
  }
}
</script>

Read-only and disabled

<template>
<article>
  <section>
    <veui-radio-group
      v-model="state"
      :items="states"
    />
  </section>
  <section>
    <veui-searchbox
      :readonly="isReadonly"
      :disabled="isDisabled"
    />
    <veui-searchbox
      :readonly="isReadonly"
      :disabled="isDisabled"
      ui="primary"
    />
  </section>
</article>
</template>

<script>
import { Searchbox, RadioGroup } from 'veui'

export default {
  components: {
    'veui-searchbox': Searchbox,
    'veui-radio-group': RadioGroup
  },
  data () {
    return {
      state: null,
      states: [
        {
          label: 'Normal',
          value: null
        },
        {
          label: 'Read-only',
          value: 'readonly'
        },
        {
          label: 'Disabled',
          value: 'disabled'
        }
      ]
    }
  },
  computed: {
    isReadonly () {
      return this.state === 'readonly'
    },
    isDisabled () {
      return this.state === 'disabled'
    }
  }
}
</script>

Suggestion list

<template>
<article>
  <veui-searchbox
    v-model="value"
    clearable
    :suggestions="suggestions"
    replace-on-select
    @select="handleSelect"
  />
</article>
</template>

<script>
import { Searchbox } from 'veui'
import toast from 'veui/managers/toast'

export default {
  components: {
    'veui-searchbox': Searchbox
  },
  data () {
    return {
      value: '',
      browsers: [
        'Google Chrome',
        'Apple Safari',
        'Microsoft Edge',
        'Mozilla Firefox',
        'Opera',
        'Vivaldi',
        'Internet Explorer',
        'Maxthon',
        'Android Browser',
        'UC Browser',
        'Samsung Internet',
        'QQ Browser'
      ]
    }
  },
  computed: {
    suggestions () {
      if (!this.value) {
        return []
      }
      return this.browsers.filter(browser => {
        return browser.toLowerCase().indexOf(this.value.toLowerCase()) !== -1
      })
    }
  },
  methods: {
    handleSelect ({ value }) {
      toast.info(value)
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
uistring-

Style variants.

ValueDescription
primaryPrimary style.
largeLarge size.
smallSmall size.
placeholderstring-The placeholder text of the search box.
valuestring-

v-model

The value of the search box.

autofocusbooleanfalseWhether the search box gains focus automatically.
clearablebooleanfalseWhether the clear button is displayed.
select-on-focusbooleanfalseWhether to select all content upon focus.
compositionbooleanfalseWhether the search box triggers value change upon composition of IME.
suggestionsArray<string>|Array<Object>-

The suggestion list. When the item type is Object, the properties will be {label, value}.

NameTypeDescription
labelstringThe text of the suggestion option.
valuestringThe value of the suggestion option.
replace-on-selectbooleantrueWhether to replace the content with suggestion item value when it's selected.
suggest-triggerArray<string>|stringinput

Specifies when the suggestion list is displayed. Can be either an event name or a list of event names.

ValueDescription
focusWhen the search box is focused.
inputWhen the input triggers input event.
submitWhen the submit button is activated.
disabledbooleanfalseWhether the search box is disabled.
readonlybooleanfalseWhether the search box is read-only.

Slots

NameDescription
suggestions

The content of the entire suggestion list.

NameTypeDescription
suggestionsArray<{value: string, label: string}>The normalized suggestions from the suggestions prop.
selectfunction(suggestion: {value: string, label: string}): voidSelect the specified suggestion.
suggestions-beforeThe content before the suggestion list.
suggestions-afterThe content after the suggestion list.
suggestion

The content of each suggestion option.

NameTypeDescription
labelstringThe text label of the suggestion option.
valuestringThe value of the suggestion option.

Additionally, custom properties apart from the listed ones will also be passes into the scope object via v-bind.

When suggestions is an Array<string>, the label and value of the suggestion option will share the same string value.

Events

NameDescription
input

Triggers when the input value changes. The callback parameter list is (value: string).

NameTypeDescription
valuestringThe value of the input.
suggest

Triggers when the suggestion list is displayed. The callback parameter list is (value: string).

NameTypeDescription
valuestringThe value of the input.
select

Triggered when an suggestion option is selected. The callback parameter list is (item: Object).

NameTypeDescription
item{label: string, value: string=, ...}The suggestion option.
search

Triggered when the input value is submitted. The callback parameter list is (value: string, event: Event).

NameTypeDescription
valuestringThe value of the input.
eventEventThe native click event object.

Icons

NameDescription
searchSearch.