-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: Always focus title field on new draft #1696
Conversation
@@ -4,6 +4,7 @@ | |||
import React, { PropTypes } from 'react'; | |||
import classNames from 'classnames'; | |||
import omit from 'lodash/object/omit'; | |||
import ReactDOM from 'react-dom'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling this will become an ongoing battle ( 😄 ), but per our naming conventions, this should be ReactDom
(reference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may or may not have done this on purpose - well it is what the deprecation notice told me to use in the console 😆
'is-valid': this.props.isValid | ||
} ); | ||
focus() { | ||
ReactDom.findDOMNode( this.refs.textField ).focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the benefit of moving focus
to <FormTextInput />
is that now you have access to the "raw" DOM element, so you no longer need findDOMNode
. Here, this.refs.textField
is the a reference to the DOM node itself, so this can simply be this.refs.textField.focus()
and you can drop the react-dom
dependency.
Thanks @aduth - updated. |
}, | ||
|
||
render() { | ||
const otherProps = omit( this.props, [ 'className', 'type', 'ref' ] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could have left ref
out, since I don't think ref
is passed as a prop even when assigned in a parent component, and because you override it after applying the spread properties to the <input >
element. In fact, this whole omit statement could be left out altogether -
<input { ...this.props } ref="textField" type={ type } className={ classes } />
It's a small detail, so not to hold up merge.
Minor details be minor details. This works well in my testing 👍 |
Needs refresh. |
ce646fa
to
4adaf82
Compare
👍 Nice. Looks good. |
Editor: Always focus title field on new draft
Fixes #1622
When you first open the editor via the pencil or add in a site sidebar, the title field is focused and ready to receive a witty post title. Once within the editor though, any action that results in another new post - the title field is not auto focused. This branch aims to focus the title field on all new drafts - regardless of how one arrives at that new draft ( only on non-mobile viewports ).
To Test