Skip to content

Commit

Permalink
fixed main menu flash
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Jan 5, 2024
1 parent d43c60b commit 1222580
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/components/elements/ombed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const Oembed = ({url, ...props}: Props) => {
const ref = useRef<HTMLDivElement>(null)
const entry = useIntersectionObserver(ref, {freezeOnceVisible: true});
return (
// @ts-ignore
<div {...props} ref={ref} className="relative aspect-[16/9] w-full">
{!!entry?.isIntersecting && <Embed url={url} LoadingFallbackElement={<Loading/>}/>}
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/components/elements/select-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ const SelectList = ({options = [], label, multiple, ariaLabelledby, required, de
...props
});

useEffect(() => {
listboxVisible && listboxRef.current?.focus();
}, [listboxVisible]);
useEffect(() => listboxRef.current?.focus(), [listboxVisible]);

useLayoutEffect(() => {
const parentContainer = listboxRef.current?.parentElement?.getBoundingClientRect();
Expand Down
7 changes: 2 additions & 5 deletions src/components/menu/main-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ const MainMenu = ({menuItems}: { menuItems: DrupalMenuItem[] }) => {
const handleEscape = useCallback((event: KeyboardEvent) => {
if (event.key === "Escape" && menuOpen) {
closeMenu()

// @ts-ignore
buttonRef.current?.focus();
}
}, [menuOpen, closeMenu]);

useEffect(closeMenu, [browserUrl, closeMenu]);
useEffect(() => closeMenu(), [browserUrl, closeMenu]);

useEffect(() => {
// Add keydown listener for escape button if the submenu is open.
Expand Down Expand Up @@ -80,7 +78,7 @@ const MenuItem = ({id, url, title, activeTrail, items, level = 0}: MenuItemProps
const itemProps = useOutsideClick(closeSubmenu);

// Close the submenu if the url changes.
useEffect(closeSubmenu, [browserUrl, closeSubmenu]);
useEffect(() => closeSubmenu(), [browserUrl, closeSubmenu]);

useLayoutEffect(() => {
// If the right side of the submenu is not visible, set the position to be on the left of the menu item.
Expand All @@ -96,7 +94,6 @@ const MenuItem = ({id, url, title, activeTrail, items, level = 0}: MenuItemProps
}
}, [submenuOpen, closeSubmenu]);


useEffect(() => {
// Add keydown listener for escape button if the submenu is open.
if (submenuOpen) document.addEventListener("keydown", handleEscape);
Expand Down
3 changes: 2 additions & 1 deletion src/components/tools/editorially.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const Editori11y = () => {
if (typeof Ed11y != 'undefined') {
// @ts-ignore
new Ed11y({
checkRoots: '#main-content'
checkRoots: '#main-content',
ignoreElements: 'nav'
});
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/lib/hooks/useNavigationEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
'use client';

import {usePathname} from 'next/navigation';
import {useEffect, useRef, useState} from "react";
import {useEffect, useState} from "react";
import {syncDrupalPreviewRoutes} from "@lib/drupal/sync-drupal-preview-path";

const useNavigationEvent = () => {
const isInitialMount = useRef(true);
const [url, setUrl] = useState<string | null>();
const pathname = usePathname();

useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
return;
}
if (!pathname) return;

if (pathname !== url && !(pathname?.startsWith('/gallery-image/'))) {
setUrl(pathname ? pathname : null);
Expand Down

1 comment on commit 1222580

@vercel
Copy link

@vercel vercel bot commented on 1222580 Jan 5, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.