Skip to content

Commit

Permalink
feat(parent_body_mode): ReactTooltip#535 search parents for data-tip …
Browse files Browse the repository at this point in the history
…if in body mode
  • Loading branch information
vanmeegen committed Apr 27, 2022
1 parent 2a36416 commit 71da348
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/decorators/bodyMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ const bodyListener = function(callback, options, e) {
const { respectEffect = false, customEvent = false } = options;
const { id } = this.props;

const tip = e.target.getAttribute('data-tip') || null;
const forId = e.target.getAttribute('data-for') || null;
let tip = null;
let forId;
let target = e.target;
let lastTarget;
// walk up parent chain until tip is found
// there is no match if parent visible area is matched by mouse position, so some corner cases might not work as expected
while (tip === null && target !== null) {
lastTarget = target;
tip = target.getAttribute('data-tip') || null;
forId = target.getAttribute('data-for') || null;
target = target.parentElement;
}

target = lastTarget || e.target;

const target = e.target;
if (this.isCustomEvent(target) && !customEvent) {
return;
}
Expand Down

0 comments on commit 71da348

Please sign in to comment.