Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
the value will be managed internally by the component.
</td>
</tr>
<tr>
<td>defaultValue: string</td>
<td></td>
<td>Initial value of the input, only when it is uncontrolled.</td>
</tr>
<tr>
<td>label: string</td>
<td></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
margin="xsmall"
[suggestions]="options"
(onActionClick)="click()"
defaultValue="default value"
>
<dxc-text-input-prefix value="+34"></dxc-text-input-prefix>
<dxc-text-input-suffix value="$"></dxc-text-input-suffix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ describe("DxcNewTextInputComponent", () => {
});
});

test("uncontrolled with defaultValue", async () => {
const onChange = jest.fn();
const onBlur = jest.fn();
await render(DxcTextInputComponent, {
componentProperties: {
label: "Input label",
defaultValue: "Default value",
},
imports: [CommonModule, FormsModule],
providers: [DxcTextInputService],
declarations: [FilterOptionsPipe, BoldOptionsPipe],
});

const input = <HTMLInputElement>screen.getByRole("textbox");
input.focus();
fireEvent.click(input);
expect(screen.getByDisplayValue("Default value"));
fireEvent.input(input, { target: { value: "new value" } });
await waitFor(() => {
expect(screen.getByDisplayValue("new value"));
});
});

test("controlled dxc-input-text input with clear, change and blur", async () => {
const onChange = jest.fn();
const onBlur = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class DxcTextInputComponent
@Input()
value: string;

@Input()
defaultValue: string;

@Input()
id: string;

Expand Down Expand Up @@ -223,7 +226,7 @@ export class DxcTextInputComponent
validationError: this.validationError,
})}`;
if (this.value === undefined) {
this.value = "";
this.defaultValue ? (this.value = this.defaultValue) : (this.value = "");
this.controlled = false;
} else {
this.controlled = true;
Expand Down