Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new attribute afterShow and afterHide #173

Merged
merged 1 commit into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ npm install react-tooltip
1 . Require react-tooltip after installation

```js
var ReactTooltip = require("react-tooltip")
import ReactTooltip from 'react-tooltip'
```

2 . Add data-tip = "your placeholder" to your element
Expand Down Expand Up @@ -63,6 +63,8 @@ class | data-class | String | | extra custom class, can use !important to
border | data-border | Bool | true, false | Add one pixel white border
getContent | null | Func or Array | () => {}, [() => {}, Interval] | Generate the tip content dynamically
countTransform | data-count-transform | Bool | True, False | Tell tooltip if it needs to count parents' transform into position calculation, the default is true, but it should be set to false when using with react-list
afterShow | null | Func | () => {} | Function that will be called after tooltip show
afterHide | null | Func | () => {} | Function that will be called after tooltip hide

## Using react component as tooltip
Check the example [React-tooltip Test](http://wwayne.com/react-tooltip)
Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ReactTooltip extends Component {
isCapture: PropTypes.bool,
globalEventOff: PropTypes.string,
getContent: PropTypes.any,
countTransform: PropTypes.bool
countTransform: PropTypes.bool,
afterShow: PropTypes.func,
afterHide: PropTypes.func
}

constructor (props) {
Expand Down Expand Up @@ -255,24 +257,27 @@ class ReactTooltip extends Component {
*/
updateTooltip (e) {
const {delayShow, show} = this.state
const {afterShow} = this.props
let {placeholder} = this.state
const delayTime = show ? 0 : parseInt(delayShow, 10)
const eventTarget = e.currentTarget

const updateState = () => {
if (typeof placeholder === 'string') placeholder = placeholder.trim()
if (Array.isArray(placeholder) && placeholder.length > 0 || placeholder) {
const isInvisible = !this.state.show
this.setState({
currentEvent: e,
currentTarget: eventTarget,
show: true
}, () => {
this.updatePosition()
if (isInvisible && afterShow) afterShow()
})
}
}

this.clearTimer()
clearTimeout(this.delayShowLoop)
if (delayShow) {
this.delayShowLoop = setTimeout(updateState, delayTime)
} else {
Expand All @@ -285,14 +290,18 @@ class ReactTooltip extends Component {
*/
hideTooltip () {
const {delayHide} = this.state
const {afterHide} = this.props

if (!this.mount) return

const resetState = () => {
const isVisible = this.state.show
this.setState({
show: false
}, () => {
this.removeScrollListener()
if (isVisible && afterHide) afterHide()
})
this.removeScrollListener()
}

this.clearTimer()
Expand Down