react-stepzilla icon indicating copy to clipboard operation
react-stepzilla copied to clipboard

Browser back button?

Open SpencerGreene opened this issue 8 years ago • 6 comments

Nice component - thanks for putting it out! I tried the live demo and it seems that the browser 'back' button does not move backward in the form, which is something I need in my app - so - how hard is it to make it do that?

SpencerGreene avatar Jan 23 '18 19:01 SpencerGreene

I would love to see this as well.

francisngo avatar Oct 23 '18 18:10 francisngo

Also interested, what is the best way to go about doing this?

brennondenny avatar Nov 26 '18 14:11 brennondenny

Sorry for the delay - great idea, this feature should be mandatory and I’ll look into to after I get this library to work with hooks

newbreedofgeek avatar Nov 04 '20 21:11 newbreedofgeek

@newbreedofgeek I can help here if you need.

zeel avatar Nov 16 '20 11:11 zeel

Hi @zeel - thanks! Yes, your help is appreciated.

Let’s do some solution design first between us:

How I would do it:

  1. we need to capture “deep link” state of each step: E.g: Step 1 deep link: mysite.com/stepzilla-page.html#s1

Step 2 deep link: mysite.com/stepzilla-page.html#s2

...

Step 9 deep link: mysite.com/stepzilla-page.html#s9

Should be easy to do this by adding an hash. This is so the user can share a deep link to a step if needed.

  1. use “pushState” in the core StepZilla source file where the final “back” / “front” step jump logic happens. This will push a history entry that the browser can use.

PushState has 3 params : history.pushState([data], [title], [url]);

We can use data to store the step index based on the URL # we used. Title can be ignored I think and url will be the hash based URL

Eg stepzilla-page.html#s9

So: history.pushState(9, ‘’, ‘stepzilla-page.html#s9’ );

This should take care of the user going back and front on the webpage and the history will keep up.

  1. we then need to “recover the step” via a event listener which can be attached to the page

window.addEventListener('popstate', function(e) { // e.state is equal to the data-attribute of the last image we clicked });

There is a good example here: https://css-tricks.com/using-the-html5-history-api/

Let me know your thoughts? Or give it a go and let me know if it works?

Thanks!

newbreedofgeek avatar Nov 17 '20 07:11 newbreedofgeek

@newbreedofgeek seems feasible with your approach. maybe whole feature can be added behind one prop so if someone don't want this feature, it won't pollute browser history.

I will try this from master branch and update here. Hope it won't conflict with React hooks development

zeel avatar Nov 18 '20 15:11 zeel