Skip to content

Commit

Permalink
fix(navigation-menu): incorrect animation after closed
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 committed Aug 26, 2024
1 parent 7b26d59 commit b6f81ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/menu/menu-content-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export function MenuContentBase<T extends ValidComponent = "div">(

createEffect(() => onCleanup(context.registerContentId(local.id!)));

onCleanup(() => context.setContentRef(undefined));

const commonAttributes: Omit<MenuContentBaseRenderProps, keyof MenuDataSet> =
{
ref: mergeRefs((el) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/menu/menu-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface MenuContextValue {
triggerId: Accessor<string | undefined>;
contentId: Accessor<string | undefined>;
setTriggerRef: (el: HTMLElement) => void;
setContentRef: (el: HTMLElement) => void;
setContentRef: (el: HTMLElement | undefined) => void;
open: (focusStrategy: FocusStrategy | boolean) => void;
close: (recursively?: boolean) => void;
toggle: (focusStrategy: FocusStrategy | boolean) => void;
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/navigation-menu/navigation-menu-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ export function NavigationMenuRoot<T extends ValidComponent = "ul">(
element: () => viewportRef() ?? null,
});

createEffect(() => {
if (!viewportPresent()) {
context.setPreviousMenu(undefined);
}
});

const context: NavigationMenuContextValue = {
dataset,
delayDuration: () => local.delayDuration!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ export function NavigationMenuTrigger<T extends ValidComponent = "button">(
if (context.dataset()["data-expanded"] === "") return;

timeoutId = window.setTimeout(() => {
context.setAutoFocusMenu(true);
menuContext?.triggerRef()?.focus();
setTimeout(() => {
context.setAutoFocusMenu(true);
});
}, context.delayDuration());
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ export function NavigationMenuViewport<T extends ValidComponent = "li">(
);

const height = createMemo((prev) => {
if (ref() === undefined || !context.viewportPresent()) return undefined;
if (size.height() === 0) return prev;
return size.height();
});
const width = createMemo((prev) => {
if (ref() === undefined || !context.viewportPresent()) return undefined;
if (size.width() === 0) return prev;
return size.width();
});
Expand Down

0 comments on commit b6f81ac

Please sign in to comment.