SearchBox
Examples
Style variants
Available ui
prop values: strong
.
<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
.
<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
<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
<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
Name | Type | Default | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string | - | Button preset style.
| ||||||||||||
value | string | - |
The value of the input. | ||||||||||||
disabled | boolean | false | Whether the input is disabled. | ||||||||||||
readonly | boolean | false | Whether the input is read-only. | ||||||||||||
placeholder | string | - | Placeholder text of the search box. | ||||||||||||
clearable | boolean | false | Whether to show the clear button. | ||||||||||||
select-on-focus | boolean | false | Whether to select text on focus. | ||||||||||||
composition | boolean | false | Whether to enable composition mode. | ||||||||||||
autofocus | boolean | false | Whether the input is autofocus. | ||||||||||||
suggestions | Array<string>|Array<Object> | - | The suggestion list. When the item is an
| ||||||||||||
replace-on-select | boolean | true | Whether to replace input with selected suggestion. | ||||||||||||
maxlength | number | - | Maximum length of input. | ||||||||||||
get-length | function(string): number | - | Custom function for calculating character length. | ||||||||||||
strict | boolean | false | Whether to disallow input when maximum length is reached. | ||||||||||||
trim | boolean | string | false | Whether to remove leading and trailing white space. When set to
| ||||||||||||
suggest-trigger | Array<string>|string | input | The trigger time for displaying the suggestion list. It can be an enum value or a combination of enum values.
| ||||||||||||
expanded | boolean | false |
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-class | string | Array | Object | - | The same as the overlay-class prop of the Overlay component. | ||||||||||||
overlay-style | string | Array | Object | - | The same as the overlay-style prop of the Overlay component. |
Slots
Name | Description |
---|---|
suggestions | Content of the suggestion list. |
suggestions-before | Content before the suggestion list. |
suggestions-after | Content after the suggestion list. |
suggestion | [^slot-suggestion] |
clear | Triggered when the clear button is clicked. |
group-label | Refers to the group-label prop of the Select component. |
option-label | Refers to the option-label prop of the Select component. |
Events
Name | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
input | Triggered when the text in the input box changes. The callback parameter is (value: string) , where value is the value in the input box. | |||||||||
suggest | Triggered when the recommendation list needs to be displayed. The callback parameter is (value: string) , where value is the value in the input box. | |||||||||
select | Triggered 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
| |||||||||
toggle | Triggered 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
Name | Description |
---|---|
search | Search. |
CSS
Name | Type | Default | Description |
---|---|---|---|
--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. |