Skip to content

Commit abd2c9c

Browse files
Navigation: Hide docked menu and dock button on mobile (#76334)
* hide docked menu and dock button on mobile * add logic to handle hamburger menu button on mobile
1 parent 58ba11e commit abd2c9c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

public/app/core/components/AppChrome/AppChrome.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import classNames from 'classnames';
33
import React, { PropsWithChildren } from 'react';
44

55
import { GrafanaTheme2, PageLayoutType } from '@grafana/data';
6-
import { useStyles2, LinkButton } from '@grafana/ui';
6+
import { useStyles2, LinkButton, useTheme2 } from '@grafana/ui';
77
import config from 'app/core/config';
88
import { useGrafana } from 'app/core/context/GrafanaContext';
99
import { CommandPalette } from 'app/features/commandPalette/CommandPalette';
@@ -23,6 +23,7 @@ export function AppChrome({ children }: Props) {
2323
const { chrome } = useGrafana();
2424
const state = chrome.useState();
2525
const searchBarHidden = state.searchBarHidden || state.kioskMode === KioskMode.TV;
26+
const theme = useTheme2();
2627
const styles = useStyles2(getStyles);
2728

2829
const contentClass = cx({
@@ -31,6 +32,23 @@ export function AppChrome({ children }: Props) {
3132
[styles.contentChromeless]: state.chromeless,
3233
});
3334

35+
const handleMegaMenu = () => {
36+
switch (state.megaMenu) {
37+
case 'closed':
38+
chrome.setMegaMenu('open');
39+
break;
40+
case 'open':
41+
chrome.setMegaMenu('closed');
42+
break;
43+
case 'docked':
44+
// on desktop, clicking the button when the menu is docked should close the menu
45+
// on mobile, the docked menu is hidden, so clicking the button should open the menu
46+
const isDesktop = window.innerWidth > theme.breakpoints.values.md;
47+
isDesktop ? chrome.setMegaMenu('closed') : chrome.setMegaMenu('open');
48+
break;
49+
}
50+
};
51+
3452
// Chromeless routes are without topNav, mega menu, search & command palette
3553
// We check chromeless twice here instead of having a separate path so {children}
3654
// doesn't get re-mounted when chromeless goes from true to false.
@@ -54,7 +72,7 @@ export function AppChrome({ children }: Props) {
5472
pageNav={state.pageNav}
5573
actions={state.actions}
5674
onToggleSearchBar={chrome.onToggleSearchBar}
57-
onToggleMegaMenu={() => chrome.setMegaMenu(state.megaMenu === 'closed' ? 'open' : 'closed')}
75+
onToggleMegaMenu={handleMegaMenu}
5876
onToggleKioskMode={chrome.onToggleKioskMode}
5977
/>
6078
</div>
@@ -110,7 +128,12 @@ const getStyles = (theme: GrafanaTheme2) => {
110128
background: theme.colors.background.primary,
111129
borderRight: `1px solid ${theme.colors.border.weak}`,
112130
borderTop: `1px solid ${theme.colors.border.weak}`,
131+
display: 'none',
113132
zIndex: theme.zIndex.navbarFixed,
133+
134+
[theme.breakpoints.up('md')]: {
135+
display: 'block',
136+
},
114137
}),
115138
topNav: css({
116139
display: 'flex',

public/app/core/components/AppChrome/DockedMegaMenu/MegaMenu.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ const getStyles = (theme: GrafanaTheme2) => ({
116116
},
117117
}),
118118
dockMenuButton: css({
119+
display: 'none',
119120
marginRight: theme.spacing(2),
121+
122+
[theme.breakpoints.up('md')]: {
123+
display: 'inline-flex',
124+
},
120125
}),
121126
});

0 commit comments

Comments
 (0)