-
Notifications
You must be signed in to change notification settings - Fork 4k
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
layershifter
merged 3 commits into
Semantic-Org:master
from
mkarajohn:execute_onclose_when_hideonscroll
Oct 26, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 becomesfalse
after 50ms? This looks confusing to me.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 thetrigger
set: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 tothis.trySetState({ open: false })
without a timeout. This way, we are attempting to immediately close the Popup on scroll.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.