简体   繁体   English

将工具提示添加到禁用的Dropdown.Toggle

[英]Adding tooltip to disabled Dropdown.Toggle

If Dropdown.Toggle is not disabled tooltip works. 如果未禁用Dropdown.Toggle则工具提示会起作用。 When Dropdown.Toggle has the class Dropdown.Toggle具有类时

.disabled {
     pointer-events: none;
}.

Tooltip does not work. 工具提示不起作用。 I'm using the library: react-bootstrap and react-tooltip . 我正在使用库: react-bootstrapreact-tooltip

Example: https://stackblitz.com/edit/react-tnh9rr 示例: https//stackblitz.com/edit/react-tnh9rr

class App extends Component {
  constructor() {
    super();
    this.state = {
      disabled: true
    };
  }

  render() {
    return (
      <Dropdown className = {`${this.state.disabled  ? 'disabled' :     null}`} onClick={this.checkStatus}>
        <Dropdown.Toggle  data-tip="hello world" variant="success" id="dropdown-basic">
            Change status
        <ReactTooltip/>
        </Dropdown.Toggle>
        <Dropdown.Menu >
            <Dropdown.Item>AAAAAAA</Dropdown.Item>
        </Dropdown.Menu>
      </Dropdown>
    );
  }
}

CSS 的CSS

.disabled {
    pointer-events: none; 
}

You can directly check the state property( disabled ) when the particular function is called with onClick event on Dropdown component. Dropdown组件上使用onClick事件调用特定函数时,可以直接检查状态属性( disabled )。 pointer-events: none disables all the mouse events and hence we are unable to see the tooltip as tooltip mostly gets triggered when you hover it on the button and since hover is also a kind of event in mouse no event is triggered . pointer-events: none会禁用所有鼠标事件,因此,我们无法看到tooltip因为当您将hoverbutton上时,工具提示通常会被触发,并且由于hover也是hover中的一种事件,因此不会触发任何事件。

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

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