Skip to content

Commit

Permalink
fix: onSelect 이벤트가 발생하더라도 input 포커스 유지하도록 수정
Browse files Browse the repository at this point in the history
사용자 경험을 향상하기 위해 사용자가 뭔가를 선택해도 input으로 포커스를 다시 설정합니다.
하지만 현재 사용 사례를 고려했을 때 문제 될 점이 없으므로 이 방식대로 적용합니다.
  • Loading branch information
이재민 committed Feb 25, 2024
1 parent 71fbbf0 commit 36ecd27
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/tabs/tabs-cmdk.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,29 @@
}
};
const isFocusable = (element: HTMLElement): boolean => {
const tabIndex = element.getAttribute('tabIndex');
const isTabIndexFocusable = tabIndex !== null && parseInt(tabIndex, 10) >= 0;
return isTabIndexFocusable || element.isContentEditable;
};
const handleClickOutside = (event: MouseEvent) => {
const target = event.target as HTMLElement;
if (!isFocusable(target)) {
cmdkInputEl?.focus();
event.preventDefault();
}
};
onMount(() => {
cmdkInputEl = document.querySelector('[data-cmdk-input]') as HTMLInputElement;
});
</script>

<svelte:window on:click={handleClickOutside} />

<Command.Root
onKeydown={handleKeydown}
tabindex={-1}
Expand Down

0 comments on commit 36ecd27

Please sign in to comment.