Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

refactor(Portal): allow to use createRef() API in triggerRef #787

Merged
merged 6 commits into from
Jan 29, 2019

Conversation

layershifter
Copy link
Member

The main goal of this PR allow to use createRef API in triggerRef.

@layershifter layershifter changed the title refactor(Portal): use createRef() API refactor(Portal): allow to use createRef() API in triggerRef Jan 29, 2019
doesNodeContainClick(this.triggerNode, e) || // event happened in trigger (delegate to trigger handlers)
doesNodeContainClick(this.portalNode, e) // event happened in the portal
!this.portalRef.current || // no portal
doesNodeContainClick(this.triggerRef.current, e) || // event happened in trigger (delegate to trigger handlers)
Copy link
Contributor

@kuzhelov kuzhelov Jan 29, 2019

Choose a reason for hiding this comment

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

this method doesNodeContainClick is working with DOM modes only. We should preserve original code of this method and just pass DOM nodes there explicitly - this will make contract of this method to be explicit

this.triggerNode = triggerNode

_.invoke(this.props, 'triggerRef', triggerNode)
handleRef(this.triggerRef, triggerNode)
Copy link
Contributor

Choose a reason for hiding this comment

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

once again this strikes my cognitive process :) I really think that setRef will be much more intuitive name for this method as, essentially, this is what it does

@@ -57,9 +58,9 @@ export interface PortalProps extends ChildrenComponentProps, ContentComponentPro
/**
* Called with a ref to the trigger node.
*
* @param {JSX.Element} node - Referred node.
* @param {HTMLElement} node - Referred node.
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be removed now

@@ -103,7 +104,7 @@ class Portal extends AutoControlledComponent<ReactPropsStrict<PortalProps>, Port
onUnmount: PropTypes.func,
open: PropTypes.bool,
trigger: PropTypes.node,
triggerRef: PropTypes.func,
triggerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
Copy link
Contributor

Choose a reason for hiding this comment

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

probably, this is a good candidate for custom prop types - would expect this to appear in multiple places

@layershifter layershifter merged commit 52461b1 into master Jan 29, 2019
@layershifter layershifter deleted the refactor/portal branch January 29, 2019 15:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants