検索バーを使用すると、リストビュー要素を検索できます。または、カスタム検索の実装のための視覚的な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' | |
| component | string | 'div' | コンポーネントのHTML要素 |
| disableButton | boolean | false | 検索をキャンセルするためのボタンを追加し、その初期状態を設定します |
| disableButtonText | string | 'キャンセル' | 無効化ボタンテキスト |
| inputId | string | input のid属性 | |
| inputStyle | CSSProperties | 追加の入力クラス | |
| placeholder | string | string | '検索' | 検索バーのプレースホルダー |
| value | any | 検索バーの値 |
| 名前 | 型 | 説明 |
|---|---|---|
| blur | function(e) |
|
| change | function(e) |
|
| clear | function(e) | クリアボタンクリック時に発生します |
| disable | function(e) | 検索バーが無効化されたときに発生します |
| focus | function(e) |
|
| input | function(e) |
|
<template><k-page><k-navbar title="Searchbar"><template #subnavbar><k-searchbar:value="searchQuery"disable-buttondisable-button-text="Cancel"@clear="handleClear"@disable="handleDisable"@input="handleSearch"></k-searchbar></template></k-navbar><k-list strong inset-material outline-ios><k-list-item v-if="filteredItems.length === 0" title="Nothing found" /><k-list-itemv-for="item in filteredItems":key="item.title":title="item.title"/></k-list></k-page></template><script>import { ref, watch } from 'vue';import {kPage,kNavbar,kNavbarBackLink,kSearchbar,kList,kListItem,} from 'konsta/vue';const 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' },];export default {components: {kPage,kNavbar,kNavbarBackLink,kSearchbar,kList,kListItem,},setup() {const searchQuery = ref('');const handleSearch = (e) => {searchQuery.value = e.target.value;};const handleClear = () => {searchQuery.value = '';};const handleDisable = () => {console.log('Disable');};const filteredItems = ref(items);watch(searchQuery, () => {filteredItems.value = searchQuery.value? items.filter((item) =>item.title.toLowerCase().includes(searchQuery.value.toLowerCase())): items;});return {searchQuery,filteredItems,handleSearch,handleClear,handleDisable,};},};</script>