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

请问 Modal 中的 表单初始化的时候如何激活某个文本框? #1008

Closed
someok opened this issue Feb 14, 2016 · 4 comments
Closed

Comments

@someok
Copy link

someok commented Feb 14, 2016

Modal 中的 Form componentDidMount 只调用了一次,于是多次显示 Modal 的时候无法做激活操作了。

不知是否有办法处理?

@benjycui
Copy link
Contributor

Modal 只有在第一次显示时才会触发 componentDidMount 及相关的 lifecycle,后面的显隐是用 CSS 控制的。

Edit: 这个方法也不行。。事实上,在 Chrome 里面直接 $r.refs.input.focus() | $0.focus() 都没有 focus,不排除是我的环境问题,你还是先试试这个方法先吧 @someok

对于多次显示 Modal,考虑到 Modal 的 visible 其实是父组件传进来的,所以可以在父组件修改 Modal 的 visible 的同时,调用文本框的 focus

@someok
Copy link
Author

someok commented Feb 16, 2016

目前已解决,在 modal 中得使用 setTimeout 来调用相应的 focus 后才有效果。

    focusTitleInput() {
        let titleInput = ReactDOM.findDOMNode(this.refs.titleInput.refs.input);
        setTimeout(() => titleInput.focus());
    }

    componentDidMount() {
        this.focusTitleInput();
    }

    componentDidUpdate(prevProps, prevState) {
        this.focusTitleInput();
    }

@someok someok closed this as completed Feb 16, 2016
@deepfunc
Copy link

@someok 你的方法确实有效果,为啥要setTimeout呢?

@lock
Copy link

lock bot commented May 1, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants