React-tooltip: How to show a tooltip initially on page load until onMouseEnter?

Created on 11 Jan 2017  路  2Comments  路  Source: wwayne/react-tooltip

Basically I'm looking for a feature like this.

<ReactTooltip showInitial />

Any way to do this currently on page load?

Most helpful comment

Actually I just wrapped your library and added this feature for myself. If you're curious here's how I did it.

import React, { Component } from 'react'

import ReactTooltip from 'react-tooltip'



export default class Tooltip extends Component {

  componentDidMount () {
    if (this.props.showInitial) {
      this.showTooltip()
    }
  }

  showTooltip () {
    let tooltip = document.querySelectorAll(`[data-tip][data-for="${this.props.id}"]`)[0]
    ReactTooltip.show(tooltip)
  }

  render () {
    const { children, showInitial, ...props } = this.props
    if (!children) return null

    return (
      <ReactTooltip {...props}>
        {children}
      </ReactTooltip>
    )
  }
}

All 2 comments

Actually I just wrapped your library and added this feature for myself. If you're curious here's how I did it.

import React, { Component } from 'react'

import ReactTooltip from 'react-tooltip'



export default class Tooltip extends Component {

  componentDidMount () {
    if (this.props.showInitial) {
      this.showTooltip()
    }
  }

  showTooltip () {
    let tooltip = document.querySelectorAll(`[data-tip][data-for="${this.props.id}"]`)[0]
    ReactTooltip.show(tooltip)
  }

  render () {
    const { children, showInitial, ...props } = this.props
    if (!children) return null

    return (
      <ReactTooltip {...props}>
        {children}
      </ReactTooltip>
    )
  }
}

Actually I just wrapped your library and added this feature for myself. If you're curious here's how I did it.

import React, { Component } from 'react'

import ReactTooltip from 'react-tooltip'



export default class Tooltip extends Component {

  componentDidMount () {
    if (this.props.showInitial) {
      this.showTooltip()
    }
  }

  showTooltip () {
    let tooltip = document.querySelectorAll(`[data-tip][data-for="${this.props.id}"]`)[0]
    ReactTooltip.show(tooltip)
  }

  render () {
    const { children, showInitial, ...props } = this.props
    if (!children) return null

    return (
      <ReactTooltip {...props}>
        {children}
      </ReactTooltip>
    )
  }
}

Good Solution.!

Was this page helpful?
0 / 5 - 0 ratings