搜索栏允许用户搜索列表视图元素。或者可以将其用作自定义搜索实现的视觉 UI 组件。
包含以下组件
搜索栏
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
clearButton | 布尔值 | true | 添加输入清除按钮 |
colors | 对象 | 包含 Tailwind CSS 颜色类别的对象 | |
colors.inputBgIos | 字符串 | '' | |
colors.inputBgMaterial | 字符串 | 'bg-md-light-secondary-container dark:bg-md-dark-secondary-container' | |
colors.placeholderIos | 字符串 | '' | |
colors.placeholderMaterial | 字符串 | 'placeholder-md-light-on-surface-variant dark:placeholder-md-dark-on-surface-variant' | |
disableButton | 布尔值 | false | 添加用于取消搜索的按钮并设置其初始状态 |
disableButtonText | 字符串 | '取消' | 禁用按钮文本 |
inputId | 字符串 | 输入 ID 属性 | |
inputStyle | CSSProperties | 附加输入类 | |
placeholder | 字符串 | 数字 | '搜索' | 搜索栏占位符 |
value | 任何 | 搜索栏值 | |
onBlur | function(e) |
| |
onChange | function(e) |
| |
onClear | function(e) | 在清除按钮点击时触发 | |
onDisable | function(e) | 在搜索栏禁用时触发 | |
onFocus | function(e) |
| |
onInput | function(e) |
|
<script>import {Page,Navbar,NavbarBackLink,Searchbar,List,ListItem,} from 'konsta/svelte';let searchQuery = '';let items = [{ title: 'FC Ajax' },{ title: 'FC Arsenal' },{ title: 'FC Athletic' },{ title: 'FC Barcelona' },{ title: 'FC Bayern München' },{ title: 'FC Bordeaux' },{ title: 'FC Borussia Dortmund' },{ title: 'FC Chelsea' },{ title: 'FC Galatasaray' },{ title: 'FC Juventus' },{ title: 'FC Liverpool' },{ title: 'FC Manchester City' },{ title: 'FC Manchester United' },{ title: 'FC Paris Saint-Germain' },{ title: 'FC Real Madrid' },{ title: 'FC Tottenham Hotspur' },{ title: 'FC Valencia' },{ title: 'FC West Ham United' },];function handleSearch(e) {searchQuery = e.target.value;}function handleClear() {searchQuery = '';}function handleDisable() {console.log('Disable');}let filteredItems = [];/* eslint-disable */$: {filteredItems = searchQuery? items.filter((item) =>item.title.toLowerCase().includes(searchQuery.toLowerCase())): items;}/* eslint-enable */</script><Page><Navbar title="Searchbar"> <Searchbarslot="subnavbar"onInput={handleSearch}value={searchQuery}onClear={handleClear}disableButtondisableButtonText="Cancel"onDisable={handleDisable}/></Navbar><List strong insetMaterial outlineIos>{#if filteredItems.length === 0}<ListItem title="Nothing found" />{/if}{#each filteredItems as item (item.title)}<ListItem key={item.title} title={item.title} />{/each}</List></Page>