All Projects → wwayne → React Tooltip

wwayne / React Tooltip

Licence: mit
react tooltip component

Programming Languages

javascript
184084 projects - #8 most used programming language
SCSS
7915 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to React Tooltip

Reactjs Popup
React Popup Component - Modals,Tooltips and Menus —  All in one
Stars: ✭ 1,211 (-53.53%)
Mutual labels:  tooltip
Redux Tooltip
A tooltip React component for Redux.
Stars: ✭ 134 (-94.86%)
Mutual labels:  tooltip
Vue Ui For Pc
基于Vue2.x的一套PC端UI组件,包括了Carousel 跑马灯、Cascader 级联、Checkbox 多选框、Collapse 折叠面板、DatePicker 日期选择、Dialog 对话框、Form 表单、Input 输入框、InputNumber 数字输入框、Layer 弹窗层、Loading 加载、Menu 菜单、Page 分页、Progress 进度条、Radio 单选框、SelectDropDown 仿select、Switch 开关、Table 表格、Tabs 标签页、Textarea 文本框、Tooltip 文字提示、BackTop 返回顶部、steps 步骤条、Transfer 穿梭框、Tree 树形、Upload 文件上传、Lazy 图片懒加载、Loading 加载、Pagination 分页等等
Stars: ✭ 156 (-94.01%)
Mutual labels:  tooltip
Cooltipz.css
A modern, highly customisable, minimal, pure CSS tooltip library
Stars: ✭ 81 (-96.89%)
Mutual labels:  tooltip
Hibiscus.js
Native Angular directives for Bootstrap4
Stars: ✭ 115 (-95.59%)
Mutual labels:  tooltip
React Popper Tooltip
A React hook to effortlessly build smart tooltips.
Stars: ✭ 149 (-94.28%)
Mutual labels:  tooltip
Tippyjs
Tooltip, popover, dropdown, and menu library
Stars: ✭ 9,433 (+261.97%)
Mutual labels:  tooltip
React Popper
🍿⚛Official React library to use Popper, the positioning library
Stars: ✭ 2,173 (-16.62%)
Mutual labels:  tooltip
Sexytooltip
The tooltip that has all the right moves
Stars: ✭ 125 (-95.2%)
Mutual labels:  tooltip
V Tooltip
💬 Easy tooltips, popovers, dropdown for Vue
Stars: ✭ 2,109 (-19.07%)
Mutual labels:  tooltip
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (-52%)
Mutual labels:  tooltip
Bubb
Euphemism for a JS tooltip
Stars: ✭ 101 (-96.12%)
Mutual labels:  tooltip
Resharper.enhancedtooltip
A plugin for JetBrains Resharper that colorizes the tooltip and parameter information.
Stars: ✭ 151 (-94.21%)
Mutual labels:  tooltip
Android Target Tooltip
Create Toast like tooltips, but targets can be specified, plus custom properties and features
Stars: ✭ 1,221 (-53.15%)
Mutual labels:  tooltip
Popover
Angular CDK Popover, no default style, examples using @angular/material
Stars: ✭ 156 (-94.01%)
Mutual labels:  tooltip
Toolgif
💭 The only GIF tooltip plugin you need
Stars: ✭ 75 (-97.12%)
Mutual labels:  tooltip
Balloon
🎈 Modernized and sophisticated tooltips, fully customizable with an arrow and animations on Android.
Stars: ✭ 2,242 (-13.97%)
Mutual labels:  tooltip
Ngx Popper
An angular wrapper for popper.js, great for tooltips and positioning popping elements
Stars: ✭ 183 (-92.98%)
Mutual labels:  tooltip
Vue Directive Tooltip
Vue.js tooltip directive. Easy to use, configure and style
Stars: ✭ 158 (-93.94%)
Mutual labels:  tooltip
React Layer Stack
Layering system for React. Useful for popover/modals/tooltip/dnd application
Stars: ✭ 152 (-94.17%)
Mutual labels:  tooltip

react-tooltip

Version code style: prettier npm download Build Status semantic-release

Demo

Edit ReactTooltip

Or see it on Github Page.

Maintainers

aronhelser Passive maintainer - accepting PRs and doing minor testing, but not fixing issues or doing active development.

roggervalf Active maintainer - accepting PRs and doing minor testing, fixing issues or doing active development.

huumanoid (inactive)

We would gladly accept a new maintainer to help out!

Installation

npm install react-tooltip

or

yarn add react-tooltip

Usage

Using NPM

1 . Require react-tooltip after installation

import ReactTooltip from 'react-tooltip';

2 . Add data-tip = "your placeholder" to your element

<p data-tip="hello world">Tooltip</p>

3 . Include react-tooltip component

<ReactTooltip />

Standalone

You can import node_modules/react-tooltip/dist/index.js into your page. Please make sure that you have already imported react and react-dom into your page.

Options

Notes:

  • The tooltip sets type: dark place: top effect: float as default attributes. You don't have to add these options if you don't want to change the defaults
  • The option you set on <ReactTooltip /> component will be implemented on every tooltip in a same page: <ReactTooltip effect="solid" />
  • The option you set on a specific element, for example: <a data-type="warning"></a> will only affect this specific tooltip
Global Specific Type Values Description
place data-place String top, right, bottom, left placement
type data-type String dark, success, warning, error, info, light theme
effect data-effect String float, solid behaviour of tooltip
event data-event String e.g. click custom event to trigger tooltip
eventOff data-event-off String e.g. click custom event to hide tooltip (only makes effect after setting event attribute)
globalEventOff String e.g. click global event to hide tooltip (global only)
isCapture data-iscapture Bool true, false when set to true, custom event's propagation mode will be capture
offset data-offset Object top, right, bottom, left data-offset="{'top': 10, 'left': 10}" for specific and offset={{top: 10, left: 10}} for global
padding data-padding String e.g. 8px 21px Popup padding style
multiline data-multiline Bool true, false support <br>, <br /> to make multiline
className data-class String extra custom class, can use !important to overwrite react-tooltip's default class
html data-html Bool true, false <p data-tip="<p>HTML tooltip</p>" data-html={true}></p> or <ReactTooltip html={true} />, but see Security Note below.
When using JSX, see this note below.
delayHide data-delay-hide Number <p data-tip="tooltip" data-delay-hide='1000'></p> or <ReactTooltip delayHide={1000} />
delayShow data-delay-show Number <p data-tip="tooltip" data-delay-show='1000'></p> or <ReactTooltip delayShow={1000} />
delayUpdate data-delay-update Number <p data-tip="tooltip" data-delay-update='1000'></p> or <ReactTooltip delayUpdate={1000} /> Sets a delay in calling getContent if the tooltip is already shown and you mouse over another target
insecure null Bool true, false Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default)
border data-border Bool true, false Add one pixel white border
textColor data-text-color String e.g. red Popup text color
backgroundColor data-background-color String e.g. yellow Popup background color
borderColor data-border-color String e.g. green Popup border color - enabled by the border value
arrowColor data-arrow-color String e.g. #fff Popup arrow color - if not specified, will use the backgroundColor value
getContent null Func or Array (dataTip) => {}, [(dataTip) => {}, Interval] Generate the tip content dynamically
afterShow null Func (evt) => {} Function that will be called after tooltip show, with event that triggered show
afterHide null Func (evt) => {} Function that will be called after tooltip hide, with event that triggered hide
overridePosition null Func ({left:number, top: number}, currentEvent, currentTarget, node, place, desiredPlace, effect, offset) => ({left: number, top: number}) Function that will replace tooltip position with custom one
disable data-tip-disable Bool true, false Disable the tooltip behaviour, default is false
scrollHide data-scroll-hide Bool true, false Hide the tooltip when scrolling, default is true
resizeHide null Bool true, false Hide the tooltip when resizing the window, default is true
wrapper null String div, span Selecting the wrapper element of the react tooltip, default is div
clickable null Bool true, false Enables tooltip to respond to mouse (or touch) events, default is false

Security Note

The html option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user. Any user-supplied content must be sanitized, using a package like sanitize-html. We chose not to include sanitization after discovering it increased our package size too much - we don't want to penalize people who don't use the html option.

JSX Note

You can use React's renderToStaticMarkup-function to use JSX instead of HTML. You still need to set data-html={true}. Example:

import ReactDOMServer from 'react-dom/server';
[...]
<p data-html={true} data-tip={ReactDOMServer.renderToString(<div>I am <b>JSX</b> content</div>)}>
  Hover me
</p>

Note

  1. data-tip is necessary, because <ReactTooltip /> finds the tooltip via this attribute
  2. data-for corresponds to the id of <ReactTooltip />
  3. When using react component as tooltip, you can have many <ReactTooltip /> in a page but they should have different ids

Static Methods

ReactTooltip.hide(target)

Hide the tooltip manually, the target is optional, if no target passed in, all existing tooltips will be hidden

import ReactTooltip from 'react-tooltip'

<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
<button onClick={() => { ReactTooltip.hide(this.fooRef) }}></button>
<ReactTooltip />

ReactTooltip.rebuild()

Rebinding all tooltips

ReactTooltip.show(target)

Show specific tooltip manually, for example:

import ReactTooltip from 'react-tooltip'

<p ref={ref => this.fooRef = ref} data-tip='tooltip'></p>
<button onClick={() => { ReactTooltip.show(this.fooRef) }}></button>
<ReactTooltip />

Troubleshooting

1. Using tooltip within the modal (e.g. react-modal)

The component was designed to set <ReactTooltip /> once and then use tooltip everywhere, but a lot of people get stuck when using this component in a modal. You can read the discussion here. To solve this problem:

  1. Place <ReactTooltip /> outside of the <Modal>
  2. Use ReactTooltip.rebuild() when opening the modal
  3. If your modal's z-index happens to be higher than the tooltip's, use the attribute className to custom your tooltip's z-index

I suggest always putting <ReactTooltip /> in the Highest level or smart component of Redux, so you might need these static method to control tooltip's behaviour in some situations

2. Hide tooltip when getContent returns undefined

When you set getContent={() => { return }} you will find the tooltip will display true. That's because React will set the value of data-* to be 'true' automatically if there is no value to be set. So you have to set data-tip='' in this situation.

<p data-tip='' data-for='test'></p>
<ReactTooltip id='test' getContent={() => { return null }}/>

Same for empty children, if you don't want show the tooltip when the children is empty

<p data-tip='' data-for='test'></p>
<ReactTooltip id='test'>{}</ReactTooltip>

3. Tooltip not binding to dynamic content

When you render <ReactTooltip> ahead of dynamic content, and are using data-for={id} attributes on new dynamic content, the tooltip will not register its event listener.

For example, you render a generic tooltip in the root of your app, then load a list of content async. Elements in the list use the data-for={id} attribute to bind the tooltip on hover. Since the tooltip has already scanned for data-tip these new elements will not trigger.

One workaround for this is to trigger ReactTooltip.rebuild() after the data load to scan for the attribute again, to allow event wireup.

Example

<app>
  <ReactTooltip id="foo" />
  <list/>
</app>
const dynamicList = (props) => {

 useEffect(() => {
        ReactTooltip.rebuild();
    });

return(
  <list>
    {data.map((item)=> {
      <span data-for="foo">My late bound tooltip triggered data</span>
    });}
  </list>
);
};

Article

How I insert sass into react component

Contributing

We welcome your contribution! Fork the repo, make some changes, submit a pull-request! Our contributing doc has some details.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].