简体   繁体   English

React Popover 组件 - Material UI

[英]React Popover component - Material UI

I'm trying to make a color palette which functions like: when I hover over the PaletteIcon it should popover the color palette and I should be able to select the colors as desired.我正在尝试制作一个调色板,其功能如下:当我将鼠标悬停在PaletteIcon它应该会弹出调色板,我应该能够根据需要选择颜色。 But after hovering when I try to select the color, the palette disappears.但是当我尝试选择颜色时悬停后,调色板消失了。 Is there any property which I can add to paper React component or some other way to achieve this?是否有任何属性可以添加到纸质 React 组件或其他一些方法来实现这一点? I checked the Paper API documentation but didn't find any solution.我检查了Paper API 文档,但没有找到任何解决方案。

Here is the link for CodeSandbox .这是CodeSandbox的链接。

Popover is not rendered in the same tree as your Button, it is not a descendant of Button so therefore this logic would be very hard to implement out-of-the-box. Popover与您的 Button 不在同一棵树中呈现,它不是 Button 的后代,因此这种逻辑很难开箱即用。

You could remove onMouseLeave event and close the Popover once the color is selected.您可以删除onMouseLeave事件并在选择颜色后关闭 Popover。 Or you could just control the popover with clicking on the Button.或者您可以通过单击按钮来控制弹出窗口。

Or you could add your custom Popover as a child of Button element and therefore hover will remain on parent.或者您可以将自定义 Popover 添加为 Button 元素的子元素,因此悬停将保留在父元素上。

TL;DR: remove pointerEvents: "none" to listening to events from the popover content, remove your anchor's (Fab) onMouseLeave and control the popover when hovering ( onMouseEnter , onMouseLeave ) its content or the popover's backdrop. TL;DR:删除pointerEvents: "none"以从弹出框内容中监听事件,删除锚点 (Fab) onMouseLeave并在悬停( onMouseEnteronMouseLeave )其内容或弹出onMouseLeave背景时控制弹出onMouseEnter

NL;PR: I modified your Pastebin to reflect that change . NL;PR:我修改了你的 Pastebin 以反映这一 变化 Alternatively, you can opt for using a state management API ).或者,您可以选择使用状态管理 API )。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM