简体   繁体   English

我可以禁用Material-UI SpeedDial鼠标悬停事件

[英]Can I disable the Material-UI SpeedDial mouseover event

I am wanting to disable the default mouseover/hover 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 mouseover the primary icon, the SpeedDial component will open. 当前,当您将鼠标悬停在主要图标上时,SpeedDial组件将打开。 It will also open on click. 单击它也将打开。 This has caused issues with some of our users as when they mouse over the button - it opens - and they immediately click and it closes. 当某些用户将鼠标悬停在按钮上时,它引起了问题-它打开-然后他们立即单击并关闭。

I would like to keep the just the click action for opening the SpeedDial for touch screen devices. 我想保留单击操作,以打开触摸屏设备的SpeedDial。

Is there a simple way for me to disable the hover/mouseover event? 我有一种简单的方法来禁用悬停/鼠标悬停事件吗? As far as I can tell the API does not allow this. 据我所知,API不允许这样做。

Thanks! 谢谢!

This behaviour can be achieved by ignoring onOpen prop and control the component with onClick prop. 可以通过忽略onOpen并使用onClick onOpen控制组件来实现此行为。

// Component code

const [open, setOpen] = React.useState(false);

const handleOpen = (event) => {
  setOpen(!open);
};

return (
   <SpeedDial
      onClick={handleOpen}
      open={open}
      ...
   />
);

You can see a working example here: https://codesandbox.io/s/material-demo-1lwci 您可以在这里看到一个有效的示例: https : //codesandbox.io/s/material-demo-1lwci

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

相关问题 单击 SpeedDialAction 按钮时,我可以阻止 Material-UI SpeedDial 关闭吗 - Can I stop Material-UI SpeedDial from closing when a SpeedDialAction button is clicked 如何让 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) 如何在类型编号的 html 输入上禁用键盘输入? 反应或 material-ui 怎么样? - How can I disable keyboard input on an html input of type number? What about in react or material-ui? 如何在不删除自动完成中的选择的情况下禁用 Material-UI 中的下划线? - How can I disable underline in Material-UI without removing the selection in Autocomplete? 如何导出具有 2 个样式对象的 react material-ui 组件? (材质-ui V1) - How can I export a react material-ui component with 2 styles object? (material-ui V1) 禁用所有Material-UI组件的拼写检查 - Disable spellcheck on all material-ui components 是否可以禁用一个<menuitem>在 material-ui 中?</menuitem> - Is it possible to disable a <MenuItem> in material-ui? 我无法在 Material-UI 中编辑文本字段 - I can't edit Text Field in Material-UI 如何使用 material-ui 图标中的图标? - How can I use Icons from material-ui icons? 我如何使用导出导出material -ui组件 - How can I export a react material-ui component with
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM