SearchBox
Demos
Stylistic variants
Available stylistic values for the ui
prop: strong
.
<template>
<article>
<veui-search-box/>
<veui-search-box ui="strong"/>
</article>
</template>
<script>
import { SearchBox } from 'veui'
export default {
components: {
'veui-search-box': SearchBox
}
}
</script>
<style lang="less" scoped>
.veui-search-box {
margin-right: 1em;
}
</style>
Size variants
Available size values for the ui
prop: xs
/ s
/ m
/ l
.
<template>
<article>
<div class="container">
<veui-search-box ui="strong xs"/>
</div>
<div class="container">
<veui-search-box ui="strong s"/>
</div>
<div class="container">
<veui-search-box ui="strong"/>
</div>
<div class="container">
<veui-search-box ui="strong l"/>
</div>
<div class="container">
<veui-search-box ui="xs"/>
<veui-search-box ui="s"/>
</div>
<div class="container">
<veui-search-box/>
<veui-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;
.veui-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
:readonly="isReadonly"
:disabled="isDisabled"
/>
<veui-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;
}
.veui-search-box {
margin-right: 1em;
}
</style>
Suggestion list
<template>
<article>
<veui-search-box
v-model="value"
clearable
:suggestions="suggestions"
replace-on-select
@select="handleSelect"
/>
<veui-search-box
v-model="value1"
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>
.veui-search-box {
margin-left: 1em;
}
</style>
API
Props
Name | Type | Default | Description | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string= | - | Style variants.
| ||||||||||||||
placeholder | string | - | The placeholder text of the search box. | ||||||||||||||
value | string | - |
The value of the search box. | ||||||||||||||
autofocus | boolean | false | Whether the search box gains focus automatically. | ||||||||||||||
clearable | boolean | false | Whether the clear button is displayed. | ||||||||||||||
select-on-focus | boolean | false | Whether to select all content upon focus. | ||||||||||||||
composition | boolean | false | Whether the search box triggers value change upon composition of IME. | ||||||||||||||
suggestions | Array<string>|Array<Object> | - | The suggestion list. When the item type is
| ||||||||||||||
replace-on-select | boolean | true | Whether to replace the content with suggestion item value when it's selected. | ||||||||||||||
suggest-trigger | Array<string>|string | input | Specifies when the suggestion list is displayed. Can be either an event name or a list of event names.
| ||||||||||||||
expanded | boolean= | false |
Whether the suggestion list is expanded (if there are no items in | ||||||||||||||
disabled | boolean= | false | Whether the search box is disabled. | ||||||||||||||
readonly | boolean= | false | Whether the search box is read-only. |
Slots
Name | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
suggestions | The content of the entire suggestion list.
| |||||||||
suggestions-before | The content before the suggestion list. | |||||||||
suggestions-after | The content after the suggestion list. | |||||||||
suggestion | The content of each suggestion option.
Additionally, custom properties apart from the listed ones will also be passes into the scope object via When |
Events
Name | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
input | Triggers when the input value changes. The callback parameter list is
| |||||||||
suggest | Triggers when the suggestion list is displayed. The callback parameter list is
| |||||||||
select | Triggered when an suggestion option is selected. The callback parameter list is
| |||||||||
search | Triggered when the input value is submitted. The callback parameter list is
| |||||||||
toggle | Triggered when the expanded state is going to change. The callback parameter list is (expanded: boolean) . expanded denotes whether the suggestion list is to be expanded or collapsed. |
Icons
Name | Description |
---|---|
search | Search. |