Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not get autoFocus to work #75

Closed
fiws opened this issue Apr 11, 2018 · 7 comments
Closed

Can not get autoFocus to work #75

fiws opened this issue Apr 11, 2018 · 7 comments

Comments

@fiws
Copy link

fiws commented Apr 11, 2018

The prop simply does nothing for me:

Edit 3r3yx41kq6

@121watts
Copy link

Can confirm. Same issue here

@scniro
Copy link
Owner

scniro commented Apr 18, 2018

@fiws @121watts sorry for the late response. I'll definitely look into this over the weekend and either get a fix up or clarify the documentation.

@Adam13531
Copy link

I did some investigation into this just now.

The cm class is not being constructed with options passed in (which is where autofocus would actually take effect):

react-codemirror2 side of things:

this.editor = cm(this.ref) as IInstance;

CodeMirror side of things:

if (options.autofocus && !mobile) display.input.focus()

Instead, hydrate is called later in componentDidMount, which triggers a call to setOption in CodeMirror directly (source here). This just doesn't have a handler for autofocus, so nothing is done to focus the input.

I hope that's helpful. I can't prioritize making a pull request for this right now, so I haven't looked into the best solution. 🙁

@scniro
Copy link
Owner

scniro commented Apr 20, 2018

@Adam13531 thanks for doing some investigative work on this, it'll surely help. I'm planning on knocking this out over the weekend and will post an update here 👍

scniro added a commit that referenced this issue Apr 22, 2018
@scniro
Copy link
Owner

scniro commented Apr 22, 2018

@Adam13531 @121watts @fiws This should now be fixed with the 5.0.0 release. I've done away with the autoFocus prop entirely in favor of the codemirror options={{ autofocus: true }}. As @Adam13531 pointed out, there simply wasn't a handler for this, so we just trigger it on componentDidMount

if (this.editor.getOption('autofocus')) {
  this.editor.focus();
}

@scniro scniro closed this as completed Apr 22, 2018
@121watts
Copy link

awesome! thanks for the speedy response / resolution

@Adam13531
Copy link

@scniro thanks a ton for the fix! I tried it out and it's working. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants