react-bootstrap: Overlay trigger does not trigger when child button is disabled
An overlay trigger that wraps a button with a prop of disabled will not show overlay on hover. Not sure if this is considered a bug or a feature. In my specific case I’d like to disable a button and then give the reason on hover.
Displays overlay:
<OverlayTrigger
overlay={<Tooltip>Some overlay</Tooltip>}>
<Button>Some button</Button>
</OverlayTrigger>
Does not display overlay:
<OverlayTrigger
overlay={<Tooltip>Some overlay</Tooltip>}>
<Button disabled>Some button</Button>
</OverlayTrigger>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 10
- Comments: 15 (2 by maintainers)
Yeah mouse events don’t fire on disabled elements (browser behavior), so
hoveris going to fail there. Instead wrap your button in a span or other inline element. See also this note about it here: http://getbootstrap.com/javascript/#tooltipsThis thread pointed me in the right direction to get this working for my use case. JSBin here: http://jsbin.com/midixo/edit in case its of use to anyone.
Indeed, can confirm that :
pointer-events: all;does not work anymoredivprovided by @simarsenault worksIt seems something has changed in the newer versions that broke the old trick. @simarsenault’s suggested workaround does the job (thanks for that by the way!), but is definitely far from optimal. Until someone finds a better alternative perhaps it is best to reopen the issue, WDYT?
For my fellow Googlers: I wasn’t able to make it work with either wrapping the
buttoninside aspan/divor the CSSpointer-events: all;. However, I made it work by creating adivwithposition: absoluteabove the button:Here’s a component that does the work-around: react-bootstrap-tooltip-button
Wrapping a button in a
<div>breaks the bootstrap styling for ButtonGroup and ButtonToolbar because those rules expect a button, not a div. This component fixes that as well.This can also be solved with CSS:
pointer-events: all;This seems a little cleaner than polluting your markup?Find the solution here in the official doc: https://react-bootstrap.github.io/components/overlays/#disabled-elements