Skip to content

Instantly share code, notes, and snippets.

@braden-w
Last active July 3, 2022 12:11
Show Gist options
  • Save braden-w/348d17336bdc2d43664a1a1a65c676ed to your computer and use it in GitHub Desktop.
Save braden-w/348d17336bdc2d43664a1a1a65c676ed to your computer and use it in GitHub Desktop.
DaisyUI Clear Input Button. Demonstrates how to add a "clear input" button to DaisyUI, with an example in Svelte. Feel free to style and modify as desired.
<label class="label" for="my-id">
<span class="label-text">Insert your label here...</span>
</label>
<div class="input-group">
<input
tabindex="0"
type="text"
id="my-id"
class="input input-accent border-opacity-20"
placeholder="Your placeholder here..."
/>
<button class="btn btn-ghost btn-circle border-accent border-opacity-20">
<!-- Insert a backspace svg -->
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2M3 12l6.414 6.414a2 2 0 001.414.586H19a2 2 0 002-2V7a2 2 0 00-2-2h-8.172a2 2 0 00-1.414.586L3 12z"
/>
</svg>
</button>
</div>
<script lang="ts">
let query: string = "";
function resetLocation() {
query = '';
}
</script>
<label class="label" for="my-id">
<span class="label-text">Insert your label here...</span>
</label>
<div class="input-group">
<input
tabindex="0"
type="text"
id="my-id"
class="input input-accent border-opacity-20"
placeholder="Your placeholder here..."
bind:value={query}
/>
<button class="btn btn-ghost btn-circle border-accent border-opacity-20" on:click={resetQuery}>
<!-- Insert a backspace svg -->
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2M3 12l6.414 6.414a2 2 0 001.414.586H19a2 2 0 002-2V7a2 2 0 00-2-2h-8.172a2 2 0 00-1.414.586L3 12z"
/>
</svg>
</button>
</div>
@braden-w
Copy link
Author

braden-w commented Jul 3, 2022

Demo:

Screenshot 2022-07-03 at 13-05-03 Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment