Skip to content

Commit

Permalink
Fix Next.js bug where Safari scrolls to bottom when closing kbar (#284)
Browse files Browse the repository at this point in the history
It's possible for the previous active element to be the same as the
current activeElement ref when blurring focus to prevent Safari from
scrolling down when the kbar is closed. This results in re-focusing the
input element.

This commit additionally checks that we didn't just blur the input
before closing, before re-focusing it.
  • Loading branch information
terabyte128 authored Jan 30, 2023
1 parent 738eb81 commit a8f4766
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/InternalEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function useFocusHandler() {
}

const activeElement = activeElementRef.current;
if (activeElement) {
if (activeElement && activeElement !== currentActiveElement) {
activeElement.focus();
}
}, [isShowing]);
Expand Down

1 comment on commit a8f4766

@vercel
Copy link

@vercel vercel bot commented on a8f4766 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kbar – ./

kbar-timc.vercel.app
kbar-git-main-timc.vercel.app
kbar.vercel.app

Please sign in to comment.