npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-bootstrap-tooltip-button2

v1.1.23

Published

React-Bootstrap button with Tooltip when disabled, updated for 2021 - originally by Dennis Bemmann

Downloads

79

Readme

react-bootstrap-tooltip-button2

Largely rewritten, but originally made by pastaclub

React component allowing you to place a tooltip on a button when the button is disabled. This can be helpful for example to inform the user of the reason why a button is disabled.

It is usually not possible to put a tooltip on a disabled button, because browser behavior is defined in such a way that disabled elements don't throw the events needed to trigger the tooltip. A widely suggested work-around is to place the disabled button in a <div> and have the div trigger the tooltip. This however breaks Bootstrap's styling in many cases (in order to display corners and margins correctly, Bootstrap relies on buttons being direct children of button toolbars or button groups or direct siblings of other buttons). This component brings custom CSS to build on Bootstrap's and fix all those issues, so the component behaves really just like you would expect a bootstrap button to behave.

Installing

npm install react-bootstrap-tooltip-button2

How to use

import TooltipButton from 'react-bootstrap-tooltip-button2';

In your render function:

<TooltipButton
  title='Button Text'
  onClick={handleClick}
  disabled={true}
  tooltipText='You need to be logged in to use this button'
  tooltipId='tt1'
/>

Props

  • className: is used for the div surrounding the button, this should be used for classes you would apply for normal buttons
  • buttonClass: in case you want to apply styling specifically on the button you can use this prop
  • disabled: if true, renders a disabled button, otherwise a regular button
  • title: the text to appear on the button
  • tooltipText: the text to appear in the tooltip
  • tooltipId: an ID for the tooltip element. This is needed for screen readers and other accessibility tools
  • tooltipPlacement: specifies where to put the tooltip, relative to the button. Can be top, bottom, left or right, default is bottom
  • renderedButton: use this prop if you DON'T want react-bootstrap-tooltip-button to render a button for you and you prefer to render the button yourself and pass it as a prop. See example in the next section
  • You can apply any other props that you would apply to a react-bootstrap button and they will be passed on to the button. Some examples:
    • onClick
    • bsStyle
    • ...

Providing your own pre-rendered button

In some cases you may want to render your own button and not have it rendered by react-bootstrap-tooltip-button. That would typically be the case when you need more flexibility in customizing the button, such as adding a glyphicon or a dropdown. This is also possible with react-bootstrap-tooltip-button by using the prop renderedButton:

<TooltipButton
  disabled={isDisabled}
  tooltipText='You need to be logged in to use this button'
  tooltipId='tt1'
  renderedButton={(
    <DropdownButton bsStyle="link" title="Button Text" id="my-dropdown" disabled={(isDisabled)}>
      <MenuItem>Menu item 1</MenuItem>
      <MenuItem>Menu item 2</MenuItem>
    </DropdownButton>
  )}
/>

Note that if you provide a pre-rendered button, it is your responsibility to correctly set the disabled prop also on that button, since react-bootstrap-tooltip-button can only do it on buttons it renders itself.

Development

If you want to fork and improve this component

  • Clone this repo and run npm install
  • npm run compile will compile JSX/ES6 into ES5 and SASS into CSS