Skip to content

Commit e8991e7

Browse files
feat(file-input): Added file input component (#1613)
Added file input component Closes #1581 --------- Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent bb1ee3b commit e8991e7

20 files changed

+1211
-36
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Added
9+
- New File Input Component(`igc-file-input`)
10+
711
## [5.3.0] - 2025-03-13
812
### Added
913
- Tile manager component [#1402](https://github.com/IgniteUI/igniteui-webcomponents/pull/1402)

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"globby": "^14.1.0",
8080
"husky": "^9.1.7",
8181
"ig-typedoc-theme": "^6.0.0",
82-
"igniteui-theming": "^16.1.0",
82+
"igniteui-theming": "^17.1.0",
8383
"keep-a-changelog": "^2.6.2",
8484
"lint-staged": "^15.5.0",
8585
"lit-analyzer": "^2.0.3",

src/components/common/mixins/forms/form-value.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ export const defaultDateTimeTransformers: Partial<
5656
setFormValue: getDateFormValue,
5757
};
5858

59+
export const defaultFileListTransformer: Partial<
60+
FormValueTransformers<FileList | null>
61+
> = {
62+
setValue: (value) => value || null,
63+
getValue: (value) => value,
64+
setDefaultValue: (value) => value || null,
65+
getDefaultValue: (value) => value,
66+
setFormValue: (files: FileList | null, host: IgcFormControl) => {
67+
if (!host.name || !files) {
68+
return null;
69+
}
70+
71+
const data = new FormData();
72+
73+
for (const file of Array.from(files)) {
74+
data.append(host.name, file);
75+
}
76+
77+
return data;
78+
},
79+
};
80+
5981
/* blazorSuppress */
6082
export class FormValue<T> {
6183
private static readonly setFormValueKey = '_setFormValue' as const;

src/components/common/utils.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,37 @@ export function simulateWheel(node: Element, options?: WheelEventInit) {
357357
);
358358
}
359359

360+
/**
361+
* Simulates file upload for an input of type file.
362+
*
363+
* @param element - The custom element containing the file input
364+
* @param files - Array of File objects to upload
365+
* @param shadowRoot - Whether to look for the input in shadow DOM (default: true)
366+
* @returns Promise that resolves when element updates
367+
*/
368+
export async function simulateFileUpload(
369+
element: HTMLElement,
370+
files: File[],
371+
shadowRoot = true
372+
): Promise<void> {
373+
const input = shadowRoot
374+
? (element.shadowRoot!.querySelector(
375+
'input[type="file"]'
376+
) as HTMLInputElement)
377+
: (element.querySelector('input[type="file"]') as HTMLInputElement);
378+
379+
if (!input) {
380+
throw new Error('File input not found');
381+
}
382+
383+
const dataTransfer = new DataTransfer();
384+
files.forEach((file) => dataTransfer.items.add(file));
385+
386+
input.files = dataTransfer.files;
387+
input.dispatchEvent(new Event('change', { bubbles: true }));
388+
await elementUpdated(element);
389+
}
390+
360391
export function simulateDoubleClick(node: Element) {
361392
node.dispatchEvent(
362393
new PointerEvent('dblclick', { bubbles: true, composed: true })

0 commit comments

Comments
 (0)