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

Add jump to date functionality to date headers in timeline v2 #7339

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7dfbe7a
Fix room list roving treeview
t3chguy Dec 10, 2021
e6e7885
Fix programmatic focus management in roving tab index not triggering …
t3chguy Dec 10, 2021
08b1fdb
Fix toolbar no longer handling left & right arrows
t3chguy Dec 10, 2021
7c226b9
Fix roving tab index focus tracking on interactive element like conte…
t3chguy Dec 10, 2021
4ddc97d
Fix thread list context menu roving
t3chguy Dec 10, 2021
459f155
add comment
t3chguy Dec 10, 2021
1784b44
fix comment
t3chguy Dec 10, 2021
b061c94
Copy Jump to Date PoC changes on top of RovingTabIndex fixes
MadLittleMods Dec 11, 2021
9cc435a
RovingTabIndex in ContextMenu
MadLittleMods Dec 11, 2021
688314b
Refactor JumpToDatePicker form out to functional component so we can …
MadLittleMods Dec 11, 2021
9ad8868
DatePicker only keyboard navigable when item focused
MadLittleMods Dec 11, 2021
2985888
Fix date picker form focus
MadLittleMods Dec 11, 2021
423fb93
Clean up PR
MadLittleMods Dec 11, 2021
312af82
More cleanup
MadLittleMods Dec 11, 2021
64eef3a
Fix handling vertical arrows in the wrong direction
t3chguy Dec 13, 2021
6ce0798
iterate PR
t3chguy Dec 13, 2021
d82dbf6
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 13, 2021
2d0475d
delint
t3chguy Dec 14, 2021
254e1f3
Merge branch 't3chguy/a11y2' into madlittlemods/msc3030-jump-to-date-…
MadLittleMods Dec 14, 2021
3f1271b
Fix conflit
MadLittleMods Dec 14, 2021
4d5f9b3
Fix missing ref when opening emoji reaction menu
MadLittleMods Dec 14, 2021
3352183
Restore focuslock for now
MadLittleMods Dec 14, 2021
1ce394f
Restore changes back to MessageActionBar
MadLittleMods Dec 14, 2021
5ec17b0
Remove from diff
MadLittleMods Dec 18, 2021
2b0fdd1
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 11, 2022
9034f2c
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 11, 2022
3b2f2b5
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 14, 2022
61f6436
WIP: RovingTabIndex shared ref on CustomInput
MadLittleMods Jan 14, 2022
86c7baf
Use Field with CustomInput passed through
MadLittleMods Jan 15, 2022
9513731
Clean up PR and add behind feature flag
MadLittleMods Jan 15, 2022
4ff3032
More cleanup
MadLittleMods Jan 15, 2022
d3bc14d
Restore tabindex because jump to date menu is still keyboard navigabl…
MadLittleMods Jan 15, 2022
87c1798
Revert random yarn.lock changes
MadLittleMods Jan 15, 2022
9acd854
Fix lints
MadLittleMods Jan 15, 2022
8c2488f
Add snapshot test when jump to date is enabled
MadLittleMods Jan 15, 2022
c408443
Fix lints
MadLittleMods Jan 15, 2022
5fb3c0b
Update i18n
MadLittleMods Jan 15, 2022
246b763
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 17, 2022
4494f68
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 19, 2022
24534e8
Make border-radius on input match button
MadLittleMods Jan 25, 2022
726a569
Add copyright headers
MadLittleMods Jan 25, 2022
20939a2
Just use simple back 7 days logic
MadLittleMods Jan 25, 2022
5f98026
Some CustomInput cleanup
MadLittleMods Jan 25, 2022
01101a2
Use props.componentClass to define something custom
MadLittleMods Jan 25, 2022
128ad8e
Fix camelCase typo
MadLittleMods Jan 25, 2022
26301ea
Update labs flag to explain what else is added
MadLittleMods Jan 25, 2022
ee4829f
Remove unrecognized prop from being passed on to the inner element
MadLittleMods Jan 25, 2022
e34a977
Add explicit member access
MadLittleMods Jan 25, 2022
7ed9549
Remove unused styles now that other selects are less leaky
MadLittleMods Jan 25, 2022
fc789bf
Use semantic form submit button which makes the enter interaction wor…
MadLittleMods Jan 25, 2022
cbc496d
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 25, 2022
349c4ad
Fix lint
MadLittleMods Jan 25, 2022
9a6befa
Rename input to be self descriptive
MadLittleMods Jan 25, 2022
8782b1b
Fix some naming
MadLittleMods Jan 25, 2022
8600314
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 25, 2022
9efe04f
Merge branch 'develop' into madlittlemods/msc3030-jump-to-date-header…
MadLittleMods Jan 27, 2022
0a79ddb
Fix roomId missing after develop merge
MadLittleMods Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
@import "./views/messages/_CallEvent.scss";
@import "./views/messages/_CreateEvent.scss";
@import "./views/messages/_DateSeparator.scss";
@import "./views/messages/_JumpToDatePicker.scss";
@import "./views/messages/_EventTileBubble.scss";
@import "./views/messages/_MEmoteBody.scss";
@import "./views/messages/_MFileBody.scss";
Expand Down
12 changes: 6 additions & 6 deletions res/css/views/context_menus/_IconizedContextMenu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ limitations under the License.
}

// round the top corners of the top button for the hover effect to be bounded
&:first-child .mx_AccessibleButton:first-child {
&:first-child .mx_AccessibleButton:not(.mx_AccessibleButton_hasKind):first-child {
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
border-radius: 8px 8px 0 0; // radius matches .mx_ContextualMenu
}

// round the bottom corners of the bottom button for the hover effect to be bounded
&:last-child .mx_AccessibleButton:last-child {
&:last-child .mx_AccessibleButton:not(.mx_AccessibleButton_hasKind):last-child {
border-radius: 0 0 8px 8px; // radius matches .mx_ContextualMenu
}

// round all corners of the only button for the hover effect to be bounded
&:first-child:last-child .mx_AccessibleButton:first-child:last-child {
&:first-child:last-child .mx_AccessibleButton:not(.mx_AccessibleButton_hasKind):first-child:last-child {
border-radius: 8px; // radius matches .mx_ContextualMenu
}

.mx_AccessibleButton {
.mx_AccessibleButton:not(.mx_AccessibleButton_hasKind) {
// pad the inside of the button so that the hover background is padded too
padding-top: 12px;
padding-bottom: 12px;
Expand Down Expand Up @@ -130,7 +130,7 @@ limitations under the License.
}

.mx_IconizedContextMenu_optionList_red {
.mx_AccessibleButton {
.mx_AccessibleButton:not(.mx_AccessibleButton_hasKind) {
color: $alert !important;
}

Expand All @@ -148,7 +148,7 @@ limitations under the License.
}

.mx_IconizedContextMenu_active {
&.mx_AccessibleButton, .mx_AccessibleButton {
&.mx_AccessibleButton:not(.mx_AccessibleButton_hasKind), .mx_AccessibleButton:not(.mx_AccessibleButton_hasKind) {
color: $accent !important;
}

Expand Down
1 change: 1 addition & 0 deletions res/css/views/elements/_Field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ limitations under the License.
transform 0.25s ease-out 0s,
background-color 0.25s ease-out 0s;
font-size: $font-10px;
line-height: normal;
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
transform: translateY(-13px);
padding: 0 2px;
background-color: $background;
Expand Down
15 changes: 15 additions & 0 deletions res/css/views/messages/_DateSeparator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ limitations under the License.
margin: 0 25px;
flex: 0 0 auto;
}

.mx_DateSeparator_jumpToDateMenu {
display: flex;
}

.mx_DateSeparator_chevron {
align-self: center;
width: 16px;
height: 16px;
mask-position: center;
mask-size: contain;
mask-repeat: no-repeat;
mask-image: url('$(res)/img/feather-customised/chevron-down.svg');
background-color: $tertiary-content;
}
17 changes: 17 additions & 0 deletions res/css/views/messages/_JumpToDatePicker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.mx_JumpToDatePicker_form {
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
align-items: center;
}

.mx_JumpToDatePicker_label {
font-size: $font-15px;
}

.mx_JumpToDatePicker_datePicker {
margin: 0;
margin-left: 8px;
}

.mx_JumpToDatePicker_submitButton {
margin-left: 8px;
}
25 changes: 19 additions & 6 deletions src/accessibility/RovingTabIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const reducer = (state: IState, action: IAction) => {
}

case Type.SetFocus: {
if (state.activeRef === action.payload.ref) return state;
// update active ref
state.activeRef = action.payload.ref;
return { ...state };
Expand Down Expand Up @@ -194,6 +195,7 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({
}

let handled = false;
let focusRef: RefObject<HTMLElement>;
// Don't interfere with input default keydown behaviour
if (ev.target.tagName !== "INPUT" && ev.target.tagName !== "TEXTAREA") {
// check if we actually have any items
Expand All @@ -202,15 +204,15 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({
if (handleHomeEnd) {
handled = true;
// move focus to first (visible) item
findSiblingElement(context.state.refs, 0)?.current?.focus();
focusRef = findSiblingElement(context.state.refs, 0);
}
break;

case Key.END:
if (handleHomeEnd) {
handled = true;
// move focus to last (visible) item
findSiblingElement(context.state.refs, context.state.refs.length - 1, true)?.current?.focus();
focusRef = findSiblingElement(context.state.refs, context.state.refs.length - 1, true);
}
break;

Expand All @@ -220,7 +222,7 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({
handled = true;
if (context.state.refs.length > 0) {
const idx = context.state.refs.indexOf(context.state.activeRef);
findSiblingElement(context.state.refs, idx - 1)?.current?.focus();
focusRef = findSiblingElement(context.state.refs, idx + 1);
}
}
break;
Expand All @@ -231,7 +233,7 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({
handled = true;
if (context.state.refs.length > 0) {
const idx = context.state.refs.indexOf(context.state.activeRef);
findSiblingElement(context.state.refs, idx + 1, true)?.current?.focus();
focusRef = findSiblingElement(context.state.refs, idx - 1, true);
}
}
break;
Expand All @@ -242,7 +244,18 @@ export const RovingTabIndexProvider: React.FC<IProps> = ({
ev.preventDefault();
ev.stopPropagation();
}
}, [context.state, onKeyDown, handleHomeEnd, handleUpDown, handleLeftRight]);

if (focusRef) {
focusRef.current?.focus();
// programmatic focus doesn't fire the onFocus handler, so we must do the do ourselves
dispatch({
type: Type.SetFocus,
payload: {
ref: focusRef,
},
});
}
}, [context, onKeyDown, handleHomeEnd, handleUpDown, handleLeftRight]);

return <RovingTabIndexContext.Provider value={context}>
{ children({ onKeyDownHandler }) }
Expand Down Expand Up @@ -283,7 +296,7 @@ export const useRovingTabIndex = (inputRef?: Ref): [FocusHandler, boolean, Ref]
type: Type.SetFocus,
payload: { ref },
});
}, [ref, context]);
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const isActive = context.state.activeRef === ref;
return [onFocus, isActive, ref];
Expand Down
2 changes: 1 addition & 1 deletion src/accessibility/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Toolbar: React.FC<IProps> = ({ children, ...props }) => {
}
};

return <RovingTabIndexProvider handleHomeEnd={true} onKeyDown={onKeyDown}>
return <RovingTabIndexProvider handleHomeEnd handleLeftRight onKeyDown={onKeyDown}>
{ ({ onKeyDownHandler }) => <div {...props} onKeyDown={onKeyDownHandler} role="toolbar">
{ children }
</div> }
Expand Down
13 changes: 6 additions & 7 deletions src/accessibility/context_menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ limitations under the License.

import React from "react";

import AccessibleButton from "../../components/views/elements/AccessibleButton";
import AccessibleTooltipButton from "../../components/views/elements/AccessibleTooltipButton";
import { RovingAccessibleButton, RovingAccessibleTooltipButton } from "../RovingTabIndex";

interface IProps extends React.ComponentProps<typeof AccessibleButton> {
interface IProps extends React.ComponentProps<typeof RovingAccessibleButton> {
label?: string;
tooltip?: string;
}
Expand All @@ -31,15 +30,15 @@ export const MenuItem: React.FC<IProps> = ({ children, label, tooltip, ...props
const ariaLabel = props["aria-label"] || label;

if (tooltip) {
return <AccessibleTooltipButton {...props} role="menuitem" tabIndex={-1} aria-label={ariaLabel} title={tooltip}>
return <RovingAccessibleTooltipButton {...props} role="menuitem" aria-label={ariaLabel} title={tooltip}>
{ children }
</AccessibleTooltipButton>;
</RovingAccessibleTooltipButton>;
}

return (
<AccessibleButton {...props} role="menuitem" tabIndex={-1} aria-label={ariaLabel}>
<RovingAccessibleButton {...props} role="menuitem" aria-label={ariaLabel}>
{ children }
</AccessibleButton>
</RovingAccessibleButton>
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
);
};

98 changes: 25 additions & 73 deletions src/components/structures/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ limitations under the License.
import React, { CSSProperties, RefObject, SyntheticEvent, useRef, useState } from "react";
import ReactDOM from "react-dom";
import classNames from "classnames";
import FocusLock from "react-focus-lock";

import { Key } from "../../Keyboard";
import { Writeable } from "../../@types/common";
import { replaceableComponent } from "../../utils/replaceableComponent";
import UIStore from "../../stores/UIStore";
import { getInputableElement } from "./LoggedInView";
import { RovingTabIndexProvider } from "../../accessibility/RovingTabIndex";

// Shamelessly ripped off Modal.js. There's probably a better way
// of doing reusable widgets like dialog boxes & menus where we go and
Expand Down Expand Up @@ -86,10 +86,6 @@ export interface IProps extends IPosition {
// it will be mounted to a container at the root of the DOM.
mountAsChild?: boolean;

// If specified, contents will be wrapped in a FocusLock, this is only needed if the context menu is being rendered
// within an existing FocusLock e.g inside a modal.
focusLock?: boolean;

// Function to be called on menu close
onFinished();
// on resize callback
Expand Down Expand Up @@ -238,52 +234,10 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
};

private onKeyDown = (ev: React.KeyboardEvent) => {
// don't let keyboard handling escape the context menu
ev.stopPropagation();

if (!this.props.managed) {
if (ev.key === Key.ESCAPE) {
this.props.onFinished();
ev.preventDefault();
}
return;
}

// only handle escape when in an input field
if (ev.key !== Key.ESCAPE && getInputableElement(ev.target as HTMLElement)) return;

let handled = true;

switch (ev.key) {
// XXX: this is imitating roving behaviour, it should really use the RovingTabIndex utils
// to inherit proper handling of unmount edge cases
case Key.TAB:
case Key.ESCAPE:
case Key.ARROW_LEFT: // close on left and right arrows too for when it is a context menu on a <Toolbar />
case Key.ARROW_RIGHT:
this.props.onFinished();
break;
case Key.ARROW_UP:
this.onMoveFocus(ev.target as Element, true);
break;
case Key.ARROW_DOWN:
this.onMoveFocus(ev.target as Element, false);
break;
case Key.HOME:
this.onMoveFocusHomeEnd(this.state.contextMenuElem, true);
break;
case Key.END:
this.onMoveFocusHomeEnd(this.state.contextMenuElem, false);
break;
default:
handled = false;
}

if (handled) {
// consume all other keys in context menu
ev.preventDefault();
if (ev.key === Key.TAB || ev.key === Key.ESCAPE) {
this.props.onFinished();
}
};
}

protected renderMenu(hasBackground = this.props.hasBackground) {
const position: Partial<Writeable<DOMRect>> = {};
Expand Down Expand Up @@ -401,30 +355,28 @@ export default class ContextMenu extends React.PureComponent<IProps, IState> {
{ props.children }
</>;

if (props.focusLock) {
body = <FocusLock>
{ body }
</FocusLock>;
}

return (
<div
className={classNames("mx_ContextualMenu_wrapper", this.props.wrapperClassName)}
style={{ ...position, ...wrapperStyle }}
onKeyDown={this.onKeyDown}
onClick={this.onClick}
onContextMenu={this.onContextMenuPreventBubbling}
>
{ background }
<div
className={menuClasses}
style={menuStyle}
ref={this.collectContextMenuRect}
role={this.props.managed ? "menu" : undefined}
>
{ body }
</div>
</div>
<RovingTabIndexProvider handleHomeEnd handleUpDown onKeyDown={this.onKeyDown}>
{ ({ onKeyDownHandler }) => (
<div
className={classNames("mx_ContextualMenu_wrapper", this.props.wrapperClassName)}
style={{ ...position, ...wrapperStyle }}
onClick={this.onClick}
onKeyDown={onKeyDownHandler}
onContextMenu={this.onContextMenuPreventBubbling}
>
{ background }
<div
className={menuClasses}
style={menuStyle}
ref={this.collectContextMenuRect}
role={this.props.managed ? "menu" : undefined}
>
{ body }
</div>
</div>
) }
</RovingTabIndexProvider>
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ export default class MessagePanel extends React.Component<IProps, IState> {

// do we need a date separator since the last event?
const wantsDateSeparator = this.wantsDateSeparator(prevEvent, eventDate);
if (wantsDateSeparator && !isGrouped) {
const dateSeparator = <li key={ts1}><DateSeparator key={ts1} ts={ts1} /></li>;
if (wantsDateSeparator && !isGrouped && this.props.room) {
const dateSeparator = <li key={ts1}><DateSeparator key={ts1} roomId={this.props.room.roomId} ts={ts1} /></li>;
ret.push(dateSeparator);
}

Expand Down Expand Up @@ -1109,7 +1109,7 @@ class CreationGrouper extends BaseGrouper {
if (panel.wantsDateSeparator(this.prevEvent, createEvent.getDate())) {
const ts = createEvent.getTs();
ret.push(
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
<li key={ts+'~'}><DateSeparator key={ts+'~'} roomId={createEvent.getRoomId()} ts={ts} /></li>,
);
}

Expand Down Expand Up @@ -1222,7 +1222,7 @@ class RedactionGrouper extends BaseGrouper {
if (panel.wantsDateSeparator(this.prevEvent, this.events[0].getDate())) {
const ts = this.events[0].getTs();
ret.push(
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
<li key={ts+'~'}><DateSeparator key={ts+'~'} roomId={this.events[0].getRoomId()} ts={ts} /></li>,
);
}

Expand Down Expand Up @@ -1318,7 +1318,7 @@ class MemberGrouper extends BaseGrouper {
if (panel.wantsDateSeparator(this.prevEvent, this.events[0].getDate())) {
const ts = this.events[0].getTs();
ret.push(
<li key={ts+'~'}><DateSeparator key={ts+'~'} ts={ts} /></li>,
<li key={ts+'~'}><DateSeparator key={ts+'~'} roomId={this.events[0].getRoomId()} ts={ts} /></li>,
);
}

Expand Down
Loading