Refine mobile dropdown close behavior
This commit is contained in:
@@ -35,6 +35,7 @@ type BannerApiResponse = {
|
|||||||
|
|
||||||
const AUTOPLAY_MS = 3000;
|
const AUTOPLAY_MS = 3000;
|
||||||
const RESUME_AFTER_INTERACTION_MS = 8000;
|
const RESUME_AFTER_INTERACTION_MS = 8000;
|
||||||
|
const publicMenuOpenChangeEvent = "ark:public-menu-open-change";
|
||||||
|
|
||||||
function bannerLangParam(lang: Lang): string {
|
function bannerLangParam(lang: Lang): string {
|
||||||
return langQuery(lang).toLowerCase();
|
return langQuery(lang).toLowerCase();
|
||||||
@@ -62,6 +63,7 @@ export function FigmaBanner() {
|
|||||||
const scrollerRef = useRef<HTMLDivElement>(null);
|
const scrollerRef = useRef<HTMLDivElement>(null);
|
||||||
const [activeIndex, setActiveIndex] = useState(0);
|
const [activeIndex, setActiveIndex] = useState(0);
|
||||||
const [autoplayPaused, setAutoplayPaused] = useState(false);
|
const [autoplayPaused, setAutoplayPaused] = useState(false);
|
||||||
|
const [publicMenuOpen, setPublicMenuOpen] = useState(false);
|
||||||
const resumeTimerRef = useRef<number | null>(null);
|
const resumeTimerRef = useRef<number | null>(null);
|
||||||
const dragStateRef = useRef<{
|
const dragStateRef = useRef<{
|
||||||
pointerId: number;
|
pointerId: number;
|
||||||
@@ -115,6 +117,23 @@ export function FigmaBanner() {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handlePublicMenuOpenChange = (event: Event) => {
|
||||||
|
setPublicMenuOpen(Boolean((event as CustomEvent<boolean>).detail));
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener(
|
||||||
|
publicMenuOpenChangeEvent,
|
||||||
|
handlePublicMenuOpenChange,
|
||||||
|
);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(
|
||||||
|
publicMenuOpenChangeEvent,
|
||||||
|
handlePublicMenuOpenChange,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const scroller = scrollerRef.current;
|
const scroller = scrollerRef.current;
|
||||||
if (!scroller) return;
|
if (!scroller) return;
|
||||||
@@ -132,7 +151,7 @@ export function FigmaBanner() {
|
|||||||
}, [slides.length]);
|
}, [slides.length]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasMultiple || autoplayPaused) return;
|
if (!hasMultiple || autoplayPaused || publicMenuOpen) return;
|
||||||
const timer = window.setInterval(() => {
|
const timer = window.setInterval(() => {
|
||||||
setActiveIndex((prev) => {
|
setActiveIndex((prev) => {
|
||||||
const next = (prev + 1) % slides.length;
|
const next = (prev + 1) % slides.length;
|
||||||
@@ -141,7 +160,7 @@ export function FigmaBanner() {
|
|||||||
});
|
});
|
||||||
}, AUTOPLAY_MS);
|
}, AUTOPLAY_MS);
|
||||||
return () => window.clearInterval(timer);
|
return () => window.clearInterval(timer);
|
||||||
}, [hasMultiple, autoplayPaused, slides.length, goTo]);
|
}, [hasMultiple, autoplayPaused, publicMenuOpen, slides.length, goTo]);
|
||||||
|
|
||||||
const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
|
const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
|
||||||
if (event.pointerType !== "mouse") return;
|
if (event.pointerType !== "mouse") return;
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ function navClassName(active: boolean) {
|
|||||||
const dropdownAnimationClass =
|
const dropdownAnimationClass =
|
||||||
"animate__animated animate__fadeInDown ark-dropdown-enter";
|
"animate__animated animate__fadeInDown ark-dropdown-enter";
|
||||||
|
|
||||||
|
const publicMenuOpenChangeEvent = "ark:public-menu-open-change";
|
||||||
|
|
||||||
type LanguageDropdownProps = {
|
type LanguageDropdownProps = {
|
||||||
lang: Lang;
|
lang: Lang;
|
||||||
setLang: (lang: Lang) => void;
|
setLang: (lang: Lang) => void;
|
||||||
@@ -294,6 +296,12 @@ export function PublicLayout() {
|
|||||||
setMobileSearchOpen(false);
|
setMobileSearchOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent<boolean>(publicMenuOpenChangeEvent, { detail: open }),
|
||||||
|
);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
|
|
||||||
@@ -312,11 +320,11 @@ export function PublicLayout() {
|
|||||||
|
|
||||||
document.addEventListener("mousedown", closeOnOutside);
|
document.addEventListener("mousedown", closeOnOutside);
|
||||||
document.addEventListener("touchstart", closeOnOutside);
|
document.addEventListener("touchstart", closeOnOutside);
|
||||||
window.addEventListener("scroll", closeOnScroll, true);
|
window.addEventListener("scroll", closeOnScroll);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener("mousedown", closeOnOutside);
|
document.removeEventListener("mousedown", closeOnOutside);
|
||||||
document.removeEventListener("touchstart", closeOnOutside);
|
document.removeEventListener("touchstart", closeOnOutside);
|
||||||
window.removeEventListener("scroll", closeOnScroll, true);
|
window.removeEventListener("scroll", closeOnScroll);
|
||||||
};
|
};
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user