Skip to content

Commit

Permalink
fix: Fix autoFocusOnShow behavior on Popover
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohaz committed Jan 25, 2022
1 parent 228eaec commit 72944c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ariakit/src/popover/popover-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function usePopoverState({
{
// https://popper.js.org/docs/v2/modifiers/flip/
name: "flip",
enabled: flip,
enabled: flip && dialog.mounted,
options: { padding },
},
{
Expand Down
5 changes: 2 additions & 3 deletions packages/ariakit/src/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ export const usePopover = createHook<PopoverOptions>(
wrapper.style.zIndex = getComputedStyle(popover).zIndex;
}, [popoverRef, state.contentElement]);

const domReady = !portal || portalNode;
const [canAutoFocusOnShow, setCanAutoFocusOnShow] = useState(state.fixed);

// When the popover is absolutely positioned, we can't move focus right
// after it gets open. Otherwise we may see some scroll jumps. So we wait a
// bit so Popper can finish positioning the popover before we move focus.
useEffect(() => {
if (state.fixed) return;
setCanAutoFocusOnShow(!!domReady && state.mounted);
}, [state.fixed, domReady, state.mounted]);
setCanAutoFocusOnShow(state.mounted && !!state.contentElement);
}, [state.fixed, state.mounted, state.contentElement]);

// Wrap our element in a div that will be used to position the popover.
// This way the user doesn't need to override the popper's position to
Expand Down

1 comment on commit 72944c1

@vercel
Copy link

@vercel vercel bot commented on 72944c1 Jan 25, 2022

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:

ariakit – ./

www.ariakit.org
ariakit-ariakit.vercel.app
ariakit-git-v2-ariakit.vercel.app
ariakit.org

Please sign in to comment.