Skip to content

Commit f707a45

Browse files
committed
Improve InputElement.ts
1 parent 2b57364 commit f707a45

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

packages/react-form-with-constraints-tools/src/DisplayFields.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
FieldFeedbackType,
1010
FormWithConstraints,
1111
FormWithConstraintsChildContext,
12-
HTMLInput,
13-
isHTMLInput,
14-
TextInput
12+
isHTMLInput
1513
} from 'react-form-with-constraints';
1614

1715
// Before:
@@ -74,9 +72,7 @@ function normalizeFieldElementProperty(fields: Field[]) {
7472
const { element, ...otherProps } = field;
7573
return element
7674
? {
77-
element: isHTMLInput(element)
78-
? (element as HTMLInput).outerHTML
79-
: (element as TextInput).props,
75+
element: isHTMLInput(element) ? element.outerHTML : element.props,
8076
...otherProps
8177
}
8278
: field;

packages/react-form-with-constraints/src/InputElement.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface IHTMLInput {
5656
readonly validationMessage: string;
5757
}
5858

59-
export function isHTMLInput(input: IHTMLInput | TextInput) {
59+
export function isHTMLInput(input: IHTMLInput | TextInput): input is IHTMLInput {
6060
return (input as any).props === undefined;
6161
}
6262

@@ -72,10 +72,6 @@ export class InputElement implements IHTMLInput {
7272

7373
constructor(input: IHTMLInput | TextInput) {
7474
if (isHTMLInput(input)) {
75-
// FIXME
76-
// eslint-disable-next-line no-param-reassign
77-
input = input as IHTMLInput;
78-
7975
this.name = input.name;
8076
this.type = input.type;
8177
this.value = input.value;
@@ -91,13 +87,9 @@ export class InputElement implements IHTMLInput {
9187

9288
this.validationMessage = input.validationMessage;
9389
} else {
94-
// FIXME
95-
// eslint-disable-next-line no-param-reassign
96-
input = input as TextInput;
97-
98-
this.name = input.props!.name;
90+
this.name = input.props.name;
9991
this.type = undefined as any;
100-
this.value = input.props!.value!; // Tested: TextInput props.value is always a string and never undefined (empty string instead)
92+
this.value = input.props.value!; // Tested: TextInput props.value is always a string and never undefined (empty string instead)
10193
this.validity = undefined as any;
10294
this.validationMessage = undefined as any;
10395
}

0 commit comments

Comments
 (0)