Skip to content

Commit

Permalink
fix: Maintain original list order when clearing search input (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-Jayden authored Nov 19, 2023
1 parent 60f7088 commit f39b574
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-lions-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cmdk-sv': patch
---

fix: maintain original list order when clearing search value
11 changes: 8 additions & 3 deletions src/lib/cmdk/components/CommandList.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { isHTMLElement } from '$lib/internal/index.js';
import { getCtx } from '../command.js';
import { getCtx, getState } from '../command.js';
import type { ListProps } from '../types.js';
const { ids } = getCtx();
const state = getState();
type $$Props = ListProps;
Expand Down Expand Up @@ -56,11 +57,15 @@
</script>

{#if asChild}
<slot {list} {sizer} />
{#key $state.search === ''}
<slot {list} {sizer} />
{/key}
{:else}
<div {...listAttrs} bind:this={el} {...$$restProps}>
<div {...sizerAttrs} use:sizerAction>
<slot />
{#key $state.search === ''}
<slot />
{/key}
</div>
</div>
{/if}

0 comments on commit f39b574

Please sign in to comment.