andria-dev / react-spring-modal

Animatable and accessible modals built with react-spring
34 stars 8 forks source link

Option to disable auto focus? #3

Closed bitttttten closed 4 years ago

bitttttten commented 4 years ago

I have a form inside the modal, and after the modal has fully faded it, react-spring-modal is auto focusing on the first input. Since the form does appear before onRest is called the user can be entering in text in other control elements and then the code here makes the current control element loose focus as it attempts to focus on the first control element of the modal.

Is it possible to make this function / auto focus check optional?

andria-dev commented 4 years ago

Yes that is possible, I will work on it when I get back. Or you can make a pull request yourself if you want.

andria-dev commented 4 years ago

@bitttttten I believe this has been fixed by my newest release, version 1.1.0

If you have any concerns surrounding how this works or if it doesn't actually solve your problem, let me know 👍

For reference: The new feature fixing this issue is called autoFocus (defaults to true). It can be utilized as follows:

function App() {
  const [isOpen, setIsOpen] = useState(false);
  return (
    <>
      <button onClick=${() => setIsOpen(true)}>Open Modal</button>
      <CenterModal autoFocus={false} isOpen={isOpen} onRequestClose={() => setIsOpen(false)}>
        <h1>Does not autofocus</h1>
        <button>Ya yee</button>
      </CenterModal>
    </>
}
bitttttten commented 4 years ago

Ahh wow, nice one :)

I just updated and it was working perfectly! I was working on a fork already but I had no had time to make a PR back.

Thanks!

andria-dev commented 4 years ago

You're welcome, I'm glad it's working perfectly for you!