@@ -94,13 +94,13 @@ export default class ArticleDetail extends React.Component {
9494 }
9595 this . titleHandler = e => {
9696 if ( isModalOpen ( ) ) return true
97- let titleEl = ReactDOM . findDOMNode ( this . refs . title )
98- titleEl . focus ( )
99- titleEl . select ( )
97+ if ( this . refs . title ) {
98+ this . focusTitle ( )
99+ }
100100 }
101101 this . editHandler = e => {
102102 if ( isModalOpen ( ) ) return true
103- this . refs . editor . switchEditMode ( )
103+ if ( this . refs . editor ) this . refs . editor . switchEditMode ( )
104104 }
105105
106106 this . state = {
@@ -136,11 +136,10 @@ export default class ArticleDetail extends React.Component {
136136 if ( this . props . activeArticle == null || prevProps . activeArticle == null || this . props . activeArticle . key !== prevProps . activeArticle . key ) {
137137 if ( this . refs . editor ) this . refs . editor . resetCursorPosition ( )
138138 }
139- }
140139
141- editArticle ( ) {
142- ReactDOM . findDOMNode ( this . refs . title ) . focus ( )
143- ReactDOM . findDOMNode ( this . refs . title ) . select ( )
140+ if ( prevProps . activeArticle == null && this . props . activeArticle ) {
141+
142+ }
144143 }
145144
146145 renderEmpty ( ) {
@@ -233,16 +232,29 @@ export default class ArticleDetail extends React.Component {
233232 e . preventDefault ( )
234233 this . switchEditMode ( )
235234 }
235+
236236 if ( e . keyCode === 9 && e . shiftKey ) {
237237 e . preventDefault ( )
238- ReactDOM . findDOMNode ( this . refs . title ) . focus ( )
238+ this . focusTitle ( )
239+ }
240+
241+ if ( e . keyCode === 27 ) {
242+ this . focusTitle ( )
239243 }
240244 }
241245
242246 switchEditMode ( ) {
243247 this . refs . editor . switchEditMode ( )
244248 }
245249
250+ focusTitle ( ) {
251+ if ( this . refs . title ) {
252+ let titleEl = ReactDOM . findDOMNode ( this . refs . title )
253+ titleEl . focus ( )
254+ titleEl . select ( )
255+ }
256+ }
257+
246258 render ( ) {
247259 let { folders, status, tags, activeArticle, modified, user } = this . props
248260 if ( activeArticle == null ) return this . renderEmpty ( )
0 commit comments