Replies: 1 comment 3 replies
-
I would suggest instead keeping the label as a string, and creating a custom Option component. This would allow you to render the tooltip while also having access to knowing whether the option is "focused" or not. First, react-select depends on the input having focus to know whether the select is active or not, so making the options buttons with the hope of using the focus/blur events won't work without completely rewiring the menuIsOpen logic, however, react-select does have a mechanism to keep track of what is the pseudo focused object. The issue with the library you are using is that there doesn't appear to be a way to programmatically tell import Select, { components } from 'react-select';
const Option = ({ innerProps, ...props }) => {
const { label, value, tooltipContent } = props.data;
const newInnerProps = {
...innerProps,
'data-for': value,
'data-tip': tooltipContent,
// data-event likely isn't needed as we are coercing the className of the tooltip class to show when react-select indicates that the option is focused.
'aria-label': 'option',
};
const classNames=`cb-select-tooltip ${props.isFocused ? 'show' : ''}`;
return (
<ReactTooltip id={value} className={classNames.tooltip} role="tooltip" type="info" place="right" effect="solid">
<components.Option {...props} innerProps={newInnerProps} className="select-option" />
</ReactTooltip>
)
}
const MySelect = props => {
...
return <Select components={{ Option }} {...otherProps} />
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all, I want to show the tooltip for each option of using react-tooltip, I have tried below code which is working fine to show tooltip on mouseover, but on keydown and keyup arrow it not works because the focus never come to inner child div, which I have created as below...
Here, I updating options with tooltip div
There is always a parent div creted,
my question is, can we have control on that outer div HTML, while modifying option.
Or please suggest if I'm following wrong approach.
Beta Was this translation helpful? Give feedback.
All reactions