Skip to content

Commit 41cd238

Browse files
author
Luke Barnard
committed
Update to reflect previous implementation
Which was element-hq@a74bbb4
1 parent 4fe4e10 commit 41cd238

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

‎src/components/structures/RoomSubList.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var RoomNotifs = require('matrix-react-sdk/lib/RoomNotifs');
3030
var FormattingUtils = require('matrix-react-sdk/lib/utils/FormattingUtils');
3131
var AccessibleButton = require('matrix-react-sdk/lib/components/views/elements/AccessibleButton');
3232
import Modal from 'matrix-react-sdk/lib/Modal';
33+
import KeyCode from 'matrix-react-sdk/lib/KeyCode';
3334

3435
// turn this on for drop & drag console debugging galore
3536
var debug = false;
@@ -151,10 +152,11 @@ var RoomSubList = React.createClass({
151152
}
152153
},
153154

154-
onRoomTileClick(roomId) {
155+
onRoomTileClick(roomId, ev) {
155156
dis.dispatch({
156157
action: 'view_room',
157158
room_id: roomId,
159+
clear_search: (ev && (ev.keyCode == KeyCode.ENTER || ev.keyCode == KeyCode.SPACE)),
158160
});
159161
},
160162

‎src/components/structures/SearchBox.js‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ limitations under the License.
1616

1717
'use strict';
1818

19-
var React = require('react');
19+
import React from 'react';
2020
import { _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 RateLimitedFunc from 'matrix-react-sdk/lib/ratelimitedfunc';
25+
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
2526

2627
module.exports = React.createClass({
2728
displayName: 'SearchBox',
@@ -39,26 +40,25 @@ module.exports = React.createClass({
3940

4041
componentDidMount: function() {
4142
this.dispatcherRef = dis.register(this.onAction);
43+
document.addEventListener('keydown', this._onKeyDown);
4244
},
4345

4446
componentWillUnmount: function() {
4547
dis.unregister(this.dispatcherRef);
48+
document.removeEventListener('keydown', this._onKeyDown);
4649
},
4750

4851
onAction: function(payload) {
4952
switch (payload.action) {
50-
/* Disabling this as I find it really really annoying, and was used to the
51-
previous behaviour - see https://github.com/vector-im/riot-web/issues/3348
52-
// Clear up the text field when a room is selected.
5353
case 'view_room':
54-
if (this.refs.search) {
54+
if (this.refs.search && payload.clear_search) {
5555
this._clearSearch();
5656
}
5757
break;
58-
*/
5958
case 'focus_room_filter':
6059
if (this.refs.search) {
6160
this.refs.search.focus();
61+
this.refs.search.select();
6262
}
6363
break;
6464
}
@@ -70,7 +70,7 @@ module.exports = React.createClass({
7070
this.onSearch();
7171
},
7272

73-
onSearch: new rate_limited_func(
73+
onSearch: new RateLimitedFunc(
7474
function() {
7575
this.props.onSearch(this.refs.search.value);
7676
},
@@ -90,6 +90,17 @@ module.exports = React.createClass({
9090
}
9191
},
9292

93+
_onKeyDown: function(ev) {
94+
// Only do anything when the key event target is the search input
95+
if(ev.target !== this.refs.search) return;
96+
switch (ev.keyCode) {
97+
case KeyCode.ESCAPE:
98+
this._clearSearch();
99+
dis.dispatch({action: 'focus_composer'});
100+
break;
101+
}
102+
},
103+
93104
_clearSearch: function() {
94105
this.refs.search.value = "";
95106
this.onChange();

0 commit comments

Comments
 (0)