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(Popup): execute onClose when Popup closes on scroll #2182

Merged

Conversation

mkarajohn
Copy link
Contributor

I believe when a popup closes on scroll the onClose handler should be called, since the popup closed.

This PR makes it so.

@mkarajohn
Copy link
Contributor Author

mkarajohn commented Oct 10, 2017

I am not sure what is breaking the tests. It passed locally and the commit name follows the guidelines. Help?

this.setState({ closed: true })

eventStack.unsub('scroll', this.hideOnScroll, { target: window })
setTimeout(() => this.setState({ closed: false }), 50)

this.handleClose(e)
Copy link
Member

Choose a reason for hiding this comment

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

@mkarajohn Did you investigate what closed value in state actually does? Why it becomes false after 50ms? This looks confusing to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I I saw it reopens the modal, even though I do not understand the reason as to why it does so.

From my understanding of the docs, and from the visual feedback, when the modal closes on scroll, it closes for good.

Could you please explain to me?

Copy link
Member

Choose a reason for hiding this comment

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

Seems it is only used in one place, render. If true, the trigger is rendered directly, else, the Portal is rendered with the trigger set:

if (closed) return trigger

// ..snip

return (
  <Portal...

I can't see why a timeout is added here?

Also, I've been racking my brain as to why we have an error logged regarding setState being called on an unmounted component, and I believe this is the issue :) There is no cancelling of this timeout when the Popup unmounts, therefore, setState can still be called 50ms after unmount.

This looks like it might be a hack to "reset" the portal. By rendering the trigger only, there is no Portal so it appears to have closed. Then, by nearly immediately (50ms?) rending the Portal again this ensures the Portal behavior is added to the trigger again. Future click/hover/etc will re-open the Portal.

I would have to investigate a solution to have a solid answer, but my suggestion would be to explore moving Popup to an AutoControlledComponent. Then, in hideOnScroll, we likely need to this.trySetState({ open: false }) without a timeout. This way, we are attempting to immediately close the Popup on scroll.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@levithomason

Also, I've been racking my brain as to why we have an error logged regarding setState being called on an unmounted component, and I believe this is the issue :) There is no cancelling of this timeout when the Popup unmounts, therefore, setState can still be called 50ms after unmount.

This was supposed to be closed here. It seems like it's been undone or something.

So, what about the initial concern that this PR addresses? The fact that the onClose is not called when the Popup closes because of scrolling?

Copy link
Member

Choose a reason for hiding this comment

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

So, what about the initial concern that this PR addresses? The fact that the onClose is not called when the Popup closes because of scrolling?

Yes, any state change due to user interaction should fire callbacks. This would include scroll. We only skip callbacks when state is changed through props, such as toggling the open prop.

@codecov-io
Copy link

codecov-io commented Oct 14, 2017

Codecov Report

Merging #2182 into master will decrease coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2182      +/-   ##
==========================================
- Coverage   99.73%   99.65%   -0.08%     
==========================================
  Files         151      151              
  Lines        2624     2624              
==========================================
- Hits         2617     2615       -2     
- Misses          7        9       +2
Impacted Files Coverage Δ
src/modules/Popup/Popup.js 100% <100%> (ø) ⬆️
src/modules/Search/Search.js 98.39% <0%> (-1.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28c8af9...83d8fd6. Read the comment docs.

@layershifter
Copy link
Member

I've retrigged the build, now it passes

@layershifter layershifter changed the title fix(Popup): Execute onClose when popup closes on scroll fix(Popup): execute onClose when popup closes on scroll Oct 14, 2017
@layershifter layershifter changed the title fix(Popup): execute onClose when popup closes on scroll fix(Popup): execute onClose when Popup closes on scroll Oct 14, 2017
@layershifter
Copy link
Member

@mkarajohn Let's add a test that asserts that onClose will be called on scroll and we will ready for review

Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

@mkarajohn Thanks for PR. I've added a missing test and simplified existing. I will investigate the case with closed during the refactor in future

@layershifter layershifter merged commit 01b02f7 into Semantic-Org:master Oct 26, 2017
@levithomason
Copy link
Member

Released in semantic-ui-react@0.76.0

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