Skip to content

Commit b1c4df1

Browse files
chore: tweaks on implementation details
1 parent a3895f5 commit b1c4df1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/lib/components/command/Item.svelte

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
let acted = false;
3535
3636
beforeNavigate(({ complete }) => {
37-
complete.then(acted ? callback : null);
37+
acted && complete.then(null);
3838
});
3939
</script>
4040

@@ -57,29 +57,30 @@
5757
{:else if item.type === "link"}
5858

5959
<Command.Item onSelect={() => acted = true} asChild let:action let:attrs>
60+
{@const highlighted = attrs["data-selected"]}
6061
<!-- eslint-disable-next-line no-unused-vars -->
61-
{@const _ = (browser && attrs["data-selected"] && preloadData(item.href))}
62-
<a href={item.href} use:action {...attrs} class:selected={attrs["data-selected"]}>
62+
{@const _ = (browser && highlighted && preloadData(item.href))}
63+
<a href={item.href} use:action {...attrs} class:highlighted>
6364
{item.text}
6465
</a>
6566
</Command.Item>
6667

6768
{:else if item.type === "cmd"}
6869

69-
<Command.Item onSelect={value => item.callback(value).then(() => acted = true)} asChild let:action let:attrs>
70-
<button use:action {...attrs} class:selected={attrs["data-selected"]}>
70+
<Command.Item onSelect={value => (async () => item.callback(value))().finally(callback)} asChild let:action let:attrs>
71+
<button use:action {...attrs} class:highlighted={attrs["data-selected"]}>
7172
{item.text}
7273
</button>
7374
</Command.Item>
7475

7576
{/if}
7677

7778
<style>
78-
a, button {
79-
--uno: block w-full rounded-md p-2 -mx-2;
80-
}
79+
a, button {
80+
--uno: block w-full rounded-md p-2 -mx-2;
81+
}
8182
82-
.selected {
83-
--uno: bg-white/5;
84-
}
83+
.highlighted {
84+
--uno: bg-white/5;
85+
}
8586
</style>

0 commit comments

Comments
 (0)