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 all 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 @@ -183,6 +183,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/_HiddenBody.scss";
@import "./views/messages/_MEmoteBody.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
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;
}
37 changes: 37 additions & 0 deletions res/css/views/messages/_JumpToDatePicker.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_JumpToDatePicker_form {
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
display: flex;
}

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

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

&, & > input {
border-radius: 8px;
}
}

.mx_JumpToDatePicker_submitButton {
margin-left: 8px;
}
16 changes: 10 additions & 6 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,12 @@ 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 @@ -1133,7 +1137,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 @@ -1246,7 +1250,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 @@ -1342,7 +1346,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 Expand Up @@ -1444,7 +1448,7 @@ class HiddenEventGrouper 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
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class MessageEditHistoryDialog extends React.PureComponent<IProps
const baseEventId = this.props.mxEvent.getId();
allEvents.forEach((e, i) => {
if (!lastEvent || wantsDateSeparator(lastEvent.getDate(), e.getDate())) {
nodes.push(<li key={e.getTs() + "~"}><DateSeparator ts={e.getTs()} /></li>);
nodes.push(<li key={e.getTs() + "~"}><DateSeparator roomId={e.getRoomId()} ts={e.getTs()} /></li>);
}
const isBaseEvent = e.getId() === baseEventId;
nodes.push((
Expand Down
67 changes: 46 additions & 21 deletions src/components/views/elements/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
import React, { InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes, RefObject } from 'react';
import classNames from 'classnames';
import { debounce } from "lodash";

import * as sdk from '../../../index';
import { IFieldState, IValidationResult } from "./Validation";
import { ComponentClass } from "../../../@types/common";

// Invoke validation from user input (when typing, etc.) at most once every N ms.
const VALIDATION_THROTTLE_MS = 200;
Expand Down Expand Up @@ -78,26 +79,45 @@ interface IProps {
}

export interface IInputProps extends IProps, InputHTMLAttributes<HTMLInputElement> {
// The ref pass through to the input
inputRef?: RefObject<HTMLInputElement>;
// The element to create. Defaults to "input".
element?: "input";
componentClass?: undefined;
// The input's value. This is a controlled component, so the value is required.
value: string;
}

interface ISelectProps extends IProps, SelectHTMLAttributes<HTMLSelectElement> {
// The ref pass through to the select
inputRef?: RefObject<HTMLSelectElement>;
// To define options for a select, use <Field><option ... /></Field>
element: "select";
componentClass?: undefined;
// The select's value. This is a controlled component, so the value is required.
value: string;
}

interface ITextareaProps extends IProps, TextareaHTMLAttributes<HTMLTextAreaElement> {
// The ref pass through to the textarea
inputRef?: RefObject<HTMLTextAreaElement>;
element: "textarea";
componentClass?: undefined;
// The textarea's value. This is a controlled component, so the value is required.
value: string;
}

type PropShapes = IInputProps | ISelectProps | ITextareaProps;
export interface INativeOnChangeInputProps extends IProps, InputHTMLAttributes<HTMLInputElement> {
// The ref pass through to the input
inputRef?: RefObject<HTMLInputElement>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be able to pass through the RovingTabIndex ref to the <input>

element: "input";
// The custom component to render
componentClass: ComponentClass;
// The input's value. This is a controlled component, so the value is required.
value: string;
}

type PropShapes = IInputProps | ISelectProps | ITextareaProps | INativeOnChangeInputProps;

interface IState {
valid: boolean;
Expand All @@ -108,7 +128,7 @@ interface IState {

export default class Field extends React.PureComponent<PropShapes, IState> {
private id: string;
private input: HTMLInputElement;
private inputRef: RefObject<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>;

public static readonly defaultProps = {
element: "input",
Expand Down Expand Up @@ -146,7 +166,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
}

public focus() {
this.input.focus();
this.inputRef.current?.focus();
// programmatic does not fire onFocus handler
this.setState({
focused: true,
Expand Down Expand Up @@ -197,7 +217,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
if (!this.props.onValidate) {
return;
}
const value = this.input ? this.input.value : null;
const value = this.inputRef.current?.value ?? null;
const { valid, feedback } = await this.props.onValidate({
value,
focused,
Expand Down Expand Up @@ -228,13 +248,13 @@ export default class Field extends React.PureComponent<PropShapes, IState> {

public render() {
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
const { element, prefixComponent, postfixComponent, className, onValidate, children,
const { element, componentClass, inputRef, prefixComponent, postfixComponent, className, onValidate, children,
tooltipContent, forceValidity, tooltipClassName, list, validateOnBlur, validateOnChange, validateOnFocus,
usePlaceholderAsHint, forceTooltipVisible,
...inputProps } = this.props;

// Set some defaults for the <input> element
const ref = input => this.input = input;
this.inputRef = inputRef || React.createRef();

inputProps.placeholder = inputProps.placeholder || inputProps.label;
inputProps.id = this.id; // this overwrites the id from props

Expand All @@ -243,9 +263,9 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
inputProps.onBlur = this.onBlur;

// Appease typescript's inference
const inputProps_ = { ...inputProps, ref, list };
const inputProps_ = { ...inputProps, ref: this.inputRef, list };

const fieldInput = React.createElement(this.props.element, inputProps_, children);
const fieldInput = React.createElement(this.props.componentClass || this.props.element, inputProps_, children);

let prefixContainer = null;
if (prefixComponent) {
Expand All @@ -257,17 +277,22 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
}

const hasValidationFlag = forceValidity !== null && forceValidity !== undefined;
const fieldClasses = classNames("mx_Field", `mx_Field_${this.props.element}`, className, {
// If we have a prefix element, leave the label always at the top left and
// don't animate it, as it looks a bit clunky and would add complexity to do
// properly.
mx_Field_labelAlwaysTopLeft: prefixComponent || usePlaceholderAsHint,
mx_Field_placeholderIsHint: usePlaceholderAsHint,
mx_Field_valid: hasValidationFlag ? forceValidity : onValidate && this.state.valid === true,
mx_Field_invalid: hasValidationFlag
? !forceValidity
: onValidate && this.state.valid === false,
});
const fieldClasses = classNames(
"mx_Field",
`mx_Field_${this.props.element}`,
className,
{
// If we have a prefix element, leave the label always at the top left and
// don't animate it, as it looks a bit clunky and would add complexity to do
// properly.
mx_Field_labelAlwaysTopLeft: prefixComponent || usePlaceholderAsHint,
mx_Field_placeholderIsHint: usePlaceholderAsHint,
mx_Field_valid: hasValidationFlag ? forceValidity : onValidate && this.state.valid === true,
mx_Field_invalid: hasValidationFlag
? !forceValidity
: onValidate && this.state.valid === false,
},
);

// Handle displaying feedback on validity
// FIXME: Using an import will result in test failures
Expand Down
69 changes: 69 additions & 0 deletions src/components/views/elements/NativeOnChangeInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';

import { useCombinedRefs } from "../../../hooks/useCombinedRefs";

interface IProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onInput'> {
onChange?: (event: Event) => void;
onInput?: (event: Event) => void;
}

/**
* This component restores the native 'onChange' and 'onInput' behavior of
* JavaScript which have important differences for certain <input> types. This is
* necessary because in React, the `onChange` handler behaves like the native
* `oninput` handler and there is no way to tell the difference between an
* `input` vs `change` event.
*
* via https://stackoverflow.com/a/62383569/796832 and
* https://github.com/facebook/react/issues/9657#issuecomment-643970199
*
* See:
* - https://reactjs.org/docs/dom-elements.html#onchange
* - https://github.com/facebook/react/issues/3964
* - https://github.com/facebook/react/issues/9657
* - https://github.com/facebook/react/issues/14857
*
* Examples:
*
* We use this for the <input type="date"> date picker so we can distinguish from
* a final date picker selection (onChange) vs navigating the months in the date
* picker (onInput).
*
* This is also potentially useful for <input type="range" /> because the native
* events behave in such a way that moving the slider around triggers an onInput
* event and releasing it triggers onChange.
*/
const NativeOnChangeInput: React.FC<IProps> = React.forwardRef((props: IProps, ref) => {
const registerCallbacks = (input: HTMLInputElement | null) => {
if (input) {
input.onchange = props.onChange;
input.oninput = props.onInput;
}
};

return <input
ref={useCombinedRefs(registerCallbacks, ref)}
{...props}
// These are just here so we don't get a read-only input warning from React
onChange={() => {}}
onInput={() => {}}
/>;
});

export default NativeOnChangeInput;
Loading