Skip to content

Commit

Permalink
fix: dont use onMount inside CommandInput action for autofocus (#25)
Browse files Browse the repository at this point in the history
Co-authored-by: Hunter Johnston <[email protected]>
  • Loading branch information
Not-Jayden and huntabyte authored Nov 18, 2023
1 parent 4f271e4 commit 30fac0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-lobsters-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cmdk-sv": patch
---

fix: `autofocus` input behavior
10 changes: 4 additions & 6 deletions src/lib/cmdk/components/CommandInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { ITEM_SELECTOR, VALUE_ATTR, getCtx, getState } from '../command.js';
import { addEventListener, isBrowser, isHTMLInputElement } from '$lib/internal/index.js';
import type { InputEvents, InputProps } from '../types.js';
import { onMount } from 'svelte';
import { sleep } from '$lib/internal/helpers/sleep.js';
type $$Props = InputProps;
Expand Down Expand Up @@ -31,11 +30,10 @@
}
function action(node: HTMLInputElement) {
onMount(() => {
if (autofocus) {
sleep(10).then(() => node.focus());
}
});
if (autofocus) {
sleep(10).then(() => node.focus());
}
const unsubEvents = addEventListener(node, 'change', (e) => {
if (!isHTMLInputElement(e.target)) return;
state.updateState('search', e.target.value);
Expand Down

0 comments on commit 30fac0b

Please sign in to comment.