From a0ba2147e016a51fce1fbdef2cf1ab8069f73f00 Mon Sep 17 00:00:00 2001 From: Leonid Chelakhov Date: Thu, 28 Nov 2024 17:46:31 +0300 Subject: [PATCH] Changed burger menu context --- FrontEnd/src/context/BurgerMenuContext.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/FrontEnd/src/context/BurgerMenuContext.js b/FrontEnd/src/context/BurgerMenuContext.js index 06041132a..04e49de7c 100644 --- a/FrontEnd/src/context/BurgerMenuContext.js +++ b/FrontEnd/src/context/BurgerMenuContext.js @@ -1,4 +1,4 @@ -import React, { createContext, useState, useContext } from 'react'; +import React, { createContext, useState, useContext, useEffect } from 'react'; import PropTypes from 'prop-types'; const BurgerMenuContext = createContext(); @@ -8,6 +8,20 @@ export const BurgerMenuProvider = ({ children }) => { const toggleMenu = () => setIsOpen((prev) => !prev); + useEffect(() => { + const handleResize = () => { + if (window.innerWidth > 1200 && isOpen) { + setIsOpen(false); + } + }; + + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, [isOpen]); + return ( {children}