Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proper tooltip for long Options of Select in Ant Design (Antd)

We have Select components of different props (tag/no tags, with/without scrollbars), now I want to add a tooltip to the right of the options, but I can not use Tooltip to wrap around Option which will cause errors. And when tags mode is on, the Tooltip will hover over the 'check' icon.

This is the best I can do without using fixed width of content divs. https://codesandbox.io/s/busy-shirley-ss1or?

In my application I can use a boolean isTag to decide is tag mode is on and increment the width of content div, but I can not know whether the scrollbar is applied. I tried to get the ref of the dropdown menu or option div but failed.

We don't want to use 'title' because tooltip looks way better. We don't want to use 'dropdownMatchSelectWidth' because some options could be super long.

like image 236
xinli Avatar asked Oct 14 '25 15:10

xinli


1 Answers

Just wrap the value of the Option element in a Tooltip element, like this:

<Option value={value} key={key}>
  <Tooltip title="tooltip">
    {option}
  </Tooltip>
</Option>
like image 86
Pedro Madrid Avatar answered Oct 17 '25 05:10

Pedro Madrid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!