Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0f49fe9

Browse files
committed
iterate spaces treeview stuff
1 parent 09f20bc commit 0f49fe9

File tree

5 files changed

+54
-43
lines changed

5 files changed

+54
-43
lines changed

res/css/structures/_SpaceRoomDirectory.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ limitations under the License.
278278
}
279279
}
280280

281+
li.mx_SpaceRoomDirectory_roomTileWrapper {
282+
list-style: none;
283+
}
284+
281285
.mx_SpaceRoomDirectory_roomTile,
282286
.mx_SpaceRoomDirectory_subspace_children {
283287
&::before {

src/accessibility/RovingTabIndex.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({ children, handleHomeE
196196
handled = true;
197197
if (context.state.refs.length > 0) {
198198
const idx = context.state.refs.indexOf(context.state.activeRef);
199-
if (idx > 1) {
199+
if (idx > 0) {
200200
context.state.refs[idx - 1].current.focus();
201201
}
202202
}

src/components/structures/SpaceRoomDirectory.tsx

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import React, { ReactNode, KeyboardEvent, useMemo, useState } from "react";
17+
import React, { ReactNode, KeyboardEvent, useMemo, useState, KeyboardEventHandler } from "react";
1818
import { Room } from "matrix-js-sdk/src/models/room";
1919
import { EventType, RoomType } from "matrix-js-sdk/src/@types/event";
2020
import { ISpaceSummaryRoom, ISpaceSummaryEvent } from "matrix-js-sdk/src/@types/spaces";
@@ -185,8 +185,9 @@ const Tile: React.FC<ITileProps> = ({
185185
</div>
186186
</React.Fragment>;
187187

188-
let childToggle;
189-
let childSection;
188+
let childToggle: JSX.Element;
189+
let childSection: JSX.Element;
190+
let onKeyDown: KeyboardEventHandler;
190191
if (children) {
191192
// the chevron is purposefully a div rather than a button as it should be ignored for a11y
192193
childToggle = <div
@@ -216,36 +217,41 @@ const Tile: React.FC<ITileProps> = ({
216217
{ children }
217218
</div>;
218219
}
219-
}
220220

221-
const onKeyDown = children ? (e) => {
222-
let handled = false;
221+
onKeyDown = (e) => {
222+
let handled = false;
223223

224-
switch (e.key) {
225-
case Key.ARROW_LEFT:
226-
if (showChildren) {
227-
handled = true;
228-
toggleShowChildren();
229-
}
230-
break;
224+
switch (e.key) {
225+
case Key.ARROW_LEFT:
226+
if (showChildren) {
227+
handled = true;
228+
toggleShowChildren();
229+
}
230+
break;
231231

232-
case Key.ARROW_RIGHT:
233-
handled = true;
234-
if (showChildren) {
235-
(ref.current?.nextElementSibling?.firstElementChild as HTMLElement)?.focus();
236-
} else {
237-
toggleShowChildren();
238-
}
239-
break;
240-
}
232+
case Key.ARROW_RIGHT:
233+
handled = true;
234+
if (showChildren) {
235+
const childSection = ref.current?.nextElementSibling;
236+
childSection?.querySelector<HTMLDivElement>(".mx_SpaceRoomDirectory_roomTile")?.focus();
237+
} else {
238+
toggleShowChildren();
239+
}
240+
break;
241+
}
241242

242-
if (handled) {
243-
e.preventDefault();
244-
e.stopPropagation();
245-
}
246-
} : undefined;
243+
if (handled) {
244+
e.preventDefault();
245+
e.stopPropagation();
246+
}
247+
};
248+
}
247249

248-
return <>
250+
return <li
251+
className="mx_SpaceRoomDirectory_roomTileWrapper"
252+
role="treeitem"
253+
aria-expanded={children ? showChildren : undefined}
254+
>
249255
<AccessibleButton
250256
className={classNames("mx_SpaceRoomDirectory_roomTile", {
251257
mx_SpaceRoomDirectory_subspace: room.room_type === RoomType.Space,
@@ -255,14 +261,12 @@ const Tile: React.FC<ITileProps> = ({
255261
inputRef={ref}
256262
onFocus={onFocus}
257263
tabIndex={isActive ? 0 : -1}
258-
aria-expanded={children ? showChildren : undefined}
259-
role="treeitem"
260264
>
261265
{ content }
262266
{ childToggle }
263267
</AccessibleButton>
264268
{ childSection }
265-
</>;
269+
</li>;
266270
};
267271

268272
export const showRoom = (room: ISpaceSummaryRoom, viaServers?: string[], autoJoin = false) => {

src/components/views/spaces/SpacePanel.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ const HomeButton = ({ selected, isPanelCollapsed }: IHomeButtonProps) => {
100100
return SpaceStore.instance.allRoomsInHome;
101101
});
102102

103-
return <li className={classNames("mx_SpaceItem", {
104-
"collapsed": isPanelCollapsed,
105-
})}>
103+
return <li
104+
className={classNames("mx_SpaceItem", {
105+
"collapsed": isPanelCollapsed,
106+
})}
107+
role="treeitem"
108+
>
106109
<SpaceButton
107110
className="mx_SpaceButton_home"
108111
onClick={() => SpaceStore.instance.setActiveSpace(null)}
@@ -142,9 +145,12 @@ const CreateSpaceButton = ({
142145
openMenu();
143146
};
144147

145-
return <li className={classNames("mx_SpaceItem", {
146-
"collapsed": isPanelCollapsed,
147-
})}>
148+
return <li
149+
className={classNames("mx_SpaceItem", {
150+
"collapsed": isPanelCollapsed,
151+
})}
152+
role="treeitem"
153+
>
148154
<SpaceButton
149155
className={classNames("mx_SpaceButton_new", {
150156
mx_SpaceButton_newCancel: menuDisplayed,

src/components/views/spaces/SpaceTreeLevel.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export const SpaceButton: React.FC<IButtonProps> = ({
113113
onClick={onClick}
114114
onContextMenu={openMenu}
115115
forceHide={!isNarrow || menuDisplayed}
116-
role="treeitem"
117116
inputRef={handle}
118117
>
119118
{ children }
@@ -290,7 +289,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
290289
/> : null;
291290

292291
return (
293-
<li {...otherProps} className={itemClasses} ref={innerRef}>
292+
<li {...otherProps} className={itemClasses} ref={innerRef} aria-expanded={!collapsed} role="treeitem">
294293
<SpaceButton
295294
space={space}
296295
className={isInvite ? "mx_SpaceButton_invite" : undefined}
@@ -302,9 +301,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
302301
avatarSize={isNested ? 24 : 32}
303302
onClick={this.onClick}
304303
onKeyDown={this.onKeyDown}
305-
aria-expanded={!collapsed}
306-
ContextMenuComponent={this.props.space.getMyMembership() === "join"
307-
? SpaceContextMenu : undefined}
304+
ContextMenuComponent={this.props.space.getMyMembership() === "join" ? SpaceContextMenu : undefined}
308305
>
309306
{ toggleCollapseButton }
310307
</SpaceButton>

0 commit comments

Comments
 (0)