@@ -16,12 +16,13 @@ limitations under the License.
1616
1717'use strict' ;
1818
19- var React = require ( 'react' ) ;
19+ import React from 'react' ;
2020import { _t } from 'matrix-react-sdk/lib/languageHandler' ;
21- var sdk = require ( 'matrix-react-sdk' )
22- var dis = require ( 'matrix-react-sdk/lib/dispatcher' ) ;
23- var rate_limited_func = require ( 'matrix-react-sdk/lib/ratelimitedfunc' ) ;
24- var AccessibleButton = require ( 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ) ;
21+ import KeyCode from 'matrix-react-sdk/lib/KeyCode' ;
22+ import sdk from 'matrix-react-sdk' ;
23+ import dis from 'matrix-react-sdk/lib/dispatcher' ;
24+ import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc' ;
25+ import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
2526
2627module . exports = React . createClass ( {
2728 displayName : 'SearchBox' ,
@@ -46,18 +47,19 @@ module.exports = React.createClass({
4647 } ,
4748
4849 onAction : function ( payload ) {
49- // Disabling this as I find it really really annoying, and was used to the
50- // previous behaviour - see https://github.com/vector-im/riot-web/issues/3348
51- /*
5250 switch ( payload . action ) {
53- // Clear up the text field when a room is selected.
5451 case 'view_room' :
55- if (this.refs.search) {
52+ if ( this . refs . search && payload . clear_search ) {
5653 this . _clearSearch ( ) ;
5754 }
5855 break ;
56+ case 'focus_room_filter' :
57+ if ( this . refs . search ) {
58+ this . refs . search . focus ( ) ;
59+ this . refs . search . select ( ) ;
60+ }
61+ break ;
5962 }
60- */
6163 } ,
6264
6365 onChange : function ( ) {
@@ -86,6 +88,15 @@ module.exports = React.createClass({
8688 }
8789 } ,
8890
91+ _onKeyDown : function ( ev ) {
92+ switch ( ev . keyCode ) {
93+ case KeyCode . ESCAPE :
94+ this . _clearSearch ( ) ;
95+ dis . dispatch ( { action : 'focus_composer' } ) ;
96+ break ;
97+ }
98+ } ,
99+
89100 _clearSearch : function ( ) {
90101 this . refs . search . value = "" ;
91102 this . onChange ( ) ;
@@ -135,6 +146,7 @@ module.exports = React.createClass({
135146 className = "mx_SearchBox_search"
136147 value = { this . state . searchTerm }
137148 onChange = { this . onChange }
149+ onKeyDown = { this . _onKeyDown }
138150 placeholder = { _t ( 'Filter room names' ) }
139151 />
140152 ] ;
0 commit comments