Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 95973a6

Browse files
Fix input component react warnings (#160)
* Add pointer-events: none to index css to prevent weird react-error-overlay from breaking page https://github.com/facebook/create-react-app/issues/11773\#issuecomment-1064265775 * Return validation object separately to be more explicit about destructuring, fix existing references, use TextInputField vs. just TextInput in ExportDialog to show validationMessage
1 parent 2ed2cf4 commit 95973a6

File tree

8 files changed

+57
-53
lines changed

8 files changed

+57
-53
lines changed

src/components/change-password-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ const ChangePasswordForm: React.FC<ChangePasswordFormProps> = (
2828
const {
2929
value: password,
3030
onChange: onPasswordChange,
31-
...passwordValidation
31+
validation: passwordValidation,
3232
} = useInput({ isRequired: true });
3333

3434
const {
3535
value: passwordConfirmation,
3636
onChange: onPasswordConfirmationChange,
3737
setValidation: setPasswordConfirmationValidation,
38-
...passwordConfirmationValidation
38+
validation: passwordConfirmationValidation,
3939
} = useInput({ isRequired: true });
4040

4141
const validationTimeoutRef = useRef<NodeJS.Timeout | null>(null);

src/components/instruments/instrument-settings.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ const InstrumentSettings: React.FC<InstrumentSettingsProps> = (
8484
value: name,
8585
onChange: onNameChange,
8686
setValidation: setNameValidation,
87-
...nameValidation
87+
validation: nameValidation,
8888
} = useInput({
89-
initialValue: initialInstrument?.name ?? "",
89+
initialValue: initialInstrument?.name,
9090
});
9191
const {
9292
displayValue: releaseDisplayValue,
9393
value: release,
9494
onChange: onReleaseChange,
95-
...releaseValidation
95+
validation: releaseValidation,
9696
} = useNumberInput({
9797
initialValue:
9898
initialInstrument?.release ??
@@ -105,7 +105,7 @@ const InstrumentSettings: React.FC<InstrumentSettingsProps> = (
105105
displayValue: durationDisplayValue,
106106
value: duration,
107107
onChange: onDurationChange,
108-
...durationValidation
108+
validation: durationValidation,
109109
} = useNumberInput({
110110
initialValue: initialInstrument?.duration,
111111
allowFloating: true,

src/components/login-or-register-form.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ const LoginOrRegisterForm: React.FC<LoginOrRegisterFormProps> = (
4141
const {
4242
value: email,
4343
onChange: handleEmailChange,
44-
...emailValidation
44+
validation: emailValidation,
4545
} = useInput({
46-
initialValue: "",
4746
isRequired: true,
4847
});
4948
const {
5049
value: password,
5150
onChange: handlePasswordChange,
52-
...passwordValidation
51+
validation: passwordValidation,
5352
} = useInput({
54-
initialValue: "",
5553
isRequired: true,
5654
});
5755
const { mutate: createOrUpdateUser } = useCreateOrUpdateUser({

src/components/reset-password-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ResetPasswordForm: React.FC<ResetPasswordFormProps> = (
2222
const {
2323
value: email,
2424
onChange: handleEmailChange,
25-
...emailValidation
25+
validation: emailValidation,
2626
} = useInput({ isRequired: true });
2727
const {
2828
isLoading,

src/components/workstation/export-dialog.tsx

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77
Paragraph,
88
RecordIcon,
99
Spinner,
10-
Pane,
11-
TextInput,
12-
Label,
13-
minorScale,
10+
TextInputField,
1411
} from "evergreen-ui";
1512
import { List } from "immutable";
1613
import React, { useCallback, useMemo, useState } from "react";
@@ -30,6 +27,8 @@ import slugify from "slugify";
3027
import { unixTime } from "utils/core-utils";
3128
import { useInput } from "utils/hooks/use-input";
3229
import { isEmpty } from "lodash";
30+
import { FormField } from "components/forms/form-field";
31+
import { Flex } from "components/flex";
3332

3433
interface ExportDialogProps
3534
extends Pick<DialogProps, "isShown" | "onCloseComplete"> {}
@@ -61,7 +60,11 @@ const ExportDialog: React.FC<ExportDialogProps> = (
6160
setFalse: stopRecording,
6261
} = useBoolean();
6362

64-
const { value: fileName, ...inputProps } = useInput({
63+
const {
64+
value: fileName,
65+
onChange: handleFileNameChange,
66+
validation: fileNameValidation,
67+
} = useInput({
6568
initialValue: getDefaultFileName(state.project),
6669
isRequired: true,
6770
});
@@ -132,39 +135,36 @@ const ExportDialog: React.FC<ExportDialogProps> = (
132135
below. Recording happens in real-time, and you'll be
133136
able to download the file once complete.
134137
</Paragraph>
135-
<Pane
136-
display="flex"
137-
flexDirection="row"
138-
marginBottom={majorScale(2)}>
139-
<Pane
140-
display="flex"
141-
flexDirection="column"
142-
marginRight={majorScale(1)}
143-
width="88%">
144-
<Label marginBottom={minorScale(1)}>Name</Label>
145-
<TextInput
146-
{...inputProps}
138+
<Flex.Row>
139+
<Flex.Column marginRight={majorScale(1)} width="88%">
140+
<TextInputField
141+
label="Name"
142+
{...fileNameValidation}
143+
onChange={handleFileNameChange}
147144
value={fileName}
148145
width="100%"
149146
/>
150-
</Pane>
151-
<Pane display="flex" flexDirection="column" width="12%">
152-
<Label marginBottom={minorScale(1)}>Type</Label>
153-
<SelectMenu
154-
calculateHeight={true}
155-
closeOnSelect={true}
156-
hasFilter={false}
157-
isMultiSelect={false}
158-
onSelect={handleSelect}
159-
options={options}
160-
title="Type"
161-
width={majorScale(16)}>
162-
<Button disabled={hasFile || isRecording}>
163-
{getExtension(mimeType)}
164-
</Button>
165-
</SelectMenu>
166-
</Pane>
167-
</Pane>
147+
</Flex.Column>
148+
<Flex.Column width="12%">
149+
<FormField label="Type">
150+
<SelectMenu
151+
calculateHeight={true}
152+
closeOnSelect={true}
153+
hasFilter={false}
154+
isMultiSelect={false}
155+
onSelect={handleSelect}
156+
options={options}
157+
title="Type"
158+
width={majorScale(12)}>
159+
<Button
160+
disabled={hasFile || isRecording}
161+
width={58}>
162+
{getExtension(mimeType)}
163+
</Button>
164+
</SelectMenu>
165+
</FormField>
166+
</Flex.Column>
167+
</Flex.Row>
168168
<Button
169169
allowUnsafeHref={true}
170170
appearance={hasFile ? "primary" : "default"}

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ html {
1313
width: 100%;
1414
max-width: 100%;
1515
}
16+
17+
iframe {
18+
pointer-events: "none";
19+
}

src/utils/hooks/use-input.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ interface UseInputOptions {
88
isRequired?: boolean;
99
}
1010

11-
interface useInputResult extends ValidationState {
11+
interface useInputResult {
1212
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
1313
setValidation: (validation?: ValidationState) => void;
14+
validation: ValidationState;
1415
value?: string;
1516
}
1617

1718
const useInput = (input?: UseInputOptions): useInputResult => {
18-
const { isRequired = false, initialValue } = input ?? {};
19+
const { isRequired = false, initialValue = "" } = input ?? {};
1920
const [validation, setValidation] = useState<ValidationState | undefined>();
2021
const [value, setValue] = useState<string | undefined>(initialValue);
2122

@@ -38,7 +39,7 @@ const useInput = (input?: UseInputOptions): useInputResult => {
3839
);
3940

4041
return {
41-
...validation,
42+
validation: validation ?? {},
4243
onChange: handleChange,
4344
setValidation,
4445
value,

src/utils/hooks/use-number-input.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ interface UseNumberInputOptions {
1111
min?: number;
1212
}
1313

14-
interface UseNumberInputResult extends ValidationState {
14+
interface UseNumberInputResult {
1515
displayValue?: string;
1616
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
17-
setValidation: (validation?: ValidationState) => void;
17+
setValidation?: (validation?: ValidationState) => void;
18+
validation: ValidationState;
1819
value?: number;
1920
}
2021

@@ -30,7 +31,7 @@ const useNumberInput = (
3031
} = options ?? {};
3132
const [validation, setValidation] = useState<ValidationState | undefined>();
3233
const [displayValue, setDisplayValue] = useState<string | undefined>(
33-
initialValue?.toString()
34+
initialValue?.toString() ?? ""
3435
);
3536
const [value, setValue] = useState<number | undefined>(initialValue);
3637

@@ -77,7 +78,7 @@ const useNumberInput = (
7778
);
7879

7980
return {
80-
...validation,
81+
validation: validation ?? {},
8182
displayValue,
8283
onChange: handleChange,
8384
setValidation,

0 commit comments

Comments
 (0)