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
fix(Tooltip): Support for multiple target elements #1465
fix(Tooltip): Support for multiple target elements #1465
Conversation
Up |
} | ||
|
||
document.removeEventListener('click', this.handleDocumentClick, true) | ||
} | ||
|
||
updateTarget() { | ||
const newTarget = getTarget(this.props.target); | ||
if (newTarget !== this._target) { | ||
const newTarget = getTarget(this.props.target, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR broke support for refs as target
prop. When props.target
is a React ref or an HTMLElement, this will return an HTMLElement, not an array. Array.from(newTarget)
will then return an empty array, and Popper will error that target
was set to undefined
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in #1687
const newTarget = getTarget(this.props.target); | ||
if (newTarget !== this._target) { | ||
const newTarget = getTarget(this.props.target, true); | ||
if (newTarget !== this._targets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using reference equality here to compare two arrays doesn't look right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it seems like this would always be true
since we would be getting a new array from getTarget
every time. Probably need to perform a deep comparison here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then only remove the event listeners from the targets that actually got removed (vs removing from all the targets if one was removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be easier and quicker to just remove them all and add the newTarget back 🤷♂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True
It fixes #1185
Here is stackblitz demo with fix - https://stackblitz.com/edit/react-k8rkzv