jcmcneal / react-step-wizard

A modern flexible step wizard component built for React.
MIT License
580 stars 126 forks source link

On 'Enter' the wizard gets to the next step #81

Closed iamalextodoran closed 3 years ago

iamalextodoran commented 3 years ago

When pressing the enter key the wizard gets to the next step and skips all my validations. I tried preventing the default, but didn't work.

jcmcneal commented 3 years ago

If you haven't figured it out already, can you post a snippet of your code?

iamalextodoran commented 3 years ago

I've disabled the action on key press with useEffect, so far it's fine and seems to work well.

useEffect(() => {
    const handleUserKeyPress = event => {
      if (event.key === 'Enter') {
        event.preventDefault();
      }
    };

    window.addEventListener('keydown', handleUserKeyPress);'

    return () => {
      window.removeEventListener('keydown', handleUserKeyPress);
    };
}, []);