简体   繁体   English

单击 SpeedDialAction 按钮时,我可以阻止 Material-UI SpeedDial 关闭吗

[英]Can I stop Material-UI SpeedDial from closing when a SpeedDialAction button is clicked

I am wanting to disable the default behaviour of Material-UI's SpeedDial component ( https://material-ui.com/api/speed-dial/ ).我想禁用 Material-UI 的 SpeedDial 组件( https://material-ui.com/api/speed-dial/ )的默认行为。

Currently when you click a SpeedDialAction, the parent SpeedDial component will close.当前,当您单击 SpeedDialAction 时,父 SpeedDial 组件将关闭。

I would like to change the behaviour so that when a SpeedDialAction is clicked the parent SpeedDial component will stay open.我想更改行为,以便单击 SpeedDialAction 时,父 SpeedDial 组件将保持打开状态。

Is there a simple way for me to disable the 'closing' behaviour?有没有一种简单的方法可以禁用“关闭”行为?

Thanks!谢谢!

The SpeedDial component's open state is controlled via the prop open . SpeedDial组件的打开状态是通过 prop open控制的。 The default example for the SpeedDial has the following onClick function on the SpeedDialAction component: SpeedDial的默认示例在SpeedDialAction组件上具有以下onClick函数:

const handleClose = () => {
  setOpen(false);
}

setOpen sets the open state to false when an item is clicked, and this state is passed to the SpeedDial component causing it to close.当一个项目被点击时, setOpenopen状态设置为false ,并且这个状态被传递给SpeedDial组件,导致它关闭。

So, just don't set this state in the onClick , and your SpeedDial will remain open.因此,不要在onClick设置此状态,您的SpeedDial将保持打开状态。 :) :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 Material-UI SpeedDialAction onClick 事件在 SpeedDial 仅在单击时打开(不悬停)时触发 - How do I get Material-UI SpeedDialAction onClick events to fire when SpeedDial is open on click only (not hover) 我可以禁用Material-UI SpeedDial鼠标悬停事件 - Can I disable the Material-UI SpeedDial mouseover event 如何在菜单顶部添加标题和关闭按钮(在 material-ui 中单击时,在按钮菜单中的第一项上方? - How do I add a title and close button to the top of a menu (above the 1st item in a button menu when clicked in material-ui? 无法解析“材料界面/按钮” - Can't resolve 'material-ui/Button' 在Material-UI TextField中,当输入模糊时,如何防止标签落在装饰物后面? - In a Material-UI TextField how can I prevent a label from falling behind an adornment when the input is blurred? 如何使用 material-ui 图标中的图标? - How can I use Icons from material-ui icons? 单击复选框时如何停止关闭可折叠的手风琴 - How can I stop the accordion(collapsible) from closing when checkboxes are clicked 我可以取消选中 Datagrid Material-ui 中单击按钮上的选中复选框吗 - Can I Uncheck selected checkbox on a Button click in Datagrid Material-ui Material-UI Popover 关闭时按钮无法触发 - Material-UI Button cannot trigger when Popover close 如何导出具有 2 个样式对象的 react material-ui 组件? (材质-ui V1) - How can I export a react material-ui component with 2 styles object? (material-ui V1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM