mirror of
https://github.com/shadoll/sLogos.git
synced 2026-02-04 11:03:24 +00:00
Enhance search functionality in Header component with clear button and improved input handling
This commit is contained in:
@@ -82,9 +82,8 @@
|
|||||||
).sort((a, b) => a.text.localeCompare(b.text));
|
).sort((a, b) => a.text.localeCompare(b.text));
|
||||||
|
|
||||||
$: filteredLogos = logos.filter((logo) => {
|
$: filteredLogos = logos.filter((logo) => {
|
||||||
const matchesSearch = logo.name
|
const matchesSearch = logo.name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
.toLowerCase()
|
|| (logo.brand && logo.brand.toLowerCase().includes(searchQuery.toLowerCase()));
|
||||||
.includes(searchQuery.toLowerCase());
|
|
||||||
const matchesTags =
|
const matchesTags =
|
||||||
!selectedTags.length ||
|
!selectedTags.length ||
|
||||||
(logo.tags &&
|
(logo.tags &&
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
export let addTag;
|
export let addTag;
|
||||||
export let removeTag;
|
export let removeTag;
|
||||||
export let getTagObj;
|
export let getTagObj;
|
||||||
|
|
||||||
|
function onInput(event) {
|
||||||
|
searchQuery = event.target.value;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header class="main-header">
|
<header class="main-header">
|
||||||
@@ -96,7 +100,16 @@
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Search logos..."
|
placeholder="Search logos..."
|
||||||
bind:value={searchQuery}
|
bind:value={searchQuery}
|
||||||
|
on:input={onInput}
|
||||||
|
aria-label="Search logos"
|
||||||
/>
|
/>
|
||||||
|
{#if searchQuery}
|
||||||
|
<button class="clear-btn" on:click={() => searchQuery = ''} aria-label="Clear search">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M4 4L12 12M12 4L4 12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-filter">
|
<div class="tag-filter">
|
||||||
{#each selectedTags as tagText}
|
{#each selectedTags as tagText}
|
||||||
@@ -158,8 +171,7 @@
|
|||||||
x="11"
|
x="11"
|
||||||
y="11"
|
y="11"
|
||||||
width="6"
|
width="6"
|
||||||
height="6"
|
height="6" fill="currentColor"
|
||||||
fill="currentColor"
|
|
||||||
/></svg
|
/></svg
|
||||||
>
|
>
|
||||||
</button>
|
</button>
|
||||||
@@ -186,3 +198,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.search-bar {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.search-bar input {
|
||||||
|
padding-right: 2em;
|
||||||
|
}
|
||||||
|
.clear-btn {
|
||||||
|
position: absolute;
|
||||||
|
right: 0.5em;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #888;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.clear-btn:hover {
|
||||||
|
color: #f44336;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user