Skip to content

Commit

Permalink
fix(input, input-number, input-text): ensure values are initialized p…
Browse files Browse the repository at this point in the history
…roperly for dist and components output targets (#8997)

**Related Issue:** #7014 

## Summary

Moves value initialization logic to `componentWillLoad` for consistent
behavior for both `dist` and `components` output targets.

**Note**: no additional tests were added since our testing setup uses
the `dist` output target.
  • Loading branch information
jcfranco authored Mar 26, 2024
1 parent 979e837 commit 9152211
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,21 +433,6 @@ export class InputNumber
connectLabel(this);
connectForm(this);

this.setPreviousEmittedNumberValue(this.value);
this.setPreviousNumberValue(this.value);

this.warnAboutInvalidNumberValue(this.value);

if (this.value === "Infinity" || this.value === "-Infinity") {
this.displayedValue = this.value;
this.previousEmittedNumberValue = this.value;
} else {
this.setNumberValue({
origin: "connected",
value: isValidNumber(this.value) ? this.value : "",
});
}

this.mutationObserver?.observe(this.el, { childList: true });
this.setDisabledAction();
this.el.addEventListener(internalHiddenInputInputEvent, this.onHiddenFormInputInput);
Expand All @@ -474,6 +459,21 @@ export class InputNumber
this.minString = this.min?.toString();
this.requestedIcon = setRequestedIcon({}, this.icon, "number");
await setUpMessages(this);

this.setPreviousEmittedNumberValue(this.value);
this.setPreviousNumberValue(this.value);

this.warnAboutInvalidNumberValue(this.value);

if (this.value === "Infinity" || this.value === "-Infinity") {
this.displayedValue = this.value;
this.previousEmittedNumberValue = this.value;
} else {
this.setNumberValue({
origin: "connected",
value: isValidNumber(this.value) ? this.value : "",
});
}
}

componentShouldUpdate(newValue: string, oldValue: string, property: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ export class InputText
if (this.inlineEditableEl) {
this.editingEnabled = this.inlineEditableEl.editingEnabled || false;
}
this.setPreviousEmittedValue(this.value);
this.setPreviousValue(this.value);

connectLabel(this);
connectForm(this);
Expand All @@ -349,6 +347,9 @@ export class InputText
setUpLoadableComponent(this);
this.requestedIcon = setRequestedIcon({}, this.icon, "text");
await setUpMessages(this);

this.setPreviousEmittedValue(this.value);
this.setPreviousValue(this.value);
}

componentDidLoad(): void {
Expand Down
32 changes: 16 additions & 16 deletions packages/calcite-components/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,22 +487,6 @@ export class Input
connectLabel(this);
connectForm(this);

this.setPreviousEmittedValue(this.value);
this.setPreviousValue(this.value);

if (this.type === "number") {
if (this.value === "Infinity" || this.value === "-Infinity") {
this.displayedValue = this.value;
this.previousEmittedValue = this.value;
} else {
this.warnAboutInvalidNumberValue(this.value);
this.setValue({
origin: "connected",
value: isValidNumber(this.value) ? this.value : "",
});
}
}

this.mutationObserver?.observe(this.el, { childList: true });

this.setDisabledAction();
Expand All @@ -527,6 +511,22 @@ export class Input
this.minString = this.min?.toString();
this.requestedIcon = setRequestedIcon(INPUT_TYPE_ICONS, this.icon, this.type);
await setUpMessages(this);

this.setPreviousEmittedValue(this.value);
this.setPreviousValue(this.value);

if (this.type === "number") {
if (this.value === "Infinity" || this.value === "-Infinity") {
this.displayedValue = this.value;
this.previousEmittedValue = this.value;
} else {
this.warnAboutInvalidNumberValue(this.value);
this.setValue({
origin: "connected",
value: isValidNumber(this.value) ? this.value : "",
});
}
}
}

componentDidLoad(): void {
Expand Down

0 comments on commit 9152211

Please sign in to comment.