I'm trying to put the div scroll with ref tag inside Dialog Material-UI Design I'm getting an error says Cannot read property 'scrollHeight' of undefined
If I use my code out of Dialog it works fine here's the example
All what I'm trying to do is to make the scroll div to start from the end
I did an example on Not working with Dialog
import React from 'react';
import { render } from 'react-dom';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
import RaisedButton from 'material-ui/RaisedButton';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
open: false,
}
}
handleOpen = () => {
this.setState({ open: true });
};
handleClose = () => {
this.setState({ open: false });
};
componentDidMount() {
this.shoppingListContainer.scrollTop = this.shoppingListContainer.scrollHeight;
}
render() {
return (
<MuiThemeProvider>
<div id="scrolldiv">
<RaisedButton label="Alert" onClick={this.handleOpen} />
<Dialog
title="Dialog With Actions"
modal={false}
open={this.state.open}
onRequestClose={this.handleClose}
>
<div>
<ul style={{
width: 115,
height: 100,
overflow: 'auto',
border: '2px black solid'
}}
ref={(shoppingListContainer) => { this.shoppingListContainer = shoppingListContainer; }}
>
<li>Instagram</li>
<li>WhatsApp</li>
<li>Oculus</li>
<li>Instagram</li>
<li>WhatsApp</li>
<li>Oculus</li>
<li>Instagram</li>
<li>WhatsApp</li>
<li>Oculus</li>
<li>Instagram</li>
<li>WhatsApp</li>
<li>Oculus</li>
</ul>
</div>
</Dialog>
</div>
</MuiThemeProvider>
);
}
}
render(<App />, document.getElementById('root'));