Skip to content
This repository has been archived by the owner on Jul 7, 2019. It is now read-only.

Auto Focus? #9

Closed
danielstern opened this issue Sep 20, 2016 · 8 comments
Closed

Auto Focus? #9

danielstern opened this issue Sep 20, 2016 · 8 comments
Labels

Comments

@danielstern
Copy link

It should be possible to automatically focus a selected modal element when it opens.

It should be possible to focus a specific other element when the modal closes.

@diegoddox
Copy link
Owner

Yes it is possible, what is your issue!

@danielstern
Copy link
Author

I currently have a modal with an OK button. When that modal opens, I want the OK button to be focused. Is there a code example that does this?

@diegoddox
Copy link
Owner

Just add the autofocus in your button.
ex: <button autofocus>my button</button>

@danielstern
Copy link
Author

danielstern commented Sep 21, 2016

@diegoddox Sounds good, actually what was needed was

<button autoFocus={true}>My button </button>

This also does not quite work

@danielstern
Copy link
Author

Actually, this only seems to work on select inputs. Not on buttons. Is there an example with a working autoFocus on a button I can work off of?

@diegoddox
Copy link
Owner

Your question has nothing to do with the repo but try this.

componentDidMount(){
   this.refs.nameOfButon.getDOMNode().focus(); 
}

render() {
   return <button ref="nameOfButon">my button</button>;
}

@danielstern
Copy link
Author

Sure it does.

Since my app is using the Redux pattern, components can't have ref or state. So, this doesn't work.

The autofocus value on the button should just work when placed on a modal from this repo.

@diegoddox
Copy link
Owner

diegoddox commented Sep 21, 2016

no, and you can still use refs and states under redux reduxjs/redux#1287

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

No branches or pull requests

2 participants