Skip to content

Commit 7f6b50f

Browse files
authored
Merge pull request #131 from pokidovea/lazy_content
Add possibility to recalculate content on show tooltip
2 parents 8bc4bfe + 5e058dd commit 7f6b50f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class ReactTooltip extends Component {
3737
eventOff: PropTypes.string,
3838
watchWindow: PropTypes.bool,
3939
isCapture: PropTypes.bool,
40-
globalEventOff: PropTypes.string
40+
globalEventOff: PropTypes.string,
41+
getContent: PropTypes.func
4142
}
4243

4344
constructor (props) {
@@ -165,10 +166,18 @@ class ReactTooltip extends Component {
165166
showTooltip (e) {
166167
// Get the tooltip content
167168
// calculate in this phrase so that tip width height can be detected
168-
const {children, multiline} = this.props
169+
const {children, multiline, getContent} = this.props
169170
const originTooltip = e.currentTarget.getAttribute('data-tip')
170171
const isMultiline = e.currentTarget.getAttribute('data-multiline') || multiline || false
171-
const placeholder = getTipContent(originTooltip, children, isMultiline)
172+
173+
let content
174+
if (children) {
175+
content = children
176+
} else if (getContent) {
177+
content = getContent()
178+
}
179+
180+
const placeholder = getTipContent(originTooltip, content, isMultiline)
172181

173182
this.setState({
174183
placeholder,

0 commit comments

Comments
 (0)