You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React中嵌套两个AppBar组件时的Drawer z-index层级问题求助

解决MUI主AppBar被Drawer覆盖的z-index问题

问题场景

使用MUI的mini-variant drawer方案实现双AppBar布局(顶部主头部、底部带Drawer的AppBar),但主头部左上角区域被Drawer覆盖,显示空白。

问题原因

  • permanent类型的Drawer其Paper组件默认采用固定定位(fixed),z-index为theme.zIndex.drawer(默认值1200)
  • 顶部主AppBar为静态定位(static),默认z-index为auto,层级低于Drawer,因此被覆盖

解决方案

给顶部主AppBar设置更高的z-index,确保其层级高于Drawer及附带Drawer的AppBar:

修改代码

找到主AppBar的代码块,添加sx属性设置z-index:

<MuiAppBar position="static" sx={{ zIndex: theme.zIndex.drawer + 2 }}>
  <Toolbar variant="dense">
    <IconButton
      size="large"
      edge="start"
      color="inherit"
      aria-label="menu"
      sx={{ mr: 2 }}
    >
      <MenuIcon />
    </IconButton>
    <Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
      News
    </Typography>
  </Toolbar>
</MuiAppBar>

说明

  • theme.zIndex.drawer + 2既保证了主AppBar层级高于Drawer(1200),也高于你给附带Drawer的AppBar设置的theme.zIndex.drawer +1
  • 若不需要考虑附带Drawer的AppBar层级,直接设置zIndex: 1201也可生效

效果验证

修改后主AppBar的层级将高于Drawer,左上角的菜单按钮与标题会正常显示,不再被覆盖。

内容的提问来源于stack exchange,提问作者arunmmanoharan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 13:57:01