This commit is contained in:
Timothy Jaeryang Baek
2026-03-15 23:48:44 -05:00
parent a361df840e
commit 68973f9b39
3 changed files with 6 additions and 13 deletions
+2 -8
View File
@@ -1,8 +1,6 @@
<script lang="ts"> <script lang="ts">
import { flyAndScale } from '$lib/utils/transitions'; import { flyAndScale } from '$lib/utils/transitions';
import { createEventDispatcher, tick } from 'svelte'; import { tick } from 'svelte';
const dispatch = createEventDispatcher();
/** Whether the dropdown is open */ /** Whether the dropdown is open */
export let show = false; export let show = false;
@@ -106,7 +104,6 @@
async function toggleOpen() { async function toggleOpen() {
show = !show; show = !show;
onOpenChange(show); onOpenChange(show);
dispatch('change', show);
if (show) { if (show) {
await tick(); await tick();
positionContent(); positionContent();
@@ -129,22 +126,19 @@
if (contentEl?.contains(event.target)) return; if (contentEl?.contains(event.target)) return;
show = false; show = false;
onOpenChange(false); onOpenChange(false);
dispatch('change', false);
} }
function handleKeydown(event) { function handleKeydown(event) {
if (event.key === 'Escape' && show) { if (event.key === 'Escape' && show) {
show = false; show = false;
onOpenChange(false); onOpenChange(false);
dispatch('change', false); }
}
} }
/** Close the dropdown programmatically */ /** Close the dropdown programmatically */
export function close() { export function close() {
show = false; show = false;
onOpenChange(false); onOpenChange(false);
dispatch('change', false);
} }
</script> </script>
+2 -2
View File
@@ -109,8 +109,8 @@
<Dropdown <Dropdown
bind:show bind:show
{align} {align}
on:change={(e) => { onOpenChange={(state) => {
if (e.detail === false) { if (state === false) {
search = ''; search = '';
onClose(); onClose();
} }
@@ -59,8 +59,7 @@
} }
}; };
const handleDropdownChange = (e) => { const handleDropdownChange = (state) => {
const state = e.detail;
dispatch('change', state); dispatch('change', state);
// Fetch usage info when dropdown opens, if user has permission // Fetch usage info when dropdown opens, if user has permission
@@ -79,7 +78,7 @@
/> />
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<Dropdown bind:show on:change={handleDropdownChange} {align}> <Dropdown bind:show onOpenChange={handleDropdownChange} {align}>
<slot /> <slot />
<div slot="content"> <div slot="content">