検索バーは、ユーザーがリストビュー要素を検索できるようにします。または、カスタム検索を実現するための視覚的な UI コンポーネントとして使用できます。
以下のコンポーネントが含まれています
検索バー
名前 | タイプ | デフォルト | 説明 |
---|---|---|---|
clearButton | boolean | true | 入力クリアボタンを追加します |
colors | object | Tailwind CSS カラークラスを持つオブジェクト | |
colors.inputBgIos | string | '' | |
colors.inputBgMaterial | string | 'bg-md-light-secondary-container dark:bg-md-dark-secondary-container' | |
colors.placeholderIos | string | '' | |
colors.placeholderMaterial | string | 'placeholder-md-light-on-surface-variant dark:placeholder-md-dark-on-surface-variant' | |
disableButton | boolean | false | 検索をキャンセルするためのボタンを追加し、初期状態を設定します |
disableButtonText | string | 'キャンセル' | キャンセルボタンのテキスト |
inputId | string | 入力 ID 属性 | |
inputStyle | CSSProperties | 追加の入力クラス | |
placeholder | string | number | '検索' | 検索バーのプレースホルダー |
value | any | 検索バーの値 | |
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>