Skip to content

Commit ef52e1f

Browse files
authored
Merge pull request #758 from dxc-technology/jialecl-fileInputButtonLabel
[Minor] Adding new property to file input
2 parents e0a68e7 + 5729d67 commit ef52e1f

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
<td></td>
4444
<td>Helper text to be placed above the component.</td>
4545
</tr>
46+
<tr>
47+
<td>buttonLabel: string</td>
48+
<td>
49+
<code></code>
50+
</td>
51+
<td>
52+
Text to be placed inside the button.
53+
</td>
54+
</tr>
4655
<tr>
4756
<td>accept: string</td>
4857
<td></td>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
(callbackFile)="callback($event)"
1010
[multiple]="false"
1111
></dxc-file-input>
12+
<dxc-file-input
13+
label="Custom button label"
14+
helperText="helperText"
15+
buttonLabel="Custom button label"
16+
[showPreview]="true"
17+
margin="xsmall"
18+
(callbackFile)="callback2($event)"
19+
[multiple]="false"
20+
></dxc-file-input>
1221
<dxc-file-input
1322
label="Label"
1423
helperText="helperText"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/>
1111
<dxc-button
1212
*ngIf="mode === 'file'"
13-
label="Select files"
13+
[label]="buttonLabel"
1414
mode="secondary"
1515
[disabled]="disabled"
1616
(onClick)="fileInput.click()"
@@ -27,7 +27,7 @@
2727
(dragover)="dragOver($event)"
2828
>
2929
<dxc-button
30-
label="Select"
30+
[label]="buttonLabel"
3131
mode="secondary"
3232
[disabled]="disabled"
3333
[tabIndexValue]="tabIndexValue"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ describe("DxcFileInputComponent", () => {
3030
expect(fileInput.getByText("Helper Text"));
3131
});
3232

33+
test("should render dxc-file-input with custom buttonLabel", async () => {
34+
const fileInput = await render(DxcFileInputComponent, {
35+
componentProperties: {
36+
label: "Label",
37+
helperText: "Helper Text",
38+
buttonLabel: "Custom Button Label",
39+
},
40+
excludeComponentDeclaration: true,
41+
imports: [DxcFileInputModule],
42+
});
43+
44+
expect(fileInput.getByText("Custom Button Label"));
45+
expect(fileInput.getByText("Label"));
46+
expect(fileInput.getByText("Helper Text"));
47+
});
48+
49+
3350
test("should render dxc-file-input in file drop mode", async () => {
3451
const fileInput = await render(DxcFileInputComponent, {
3552
componentProperties: {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class DxcFileInputComponent implements OnChanges, OnInit {
4949
@Input() public name: string;
5050
@Input() public mode: string = "file";
5151
@Input() public label: string;
52+
@Input() public buttonLabel: string;
5253
@Input() public helperText: string;
5354
@Input() public value: Array<FileData>;
5455
@Input() public accept: any;
@@ -148,6 +149,21 @@ export class DxcFileInputComponent implements OnChanges, OnInit {
148149
this.hasShowError = this.isErrorShow();
149150
this.hasMultipleFiles = this.isMultipleFilesPrintables();
150151
this.hasSingleFile = this.isSingleFilesPrintables();
152+
if (!this.buttonLabel) {
153+
console.log(
154+
this.mode === "file"
155+
? this.multiple
156+
? "Select files"
157+
: "Select file"
158+
: "Select"
159+
);
160+
this.buttonLabel =
161+
this.mode === "file"
162+
? this.multiple
163+
? "Select files"
164+
: "Select file"
165+
: "Select";
166+
}
151167
this.className = `${this.getDynamicStyle(this.defaultInputs.getValue())}`;
152168
}
153169

0 commit comments

Comments
 (0)