Skip to content

Commit d3a28b6

Browse files
authored
Merge pull request #826 from dxc-technology/fix-762
[Minor] Added new prop defaultValue in date input
2 parents ac10ab6 + 1c2400a commit d3a28b6

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

projects/dxc-ngx-cdk-site/src/app/components/examples/date-input/date-properties/date-properties.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
uncontrolled and the value will be managed internally by the component.
1919
</td>
2020
</tr>
21+
<tr>
22+
<td>defaultValue: string</td>
23+
<td></td>
24+
<td>Initial value of the date input, only when it is uncontrolled.</td>
25+
</tr>
2126
<tr>
2227
<td>label: string</td>
2328
<td></td>

projects/dxc-ngx-cdk-site/src/app/pages/theme-builder/previews/date-input-preview/date-input-preview.component.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22
<dxc-heading text="Light Mode" [level]="5" margin="xsmall"></dxc-heading>
33
<background-provider color="#FFFFFF">
44
<tbuilder-component-mode text="Default">
5-
<dxc-date-input label="Date of birth" format="dd-MM-yyyy" margin="xsmall" helperText="helper text">
5+
<dxc-date-input
6+
defaultValue="04-10-1996"
7+
value="22-10-1996"
8+
label="Date of birth"
9+
format="dd-MM-yyyy"
10+
margin="xsmall"
11+
helperText="helper text"
12+
>
613
</dxc-date-input>
714
</tbuilder-component-mode>
815

916
<tbuilder-component-mode text="Disabled">
10-
<dxc-date-input label="Date of birth" format="dd-MM-yyyy" margin="xsmall" helperText="helper text" disabled>
17+
<dxc-date-input
18+
label="Date of birth"
19+
format="dd-MM-yyyy"
20+
margin="xsmall"
21+
helperText="helper text"
22+
disabled
23+
>
1124
</dxc-date-input>
1225
</tbuilder-component-mode>
1326

1427
<tbuilder-component-mode text="Error">
15-
<dxc-date-input label="Date of birth" format="dd-MM-yyyy" margin="xsmall" helperText="helper text"
16-
error="Error date">
28+
<dxc-date-input
29+
label="Date of birth"
30+
format="dd-MM-yyyy"
31+
margin="xsmall"
32+
helperText="helper text"
33+
error="Error date"
34+
>
1735
</dxc-date-input>
1836
</tbuilder-component-mode>
1937
</background-provider>

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<dxc-text-input
22
#dxcInput
33
[value]="renderedValue"
4+
[defaultValue]="defaultValue"
45
[clearable]="clearable"
56
[error]="error"
67
[label]="label"

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.component.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ describe("DxcDate", () => {
150150
await render(DxcDateInputComponent, {
151151
componentProperties: {
152152
label: "test-input",
153+
defaultValue: "22-10-1998",
153154
onChange: {
154155
emit: onChange,
155156
} as any,
@@ -173,7 +174,7 @@ describe("DxcDate", () => {
173174
},
174175
],
175176
});
176-
177+
expect(screen.getByDisplayValue("22-10-1998"));
177178
const input = <HTMLInputElement>screen.getByRole("textbox");
178179
input.focus();
179180
fireEvent.input(input, { target: { value: newValue } });
@@ -446,6 +447,7 @@ describe("DxcDate", () => {
446447
componentProperties: {
447448
label: "test-input",
448449
value: "03-12-1995",
450+
defaultValue: "12-04-1995",
449451
onChange: {
450452
emit: onChange,
451453
} as any,
@@ -472,6 +474,7 @@ describe("DxcDate", () => {
472474
},
473475
],
474476
});
477+
expect(screen.getByDisplayValue("03-12-1995"));
475478
const input = <HTMLInputElement>screen.getByRole("textbox");
476479

477480
input.focus();

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727
Spacing,
2828
} from "./dxc-date-input.types";
2929

30-
31-
3230
@Component({
3331
selector: "dxc-date-input",
3432
templateUrl: "./dxc-date-input.component.html",
@@ -49,6 +47,10 @@ export class DxcDateInputComponent implements OnInit {
4947
* Value of the input element. If undefined, the component will be uncontrolled and the value will be managed internally by the component.
5048
*/
5149
@Input() value: string;
50+
/**
51+
* Initial value of the date input, only when it is uncontrolled.
52+
*/
53+
@Input() defaultValue: string;
5254
/**
5355
* Helper text to be placed above the date.
5456
*/
@@ -140,6 +142,7 @@ export class DxcDateInputComponent implements OnInit {
140142
tabIndexValue: 0,
141143
placeholder: false,
142144
autocomplete: "off",
145+
defaultValue: undefined,
143146
});
144147

145148
/**

projects/dxc-ngx-cdk/src/lib/dxc-date-input/dxc-date-input.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface DateInputProperties {
1313
size?: "medium" | "large" | "fillParent";
1414
tabIndexValue?: number;
1515
autocomplete?: string;
16+
defaultValue?: string;
1617
}
1718

1819
export type Space =

0 commit comments

Comments
 (0)