Reputation: 339
I'm using antd in React.
There is a Modal, the content inside is very long (is a long ). After opening this Modal, the page will jump to the end of Modal. I want Modal to start display from the top after it pops up.
How to do that?
Upvotes: 2
Views: 4718
Reputation: 86
You're probably getting focus'd on one of the footer's buttons. Antd has a way to remove focus (thus, setting your position at 0,0) for functional Modal, and that's autoFocusButton
.
Modal.confirm({
centered: true,
bodyStyle: {overflowY: 'inherit', maxHeight: "90vh"},
autoFocusButton: null,
content: <ReactNode />,
});
The CSS styling in bodyStyle + centered
is completely optional, but it could help you keep some padding outside the modal while still be able to scroll.
Upvotes: 1
Reputation: 320
I ran into the same issue. My hacky fix was to set a timeout that selected the div used by the modal and scroll that up.
Modal.confirm({
content: <SomeReactComponent />,
});
// scroll it up, kinda hacky
setTimeout(() => document.getElementsByClassName('ant-modal-wrap')[0].scrollTo(0, 0), 100);
Upvotes: 1
Reputation: 5669
You can do it by scrolling the window to 0
th position while you set the state value which sets the modal visibility to true like,
this.setState({showModal:true},()=>window.scrollTo(0, 0));
Upvotes: 1