简体   繁体   English

如何显示每个反应选择多值元素的工具提示?

[英]How to show tooltip for each react-select multiValue element?

I'm trying to reproduce the example of the Custom MultiValueContainer Example shown in the link, but nothing seems to work properly.我正在尝试重现链接中显示的自定义 MultiValueContainer 示例的示例,但似乎没有任何工作正常。 The element is inserted (can be found within the React Component dev-tool) but the tooltip is never shown when hovered.元素已插入(可以在 React 组件开发工具中找到),但悬停时永远不会显示工具提示。

The code I'm trying to run is shown here , but even the simple code given in the example does not seem to work, as shown here我尝试运行的代码显示在这里,但即使是示例中给出的简单代码似乎也不起作用,如此处所示

What I expect is something like the following:我期望的是如下所示: 链接的预期输出

Has anyone an idea what essential part I am overlooking?有谁知道我忽略了什么重要部分?

Thanks in advance!提前致谢!

By adding a <span> Element to the CustomMultiValue and changing the Tooltip-library to material-ui , solved the problem.通过将<span>元素添加到 CustomMultiValue 并将 Tooltip-library 更改为material-ui ,解决了该问题。

const CustomMultiValue = (props) => {
  return (
    <Tooltip title={"Here we could show the legend of the element"}>
      <span>
        <MultiValueContainer {...props} />
      </span>
    </Tooltip>
  );
};

If you want an individual tooltip per item you may do it like this:如果您希望每个项目有一个单独的工具提示,您可以这样做:

const CustomMultiValueLabel = props => {
    return (
        <MultiValueLabel {...props} >
        <div className={styles.tooltip}>
            {props.data.label}
            <span className={styles.tooltiptext}>This is the tooltip text for {props.data.label}</span>
        </div>
        </MultiValueLabel>
    );
};

<Select isMulti
        components={{MultiValueLabel: CustomMultiValueLabel}}
>

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

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