Skip to content

Commit ccb8b58

Browse files
committed
feat(overridePosition): Add "overridePosition" property to handle border cases and customize position
1 parent 34fa8cb commit ccb8b58

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ className | data-class | String | | extra custom class, can use !importan
7373
getContent | null | Func or Array | (dataTip) => {}, [(dataTip) => {}, Interval] | Generate the tip content dynamically
7474
afterShow | null | Func | (evt) => {} | Function that will be called after tooltip show, with event that triggered show
7575
afterHide | null | Func | (evt) => {} | Function that will be called after tooltip hide, with event that triggered hide
76+
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
7677
disable | data-tip-disable | Bool | true, false | Disable the tooltip behaviour, default is false
7778
scrollHide | data-scroll-hide | Bool | true, false | Hide the tooltip when scrolling, default is true
7879
resizeHide | null | Bool | true, false | Hide the tooltip when resizing the window, default is true

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ReactTooltip extends React.Component {
5353
getContent: PropTypes.any,
5454
afterShow: PropTypes.func,
5555
afterHide: PropTypes.func,
56+
overridePosition: PropTypes.func,
5657
disable: PropTypes.bool,
5758
scrollHide: PropTypes.bool,
5859
resizeHide: PropTypes.bool,
@@ -309,6 +310,10 @@ class ReactTooltip extends React.Component {
309310
let effect = switchToSolid && 'solid' || this.getEffect(e.currentTarget)
310311
let offset = e.currentTarget.getAttribute('data-offset') || this.props.offset || {}
311312
let result = getPosition(e, e.currentTarget, this.tooltipRef, desiredPlace, desiredPlace, effect, offset)
313+
if (result.position && this.props.overridePosition) {
314+
result.position = this.props.overridePosition(result.position, e.currentTarget, this.tooltipRef, desiredPlace, desiredPlace, effect, offset)
315+
}
316+
312317
let place = result.isNewState ? result.newState.place : desiredPlace
313318

314319
// To prevent previously created timers from triggering
@@ -480,7 +485,10 @@ class ReactTooltip extends React.Component {
480485
updatePosition () {
481486
const {currentEvent, currentTarget, place, desiredPlace, effect, offset} = this.state
482487
const node = this.tooltipRef
483-
const result = getPosition(currentEvent, currentTarget, node, place, desiredPlace, effect, offset)
488+
let result = getPosition(currentEvent, currentTarget, node, place, desiredPlace, effect, offset)
489+
if (result.position && this.props.overridePosition) {
490+
result.position = this.props.overridePosition(result.position, currentEvent, currentTarget, node, place, desiredPlace, effect, offset)
491+
}
484492

485493
if (result.isNewState) {
486494
// Switch to reverse placement

0 commit comments

Comments
 (0)