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

fix(Tooltip): Support for multiple target elements #1465

Merged
merged 7 commits into from Oct 15, 2019

Conversation

akhlesh
Copy link
Contributor

@akhlesh akhlesh commented Apr 21, 2019

It fixes #1185
Here is stackblitz demo with fix - https://stackblitz.com/edit/react-k8rkzv

  • Bug fix
  • New feature
  • Chore
  • Breaking change
  • There is an open issue which this change addresses
  • I have read the CONTRIBUTING document.
  • My commits follow the Git Commit Guidelines
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Kliton
Copy link

Kliton commented Oct 15, 2019

Up

@TheSharpieOne TheSharpieOne changed the title fix(Tooltip single target): Support for multiple target elements fix(Tooltip): Support for multiple target elements Oct 15, 2019
@TheSharpieOne TheSharpieOne merged commit 45775c0 into reactstrap:master Oct 15, 2019
}

document.removeEventListener('click', this.handleDocumentClick, true)
}

updateTarget() {
const newTarget = getTarget(this.props.target);
if (newTarget !== this._target) {
const newTarget = getTarget(this.props.target, true);

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.

Copy link
Member

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) {

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

Copy link
Member

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.

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)

Copy link
Member

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 🤷‍♂

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltip only show for first element
4 participants