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

React中如何将isMobile变量传入Drawer组件的size="full"属性

解决方案

你可以通过动态绑定size属性,根据isMobile的值来控制Drawer的显示尺寸:

const isMobile = useMediaQuery('(max-width:992px)');

// 根据移动端状态切换Drawer尺寸
<Drawer size={isMobile ? 'full' : 'md'}>
  {/* Drawer内部内容 */}
</Drawer>

补充说明

  • 当isMobile为true(屏幕宽度≤992px)时,Drawer会启用size="full"实现全屏;
  • 非移动端场景下,你可以把'md'替换为Rsuite支持的其他尺寸值,比如'lg'(大尺寸)、'sm'(小尺寸),或者保留组件默认的尺寸逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 12:00:58