File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ import styles from './styles.module.scss';
6
6
const MobileSideBarMenu = ( { sidebar, menu} ) => {
7
7
const [ currentMenuState , setMenuState ] = useState ( false ) ;
8
8
9
+ // Define the breakpoint where mobile menu should be hidden (laptop breakpoint)
10
+ const LAPTOP_BREAKPOINT = 1330 ;
11
+
9
12
// Prevent body scroll when menu is open
10
13
useEffect ( ( ) => {
11
14
if ( currentMenuState ) {
@@ -29,6 +32,26 @@ const MobileSideBarMenu = ({sidebar, menu}) => {
29
32
}
30
33
} , [ currentMenuState ] ) ;
31
34
35
+ // Close mobile menu when viewport exceeds mobile breakpoint
36
+ useEffect ( ( ) => {
37
+ const handleResize = ( ) => {
38
+ if ( window . innerWidth >= LAPTOP_BREAKPOINT && currentMenuState ) {
39
+ setMenuState ( false ) ;
40
+ }
41
+ } ;
42
+
43
+ // Add event listener
44
+ window . addEventListener ( 'resize' , handleResize ) ;
45
+
46
+ // Also check on mount in case the component mounts with a large viewport
47
+ handleResize ( ) ;
48
+
49
+ // Cleanup
50
+ return ( ) => {
51
+ window . removeEventListener ( 'resize' , handleResize ) ;
52
+ } ;
53
+ } , [ currentMenuState , LAPTOP_BREAKPOINT ] ) ;
54
+
32
55
// Function to handle menu close
33
56
const handleMenuClose = ( ) => {
34
57
setMenuState ( false ) ;
Original file line number Diff line number Diff line change 1
1
$mobile-breakpoint : 996px ;
2
2
$tablet-breakpoint : 1024px ;
3
3
$laptop-breakpoint : 1330px ;
4
- $large-desktop-breakpoint : 1440px ;
4
+ $large-desktop-breakpoint : 1440px ;
5
+
6
+ // If you change these breakpoints, make sure to update
7
+ // MobileSideBarMenu/index.js accordingly
You can’t perform that action at this time.
0 commit comments