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

feat(Portal): More flexible configuration #590

Merged
merged 1 commit into from
Oct 3, 2016

Conversation

jeffcarbs
Copy link
Member

  • Add closeOnTriggerClick prop
  • Update closeOnMouseLeave to handle mouse leave of either trigger or portal
  • Add configurable delay for open/close on hover

This addresses an open issue of #570 which is not being able to mouse-over from the trigger of a Popup.

@jeffcarbs jeffcarbs force-pushed the feature/portal-config branch from 50b2cbc to 77e7fed Compare October 3, 2016 03:58
@codecov-io
Copy link

codecov-io commented Oct 3, 2016

Current coverage is 100% (diff: 100%)

Merging #590 into master will not change coverage

@@           master   #590   diff @@
====================================
  Files         119    119          
  Lines        1894   1915    +21   
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
+ Hits         1894   1915    +21   
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last update 7fff825...f65de27

@jeffcarbs jeffcarbs mentioned this pull request Oct 3, 2016
19 tasks
@jeffcarbs
Copy link
Member Author

@levithomason - this is blocking the Popup PR so if you could take a look I'd appreciate it 👍

@levithomason
Copy link
Member

On it, thanks!

@typehorror
Copy link
Contributor

@jcarbo, I pulled your branch into the Popup and noticed that the first time the Popup shows up the timer on leave isn't respected. The bug goes away every time I hover the trigger after that.

@@ -37,15 +37,27 @@ class Portal extends Component {
/** Controls whether or not the portal should close on blur of the trigger. */
closeOnTriggerBlur: PropTypes.bool,

/** Controls whether or not the portal should close when mousing out of the trigger. */
closeOnTriggerMouseLeave: PropTypes.bool,
/** Controls whether or not the portal should close on blur of the trigger. */
Copy link
Member

Choose a reason for hiding this comment

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

close on blur != closeOnTriggerClick

* Controls whether or not the portal should close when mousing out of the
* trigger OR the portal content.
*/
closeOnMouseLeave: PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

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

Hm, seems like we should separate these. I know the names are hideous, but I can see wanting one or the other:

closeOnTriggerMouseLeave
closeOnPortalMouseLeave

Thoughts?

Copy link
Member Author

@jeffcarbs jeffcarbs Oct 3, 2016

Choose a reason for hiding this comment

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

That was my initial thought, but then I was wondering how do you configure allowing mousing from the trigger to the portal? I think I just figured it out though:

  • If only closeOnTriggerMouseLeave is set, then mouseover/leave on the portal won't do anything
  • If closeOnPortalMouseLeave is set, then mouseover of the portal clears the timer, mouseleave restarts the timer.

So closeOnPortalMouseLeave has the added effect of preventing close when mousing over the gap from trigger -> portal

This actually lets us keep more closely with SUI's hoverable:

  • hoverable => false is { closeOnTriggerMouseLeave: true }
  • hoverable => true is { closeOnTriggerMouseLeave: true, closeOnPortalMouseLeave: true }

Copy link
Member

Choose a reason for hiding this comment

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

I'm moving quickly here, but I think this makes sense.

@@ -229,6 +273,12 @@ class Portal extends Component {
this.trySetState({ open: false })
}

closeWithTimeout = (e, delay) => {
// React wipes certain props (e.g. currentTarget) so we need to clone.
const eventClone = { ...e }
Copy link
Member

@levithomason levithomason Oct 3, 2016

Choose a reason for hiding this comment

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

Heads up, React wipes the entire event object, nullifying all values. That's because React reuses a single event object. In order to persist the event object for async access, use e.persist():

https://facebook.github.io/react/docs/events.html#event-pooling

I think what is here will technically work, but it still seems as though we should be using e.persist(), even if we're copying the persisted object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried e.persist initially but doesn't preserve the currentTarget, see facebook/react#2857. This is kinda gross but it's the only way to make a copy of the event as-is.

Copy link
Member

Choose a reason for hiding this comment

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

Womp womp, thanks for the link

@typehorror
Copy link
Contributor

typehorror commented Oct 3, 2016

@jcarbo Nevermind the issue I reported earlier (aka. timer not respected the 1st time), I can't reproduce it anymore.

* Add closeOnTriggerClick prop
* Update closeOnMouseLeave to handle mouse leave of either trigger or portal
* Add configurable delay for open/close on hover
@jeffcarbs jeffcarbs force-pushed the feature/portal-config branch from 1a5763f to f65de27 Compare October 3, 2016 05:36
@jeffcarbs
Copy link
Member Author

Ok made the changes discussed here and checks came back green. I think this is 👍

@levithomason levithomason merged commit b6703ab into master Oct 3, 2016
@levithomason levithomason deleted the feature/portal-config branch October 3, 2016 06:17
@levithomason
Copy link
Member

Released in stardust@0.52.1

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

Successfully merging this pull request may close these issues.

4 participants