feat: add search button toggle

This commit is contained in:
YunYouJun
2023-07-30 05:21:21 +08:00
parent 2c7f3c94c6
commit 0224e78669
2 changed files with 14 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ import { storeToRefs } from 'pinia'
const rStore = useRecipeStore() const rStore = useRecipeStore()
const { displayedRecipe, selectedStuff, curTool } = storeToRefs(rStore) const { displayedRecipe, selectedStuff, curTool } = storeToRefs(rStore)
const showSearchInput = ref(false)
</script> </script>
<template> <template>
@@ -14,9 +16,14 @@ const { displayedRecipe, selectedStuff, curTool } = storeToRefs(rStore)
<ToggleMode /> <ToggleMode />
<button absolute right-4 top-4 @click="showSearchInput = !showSearchInput">
<div v-if="!showSearchInput" i-ri-search-line />
<div v-else i-ri-search-fill />
</button>
<!-- <Switch /> --> <!-- <Switch /> -->
<div class="cook-recipes" p="2"> <div class="cook-recipes" p="2">
<SearchFoodInput /> <SearchFoodInput v-if="showSearchInput" />
<Transition mode="out-in"> <Transition mode="out-in">
<div class="cook-filter-recipes"> <div class="cook-filter-recipes">

View File

@@ -1,5 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
const rStore = useRecipeStore() const rStore = useRecipeStore()
const searchInput = ref<HTMLInputElement>()
onMounted(() => {
searchInput.value?.focus()
})
</script> </script>
<template> <template>
@@ -14,6 +19,7 @@ const rStore = useRecipeStore()
</div> </div>
<input <input
id="input" id="input"
ref="searchInput"
v-model="rStore.keyword" v-model="rStore.keyword"
placeholder="关键字过滤" placeholder="关键字过滤"
aria-label="搜索关键字" aria-label="搜索关键字"