@@ -16,17 +16,16 @@ limitations under the License.
1616
1717'use strict' ;
1818
19- var React = require ( 'react' ) ;
20- var DragDropContext = require ( 'react-dnd' ) . DragDropContext ;
21- var HTML5Backend = require ( 'react-dnd-html5-backend' ) ;
22- var sdk = require ( 'matrix-react-sdk' )
23- var dis = require ( 'matrix-react-sdk/lib/dispatcher' ) ;
19+ import React from 'react' ;
20+ import { DragDropContext } from 'react-dnd' ;
21+ import HTML5Backend from 'react-dnd-html5-backend' ;
22+ import KeyCode from 'matrix-react-sdk/lib/KeyCode' ;
23+ import sdk from 'matrix-react-sdk' ;
24+ import dis from 'matrix-react-sdk/lib/dispatcher' ;
2425import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg' ;
25-
26- var VectorConferenceHandler = require ( '../../VectorConferenceHandler' ) ;
27- var CallHandler = require ( "matrix-react-sdk/lib/CallHandler" ) ;
28-
26+ import CallHandler from 'matrix-react-sdk/lib/CallHandler' ;
2927import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton' ;
28+ import VectorConferenceHandler from '../../VectorConferenceHandler' ;
3029
3130var LeftPanel = React . createClass ( {
3231 displayName : 'LeftPanel' ,
@@ -42,6 +41,10 @@ var LeftPanel = React.createClass({
4241 } ;
4342 } ,
4443
44+ componentWillMount : function ( ) {
45+ this . focusedElement = null ;
46+ } ,
47+
4548 componentDidMount : function ( ) {
4649 this . dispatcherRef = dis . register ( this . onAction ) ;
4750 } ,
@@ -64,6 +67,91 @@ var LeftPanel = React.createClass({
6467 }
6568 } ,
6669
70+ _onFocus : function ( ev ) {
71+ this . focusedElement = ev . target ;
72+ } ,
73+
74+ _onBlur : function ( ev ) {
75+ this . focusedElement = null ;
76+ } ,
77+
78+ _onKeyDown : function ( ev ) {
79+ if ( ! this . focusedElement ) return ;
80+ let handled = false ;
81+
82+ switch ( ev . keyCode ) {
83+ case KeyCode . UP :
84+ this . _onMoveFocus ( true ) ;
85+ handled = true ;
86+ break ;
87+ case KeyCode . DOWN :
88+ this . _onMoveFocus ( false ) ;
89+ handled = true ;
90+ break ;
91+ }
92+
93+ if ( handled ) {
94+ ev . stopPropagation ( ) ;
95+ ev . preventDefault ( ) ;
96+ }
97+ } ,
98+
99+ _onMoveFocus : function ( up ) {
100+ var element = this . focusedElement ;
101+
102+ // unclear why this isn't needed
103+ // var descending = (up == this.focusDirection) ? this.focusDescending : !this.focusDescending;
104+ // this.focusDirection = up;
105+
106+ var descending = false ; // are we currently descending or ascending through the DOM tree?
107+ var classes ;
108+
109+ do {
110+ var child = up ? element . lastElementChild : element . firstElementChild ;
111+ var sibling = up ? element . previousElementSibling : element . nextElementSibling ;
112+
113+ if ( descending ) {
114+ if ( child ) {
115+ element = child ;
116+ }
117+ else if ( sibling ) {
118+ element = sibling ;
119+ }
120+ else {
121+ descending = false ;
122+ element = element . parentElement ;
123+ }
124+ }
125+ else {
126+ if ( sibling ) {
127+ element = sibling ;
128+ descending = true ;
129+ }
130+ else {
131+ element = element . parentElement ;
132+ }
133+ }
134+
135+ if ( element ) {
136+ classes = element . classList ;
137+ if ( classes . contains ( "mx_LeftPanel" ) ) { // we hit the top
138+ element = up ? element . lastElementChild : element . firstElementChild ;
139+ descending = true ;
140+ }
141+ }
142+
143+ } while ( element && ! (
144+ classes . contains ( "mx_RoomTile" ) ||
145+ classes . contains ( "mx_SearchBox_search" ) ||
146+ classes . contains ( "mx_RoomSubList_ellipsis" ) ) ) ;
147+
148+ if ( element ) {
149+ element . focus ( ) ;
150+ this . focusedElement = element ;
151+ this . focusedDescending = descending ;
152+ }
153+ } ,
154+
67155 _recheckCallElement : function ( selectedRoomId ) {
68156 // if we aren't viewing a room with an ongoing call, but there is an
69157 // active call, show the call element - we need to do this to make
@@ -126,7 +214,8 @@ var LeftPanel = React.createClass({
126214 }
127215
128216 return (
129- < aside className = { classes } style = { { opacity : this . props . opacity } } >
217+ < aside className = { classes } style = { { opacity : this . props . opacity } }
218+ onKeyDown = { this . _onKeyDown } onFocus = { this . _onFocus } onBlur = { this . _onBlur } >
130219 { topBox }
131220 { callPreview }
132221 < RoomList
0 commit comments