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

Problem with field focus inside modal of ant-design #279

Closed
thearabbit opened this issue Apr 21, 2017 · 4 comments
Closed

Problem with field focus inside modal of ant-design #279

thearabbit opened this issue Apr 21, 2017 · 4 comments
Assignees
Labels
Type: Question Questions and other discussions

Comments

@thearabbit
Copy link

componentDidMount() {
        this.balanceRef.focus();
    }
------
 <AutoField
                        name="balance"
                        inputRef={(ref) => {
                            this.balanceRef = ref
                        }}
 />

Get error

Uncaught TypeError: this.balanceRef.focus is not a function
    at OrderPayment.componentDidMount
@janowsiany janowsiany self-assigned this Apr 22, 2017
@janowsiany
Copy link
Contributor

Please share the whole example with both schema and OrderPayment component. My first guess is that OrderPayment is a functional component which does not have an instance.

@thearabbit
Copy link
Author

Oh I use this form in Antd Modal like this

<Modal
      title="Payment"
      key={this.state.modalKey}
      visible={this.state.visibleModal}
      onCancel={this.handleModalCancel}
       footer={null}
>
        <OrderPayment order={order} handleModalCancel={this.handleModalCancel}  />
</Modal>
--------------
export default class OrderPayment extends Component {
    componentDidMount() {
        this.balanceRef.focus();
    };
   
   render(){
      return(
        ..........
        <AutoField name="balance" inputRef={ref => this.balanceRef = ref}/>
     );
   }

@janowsiany
Copy link
Contributor

janowsiany commented Apr 23, 2017

Ok so generally it is a problem of ant-design package itself and its internals, especially rc-dialog from which they use their Modals. So if you take a look here they handle focus by their own and i could not find a way to prevent this or to change this behaviour.
So my suggestion is to use this solution:

componentDidMount () {
  setTimeout(() => this.balanceRef.focus(), 0)
}

Checked it myself and it is working, let me know if it does for you, so far i am closing,

@janowsiany janowsiany added the Type: Question Questions and other discussions label Apr 23, 2017
@janowsiany janowsiany changed the title Problem with inputRef Problem with field focus inside modal of ant-design Apr 23, 2017
@thearabbit
Copy link
Author

very thanks 👍
but now I still have problem with #278, could you help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Questions and other discussions
Projects
Archived in project
Development

No branches or pull requests

2 participants