Skip to content

set modal focus state before showing#104

Merged
eddywashere merged 1 commit intoreactstrap:masterfrom
tyler-johnson:modal-focus-fix
Aug 19, 2016
Merged

set modal focus state before showing#104
eddywashere merged 1 commit intoreactstrap:masterfrom
tyler-johnson:modal-focus-fix

Conversation

@tyler-johnson
Copy link
Copy Markdown
Contributor

Hello,

I was having some issues with controlled inputs inside modals. When I would update the Modal after an input value changed, the input would suddenly lose focus. I managed to track this issue down to the Modal's focus state being set after the call to renderIntoSubtree(). This meant that the Modal wasn't be focused until the next render, when the input changed values.

Here is some React code to show what I mean:

import React from "react";
import {Modal,ModalBody} from "reactstrap";

class ModalWithInput extends React.Component {
  state = {};

  render() {
    return <Modal {...this.props}>
      <ModalBody>
        <input
          type="text"
          value={this.state.inputValue}
          onChange={(e) => this.setState({ inputValue: e.target.value })} />
      </ModalBody>
    </Modal>;
  }
}

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 09dabf8 on tyler-johnson:modal-focus-fix into 869e523 on reactstrap:master.

@eddywashere
Copy link
Copy Markdown
Member

Thanks @tyler-johnson, great find!

@eddywashere eddywashere merged commit a358233 into reactstrap:master Aug 19, 2016
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

Successfully merging this pull request may close these issues.

3 participants