davidmfoley / react-router-modal

Simple modals for react-router 4
MIT License
153 stars 20 forks source link

Keep origin scroll position when hitting the backdrop #11

Open rohillion opened 6 years ago

rohillion commented 6 years ago

Hey there! I implemented the modal on a list view. I can open the modal perfectly by clicking on a list item. The problem is when clicking the backdrop is that it navigates forward to the original list view instead of actually going back causing it to loose the scroll pretty much starting over the top of the list. I guess it would be awesome to have a behaviour like the browser's back button which goes back and automatically scrolls to the original position of the list for when the item was clicked. Does that makes sense?

Thanks a lot for the good work!

davidmfoley commented 6 years ago

Hmmm.. can you share a snippet with your routing setup? Thanks.

lukaszsobek commented 6 years ago

@davidmfoley I'll chime in here as I just experienced the same situation, the setup is: `

    <BrowserRouter>
      <div>

        <Route
          path="/"
          component={TestList}
          />

        <ModalRoute
          path="/test/:id"
          component={TestModal}
          parentPath='/'
          />

      </div>
    </BrowserRouter>

    <ModalContainer />
  </div>`
davidmfoley commented 6 years ago

I believe I fixed this back in March (v1.3.3) with the addition of autoRestoreScrollPosition on ModalContainer. (I forgot that this issue existed).