簡體   English   中英

反應材料ui在左側增長

[英]react material ui grow on left side

如何使上下文菜單不在按鈕的中心打開,而是在按鈕的左側? 使用屬性材質 UI。

鏈接中的工作示例: https://codesandbox.io/s/2f33z

現在這個:

在此處輸入圖像描述

我要這個:

在此處輸入圖像描述

這是文檔中示例的鏈接: https://material-ui.com/components/menus/#menulist-composition

 <div> <Button ref={anchorRef} aria-controls={open? 'menu-list-grow': undefined} aria-haspopup="true" onClick={handleToggle} > Toggle Menu Grow </Button> <Popper open={open} anchorEl={anchorRef.current} role={undefined} transition disablePortal> {({ TransitionProps, placement }) => ( <Grow {...TransitionProps} style={{ transformOrigin: placement === 'bottom'? 'center top': 'center bottom' }} > <Paper> <ClickAwayListener onClickAway={handleClose}> <MenuList autoFocusItem={open} id="menu-list-grow" onKeyDown={handleListKeyDown}> <MenuItem onClick={handleClose}>Profile</MenuItem> <MenuItem onClick={handleClose}>My account</MenuItem> <MenuItem onClick={handleClose}>Logout</MenuItem> </MenuList> </ClickAwayListener> </Paper> </Grow> )} </Popper> </div>

你的Popper組件應該有一個值bottom-startplacement屬性:

// ...
<Popper
  placement="bottom-start"
  // ...
>
// ...

有關更多選項,請查看此處: https://material-ui.com/components/popper/#positioned-popper

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM