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

Scroll to top of Dialog #9186

Closed
emptycrown opened this issue Nov 17, 2017 · 6 comments
Closed

Scroll to top of Dialog #9186

emptycrown opened this issue Nov 17, 2017 · 6 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@emptycrown
Copy link

  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I'm rendering a pretty long component within the dialog, and am using the autoscroll functionality to get the overflow-y: auto styling in the dialog content. At certain points, the component moves to the the next step, and I would like to instantly go to the top of the dialog content.

I saw that jQuery's scrollTop function can be used to get to the top of a component, but I'm unsure how to reference the dialogContent div. Please advise.

Current Behavior

Currently, when the component changes, the scroll remains the same, and the result is that the user sees a lower part of the new component.

Your Environment

Tech Version
Material-UI 0.17.4
React 15.3.2
browser Chrome
etc
@m2mathew m2mathew added the support: question Community support but can be turned into an improvement label Nov 17, 2017
@m2mathew
Copy link
Member

If you want to manipulate the scrollPosition yourself programmatically, you need to use the Ref Callback pattern to have access to that DOM element directly.

Check StackOverflow and similar sources for other questions on how to use the library. 😄

@achikin
Copy link

achikin commented Jul 6, 2018

DialogContent acts like a scroll view, so you can wrap your changing components in it's own DialogContent like this:

<Dialog>
  <DialogTitle>sfdasf</DialogTitle>
  <MyComponentThatChanges/>
  <DialogActions..../>
</Dialog>

<MyComponentThatChanges>
  <DialogContent>
    actual content here
  </DialogContent>
</MyComponentThatChanges>

This way each changing component will have it's own content, scrolled to the top.

@coryhouse
Copy link

The suggestion from @m2mathew doesn't work because window.scroll doesn't work on dialogs. I've found no solution for scrolling to an element in a dialog. If it's possible, I'd be happy to submit a PR documenting how to do so.

@JoeDuncko
Copy link

Just ran into this. Has anyone figured out a solution?

@achikin
Copy link

achikin commented Mar 7, 2019

@JoeDuncko please try my solution.

@DzTheRage
Copy link

I was able to get this working using @achikin solution. Just nest a div inside of dialog content then render another dialog content.

<DialogContent>
   <div ref={node => {
	this.dialogContent = node;
      }}>
	<DialogContent className={classes.fixContentPadding}>
		Actual Content Here
	</DialogContent>
    </div>
</DialogContent>

handleNext = () => {
    /* Smooth scroll to top */
    this.dialogContent.scrollIntoView({
	behavior: 'smooth',
	block: 'start'
     });
    /* Go to next step */
     const { activeStep } = this.state;
     this.setState({
     activeStep: activeStep + 1
     });
};

	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

6 participants