Skip to content

Instantly share code, notes, and snippets.

@omirobarcelo
Created April 17, 2021 10:22
Show Gist options
  • Save omirobarcelo/0c0dc80584de56cbd326cb0dff5feb43 to your computer and use it in GitHub Desktop.
Save omirobarcelo/0c0dc80584de56cbd326cb0dff5feb43 to your computer and use it in GitHub Desktop.
WebHero - 6 - Disable and navigation of search bar
<script lang="ts">
export let segment: string;
$: if (segment === 'create') {
search.update('');
// If navigating directly to create, this executes before the onMount
if (searchElem) {
searchElem.value = '';
}
}
let searchElem: HTMLInputElement;
async function onSearchBarClick() {
await goto('/');
searchElem.focus();
}
</script>
<nav>
<input
bind:this={searchElem}
on:click={onSearchBarClick}
id="search"
type="search"
placeholder="Search..."
disabled={segment === 'create'}
/>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment