feat: search panel

This commit is contained in:
Shibo Lyu 2024-09-10 05:04:05 +08:00
parent 3ee0156d19
commit ca3dba04e0
2 changed files with 11 additions and 7 deletions

View file

@ -4,14 +4,13 @@
import { Icon, MagnifyingGlass, PencilSquare, XCircle } from 'svelte-hero-icons';
import IdentityMenu from './IdentityMenu.svelte';
import { tw } from '$lib/tw';
import { tick } from 'svelte';
export let searchQuery: string = '';
export let isSearchFocused: boolean;
let inputElement: HTMLInputElement;
function onTapX() {
function onTapClear() {
searchQuery = '';
inputElement.blur();
}
@ -28,17 +27,21 @@
bind:value={searchQuery}
bind:this={inputElement}
on:focus={() => (isSearchFocused = true)}
on:blur={async () => {
await tick();
on:blur={(e) => {
// If the related target is an anchor element, trigger the click as the user is trying to navigate
if (e.relatedTarget instanceof HTMLAnchorElement) {
console.log('relatedTarget is an anchor element');
e.relatedTarget.click();
}
isSearchFocused = false;
}}
/>
<button
class={tw(
'size-4 cursor-default text-slate-300 opacity-0 transition-opacity dark:text-slate-500',
isSearchFocused && 'opacity-100'
'pointer-events-none size-4 cursor-default text-slate-300 opacity-0 transition-opacity dark:text-slate-500',
isSearchFocused && 'pointer-events-auto opacity-100'
)}
on:click={onTapX}
on:click={onTapClear}
>
<Icon src={XCircle} mini />
<span class="sr-only">Clear</span>

View file

@ -26,6 +26,7 @@
)}
>
<a
tabindex="-1"
href="/chats/{urlSafeEndpoint}/{chat.id}"
class="flex h-20 cursor-default items-center gap-2 px-2"
>