VEUI

VEUI on GitHub
Play!中文

SearchBox

Examples

Style variants

Available ui prop values: strong.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-search-box class="search-box"/>
  <veui-search-box
    class="search-box"
    ui="strong"
  />
</article>
</template>

<script>
import { SearchBox } from 'veui'

export default {
  components: {
    'veui-search-box': SearchBox
  }
}
</script>

<style lang="less" scoped>
.search-box {
  margin-right: 1em;
}
</style>

Size variants

Available ui prop values: xs / s / m / l.

Edit this demo on GitHubEdit
<template>
<article>
  <div class="container">
    <veui-search-box
      class="search-box"
      ui="strong xs"
    />
  </div>
  <div class="container">
    <veui-search-box
      class="search-box"
      ui="strong s"
    />
  </div>
  <div class="container">
    <veui-search-box
      class="search-box"
      ui="strong"
    />
  </div>
  <div class="container">
    <veui-search-box
      class="search-box"
      ui="strong l"
    />
  </div>
  <div class="container">
    <veui-search-box
      class="search-box"
      ui="xs"
    />
    <veui-search-box
      class="search-box"
      ui="s"
    />
  </div>
  <div class="container">
    <veui-search-box class="search-box"/>
    <veui-search-box
      class="search-box"
      ui="l"
    />
  </div>
</article>
</template>

<script>
import { SearchBox } from 'veui'

export default {
  components: {
    'veui-search-box': SearchBox
  }
}
</script>

<style lang="less" scoped>
.container {
  margin-bottom: 1em;
  .search-box {
    margin-right: 1em;
  }
}
</style>

Read-only and disabled

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-radio-group
      v-model="state"
      :items="states"
    />
  </section>
  <section>
    <veui-search-box
      class="search-box"
      :readonly="isReadonly"
      :disabled="isDisabled"
    />
    <veui-search-box
      class="search-box"
      :readonly="isReadonly"
      :disabled="isDisabled"
      ui="strong"
    />
  </section>
</article>
</template>

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

export default {
  components: {
    'veui-search-box': 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>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}

.search-box {
  margin-right: 1em;
}
</style>

Suggestions

Edit this demo on GitHubEdit
<template>
<article>
  <veui-search-box
    v-model="value"
    class="search-box"
    clearable
    :suggestions="suggestions"
    replace-on-select
    @select="handleSelect"
  />
  <veui-search-box
    v-model="value1"
    class="search-box"
    ui="strong"
    clearable
    :suggestions="suggestions1"
    replace-on-select
    @select="handleSelect"
  />
</article>
</template>

<script>
import { SearchBox, toast } from 'veui'

export default {
  components: {
    'veui-search-box': SearchBox
  },
  data () {
    return {
      value: '',
      value1: '',
      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
      })
    },
    suggestions1 () {
      if (!this.value1) {
        return []
      }
      return this.browsers.filter(browser => {
        return browser.toLowerCase().indexOf(this.value1.toLowerCase()) !== -1
      })
    }
  },
  methods: {
    handleSelect ({ value }) {
      toast.info(value)
    }
  }
}
</script>

<style lang="less" scoped>
.search-box {
  margin-left: 1em;
}
</style>

API

Props

NameTypeDefaultDescription
uistring-

Button preset style.

ValueDescription
strongEnhanced style. The search icon becomes a search button, and the background is the theme color.
xsExtra small size style.
sSmall size style.
mMedium size style.
lLarge size style.
valuestring-

v-model

The value of the input.

disabledbooleanfalseWhether the input is disabled.
readonlybooleanfalseWhether the input is read-only.
placeholderstring-Placeholder text of the search box.
clearablebooleanfalseWhether to show the clear button.
select-on-focusbooleanfalseWhether to select text on focus.
compositionbooleanfalseWhether to enable composition mode.
autofocusbooleanfalseWhether the input is autofocus.
suggestionsArray<string>|Array<Object>-

The suggestion list. When the item is an Object, it should be in the format of {label, value}.

NameTypeDescription
labelstringThe text of the suggestion item.
valuestringThe value of the suggestion item.
replace-on-selectbooleantrueWhether to replace input with selected suggestion.
maxlengthnumber-Maximum length of input.
get-lengthfunction(string): number-Custom function for calculating character length.
strictbooleanfalseWhether to disallow input when maximum length is reached.
trimboolean | stringfalse

Whether to remove leading and trailing white space. When set to true, leading and trailing white space is removed; when set to false, it is not. When set to a string, leading and/or trailing white space is removed according to the specified mode.

ValueDescription
bothRemove leading and trailing white space. Equivalent to the behavior when true is set.
startRemove leading white space.
endRemove trailing white space.
suggest-triggerArray<string>|stringinput

The trigger time for displaying the suggestion list. It can be an enum value or a combination of enum values.

ValueDescription
focusWhen the input is focused.
inputWhen the input event is triggered.
submitWhen the search button is clicked.
expandedbooleanfalse

.sync

Whether the suggestion panel is expanded (the panel will be closed even if it is set to true when there are no suggestions to select from).

match(item, keyword, { ancestors }) => boolean | Array<[number, number]>-Custom function for highlighting matched text, case-insensitive by default. Refer to Autocomplete
filter(item, keyword, { ancestors, offsets }) => boolean-Custom function for filtering search results. Refer to Autocomplete
overlay-classstring | Array | Object-The same as the overlay-class prop of the Overlay component.
overlay-stylestring | Array | Object-The same as the overlay-style prop of the Overlay component.

Slots

NameDescription
suggestionsContent of the suggestion list.
suggestions-beforeContent before the suggestion list.
suggestions-afterContent after the suggestion list.
suggestion[^slot-suggestion]
clearTriggered when the clear button is clicked.
group-labelRefers to the group-label prop of the Select component.
option-labelRefers to the option-label prop of the Select component.

Events

NameDescription
inputTriggered when the text in the input box changes. The callback parameter is (value: string), where value is the value in the input box.
suggestTriggered when the recommendation list needs to be displayed. The callback parameter is (value: string), where value is the value in the input box.
selectTriggered when a certain option in the recommendation list is selected. The callback parameter is (item: {label: string, value: string, ...}), where item is a single option object.
search

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

NameTypeDescription
valuestringThe value in the input box.
eventEventNative click event.
toggleTriggered when the expansion state of the prompt panel is toggled. The callback parameter is (expanded: boolean). expanded indicates whether the operation will expand or collapse the prompt panel.

Icons

NameDescription
searchSearch.

CSS

NameTypeDefaultDescription
--dls-dropdown-max-display-items<integer>8

The maximum number of items displayed in the drop-down list at the same time. The maximum height of the drop-down box will be calculated based on this value.

Edit this page on GitHubEdit
© Baidu, Inc. 2024