【问题标题】:Disabled reason for option in react-selectreact-select中选项的禁用原因
【发布时间】:2019-02-04 07:28:35
【问题描述】:

当我使用 react-select 时,有没有办法显示为什么一个选项被禁用? 选项对象中的 disabledReason 属性之类的东西?

【问题讨论】:

    标签: reactjs react-select


    【解决方案1】:

    假设您想在菜单中的禁用选项旁边显示原因,您可以覆盖选项的呈现方式,以包含原因的方式呈现。

    如何使用 react-select API 准确执行此操作取决于您使用的是 react-select 的 V1 还是 V2。

    V1 示例:https://github.com/JedWatson/react-select/blob/v1.x/examples/src/components/CustomComponents.js
    V2 文档:https://react-select.com/props#replacing-components

    【讨论】:

      【解决方案2】:

      一种可能的解决方案是

      1. 在 react-selection 组件上使用 react 的 SyntheticEvent onMouseEnter 来检查鼠标是否悬停。
      2. 检查 react-select 组件是否被禁用
      3. 如果 react-select 被禁用,显示工具提示

        In React, onMouseEnter or hover is not working as expected

        https://reactjs.org/docs/events.html#mouse-events

        tooltip div with ReactJS

      【讨论】:

        猜你喜欢
        • 2020-11-12
        • 2015-12-18
        • 1970-01-01
        • 1970-01-01
        • 2022-10-15
        • 2020-01-25
        • 2019-06-17
        • 2019-06-03
        • 1970-01-01
        相关资源
        最近更新 更多