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

Initially disabled element breaks focus wrap #50

Closed
JonathanTR opened this issue Nov 10, 2018 · 4 comments
Closed

Initially disabled element breaks focus wrap #50

JonathanTR opened this issue Nov 10, 2018 · 4 comments

Comments

@JonathanTR
Copy link

JonathanTR commented Nov 10, 2018

First off: this is an awesome library that's saved me a big headache in implementation. Thanks for your work on this!

I've found an issue with having an initially disabled button in the mix. In my case, I disable the save button on a modal form if no changes have been made. However, I've found that having that element initially disabled breaks the focus wrap so that it stops on the button. Perhaps something to do with how the lock is initialized?

Here's a minimal example:

class ExampleForm extends React.Component {
  state = {
    string: ""
  }

  render(){
    return (
      <FocusLock>
        <input 
          onChange={ ({ target }) => this.setState({ string: target.value }) } 
          type="text" 
          tabIndex="1" 
        />
        <button 
          disabled={this.state.string.length == 0} 
          tabIndex="1"
        >
          Save
        </button>
      </FocusLock>
    )
  }
}

What I may do in the meantime is change how I disable buttons, although it would be ideal to stick with the browser implementation. Thanks for taking a look at this - let me know if there's any other info I can gather.

@theKashey
Copy link
Owner

The problem is not with disabled, but with disabled + tabIndex. Are you sure you need tabIndex?

@theKashey
Copy link
Owner

theKashey commented Nov 11, 2018

Anyway - that's my mistake. I'll fix it a but later, but removing tabIndex will fix everything right now.
See https://codesandbox.io/s/204kx1xjry

@theKashey
Copy link
Owner

Fixed in 1.17.5

@JonathanTR
Copy link
Author

Thanks!

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

2 participants