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

Commit 97c99c6

Browse files
authored
Only jump to date after pressing the 'go' button (#8548)
1 parent c67b41f commit 97c99c6

File tree

4 files changed

+4
-150
lines changed

4 files changed

+4
-150
lines changed

src/components/views/elements/Field.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import classNames from 'classnames';
1919
import { debounce } from "lodash";
2020

2121
import { IFieldState, IValidationResult } from "./Validation";
22-
import { ComponentClass } from "../../../@types/common";
2322
import Tooltip from "./Tooltip";
2423

2524
// Invoke validation from user input (when typing, etc.) at most once every N ms.
@@ -83,7 +82,6 @@ export interface IInputProps extends IProps, InputHTMLAttributes<HTMLInputElemen
8382
inputRef?: RefObject<HTMLInputElement>;
8483
// The element to create. Defaults to "input".
8584
element?: "input";
86-
componentClass?: undefined;
8785
// The input's value. This is a controlled component, so the value is required.
8886
value: string;
8987
}
@@ -93,7 +91,6 @@ interface ISelectProps extends IProps, SelectHTMLAttributes<HTMLSelectElement> {
9391
inputRef?: RefObject<HTMLSelectElement>;
9492
// To define options for a select, use <Field><option ... /></Field>
9593
element: "select";
96-
componentClass?: undefined;
9794
// The select's value. This is a controlled component, so the value is required.
9895
value: string;
9996
}
@@ -102,7 +99,6 @@ interface ITextareaProps extends IProps, TextareaHTMLAttributes<HTMLTextAreaElem
10299
// The ref pass through to the textarea
103100
inputRef?: RefObject<HTMLTextAreaElement>;
104101
element: "textarea";
105-
componentClass?: undefined;
106102
// The textarea's value. This is a controlled component, so the value is required.
107103
value: string;
108104
}
@@ -111,8 +107,6 @@ export interface INativeOnChangeInputProps extends IProps, InputHTMLAttributes<H
111107
// The ref pass through to the input
112108
inputRef?: RefObject<HTMLInputElement>;
113109
element: "input";
114-
// The custom component to render
115-
componentClass: ComponentClass;
116110
// The input's value. This is a controlled component, so the value is required.
117111
value: string;
118112
}
@@ -248,7 +242,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
248242

249243
public render() {
250244
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
251-
const { element, componentClass, inputRef, prefixComponent, postfixComponent, className, onValidate, children,
245+
const { element, inputRef, prefixComponent, postfixComponent, className, onValidate, children,
252246
tooltipContent, forceValidity, tooltipClassName, list, validateOnBlur, validateOnChange, validateOnFocus,
253247
usePlaceholderAsHint, forceTooltipVisible,
254248
...inputProps } = this.props;
@@ -265,7 +259,7 @@ export default class Field extends React.PureComponent<PropShapes, IState> {
265259
// Appease typescript's inference
266260
const inputProps_ = { ...inputProps, ref: this.inputRef, list };
267261

268-
const fieldInput = React.createElement(this.props.componentClass || this.props.element, inputProps_, children);
262+
const fieldInput = React.createElement(this.props.element, inputProps_, children);
269263

270264
let prefixContainer = null;
271265
if (prefixComponent) {

src/components/views/elements/NativeOnChangeInput.tsx

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/components/views/messages/JumpToDatePicker.tsx

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import React, { useState, FormEvent } from 'react';
1818

1919
import { _t } from '../../../languageHandler';
2020
import Field from "../elements/Field";
21-
import NativeOnChangeInput from "../elements/NativeOnChangeInput";
2221
import { RovingAccessibleButton, useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
2322

2423
interface IProps {
@@ -34,41 +33,11 @@ const JumpToDatePicker: React.FC<IProps> = ({ ts, onDatePicked }: IProps) => {
3433
const dateDefaultValue = `${year}-${month}-${day}`;
3534

3635
const [dateValue, setDateValue] = useState(dateDefaultValue);
37-
// Whether or not to automatically navigate to the given date after someone
38-
// selects a day in the date picker. We want to disable this after someone
39-
// starts manually typing in the input instead of picking.
40-
const [navigateOnDatePickerSelection, setNavigateOnDatePickerSelection] = useState(true);
41-
42-
// Since we're using NativeOnChangeInput with native JavaScript behavior, this
43-
// tracks the date value changes as they come in.
44-
const onDateValueInput = (e: React.ChangeEvent<HTMLInputElement>): void => {
45-
setDateValue(e.target.value);
46-
};
47-
48-
// Since we're using NativeOnChangeInput with native JavaScript behavior, the change
49-
// event listener will trigger when a date is picked from the date picker
50-
// or when the text is fully filled out. In order to not trigger early
51-
// as someone is typing out a date, we need to disable when we see keydowns.
52-
const onDateValueChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
53-
setDateValue(e.target.value);
54-
55-
// Don't auto navigate if they were manually typing out a date
56-
if (navigateOnDatePickerSelection) {
57-
onDatePicked(dateValue);
58-
}
59-
};
60-
6136
const [onFocus, isActive, ref] = useRovingTabIndex<HTMLInputElement>();
6237

63-
const onDateInputKeyDown = (e: React.KeyboardEvent): void => {
64-
// When we see someone manually typing out a date, disable the auto
65-
// submit on change.
66-
setNavigateOnDatePickerSelection(false);
67-
};
68-
38+
const onDateValueInput = (ev: React.ChangeEvent<HTMLInputElement>) => setDateValue(ev.target.value);
6939
const onJumpToDateSubmit = (ev: FormEvent): void => {
7040
ev.preventDefault();
71-
7241
onDatePicked(dateValue);
7342
};
7443

@@ -79,11 +48,9 @@ const JumpToDatePicker: React.FC<IProps> = ({ ts, onDatePicked }: IProps) => {
7948
>
8049
<span className="mx_JumpToDatePicker_label">{ _t("Jump to date") }</span>
8150
<Field
82-
componentClass={NativeOnChangeInput}
51+
element="input"
8352
type="date"
84-
onChange={onDateValueChange}
8553
onInput={onDateValueInput}
86-
onKeyDown={onDateInputKeyDown}
8754
value={dateValue}
8855
className="mx_JumpToDatePicker_datePicker"
8956
label={_t("Pick a date to jump to")}

src/hooks/useCombinedRefs.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)