Skip to content
This repository was archived by the owner on Mar 27, 2019. It is now read-only.

Add matchAnchorWidth to popover #39

Merged

Conversation

newyork-anthonyng
Copy link
Contributor

This commit is a WIP.

I will add tests to this if this is the way to go.

Copy link
Contributor

@quantizor quantizor left a comment

Choose a reason for hiding this comment

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

Great start! Some comments attached.

matchAnchorWidth = () => {
if (!this.props.matchAnchorWidth) return;

const anchor = this.props.anchor instanceof HTMLElement
Copy link
Contributor

@quantizor quantizor Mar 13, 2017

Choose a reason for hiding this comment

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

Just learned this recently, but findDOMNode is actually an identity function if called on a DOM node, so you can remove this ternary and always call it.

? this.props.anchor
: findDOMNode(this.props.anchor);
const dialog = this.dialog.$dialog;
const anchorWidth = anchor.getBoundingClientRect().width;
Copy link
Contributor

Choose a reason for hiding this comment

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

We compute this in cacheViewportCartography() as called by this.align(), so if we move the invocation of this function to after the caching is complete, we can avoid doing the measurement work twice 😄

this.align();
window.addEventListener('resize', this.matchAnchorWidth, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this additional event listener as well by integrating the width matching function into the alignment flow.

@newyork-anthonyng
Copy link
Contributor Author

@probablyup Thanks for the comments. I will make the updates and work on adding tests this weekend.

@newyork-anthonyng newyork-anthonyng force-pushed the popover-match-anchor-width branch from ae4f502 to 6307048 Compare March 20, 2017 00:32
@newyork-anthonyng newyork-anthonyng force-pushed the popover-match-anchor-width branch from 6307048 to 03cc5e8 Compare March 20, 2017 00:36
@newyork-anthonyng
Copy link
Contributor Author

I made the changes and added a test for this. Let me know if there's anything else needed :)

@quantizor
Copy link
Contributor

Sorry for the very long delay, this looks excellent.

@quantizor quantizor merged commit 0db516a into enigma-io:master Jun 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants