Skip to content

feat(file-input): Added file input component #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7c14ba1
feat(input): add file type to the allowed types
simeonoff Mar 20, 2025
4632d91
refactor(input): don't make renderFileParts an abstract method
simeonoff Mar 20, 2025
b58829e
refactor(input): split file type input into a new component
simeonoff Mar 25, 2025
f4f4ca9
refactor(input): move file related styles to file component
simeonoff Mar 25, 2025
0bafe9e
Merge branch 'master' into simeonoff/input/file-type
simeonoff Mar 25, 2025
117c6c4
refactor(file-input): rename base css file
simeonoff Mar 25, 2025
63e6237
refactor(file-input): rename theme files
simeonoff Mar 25, 2025
f808ee2
Merge branch 'master' into simeonoff/input/file-type
simeonoff Mar 26, 2025
d29d757
spec(file-input): add missing tests and improve coverage
simeonoff Mar 26, 2025
900c1d1
refactor(file-input): remove readOnly property from component
simeonoff Mar 26, 2025
d27c6e1
refactor(file-input): hide setSelectionRange and setRangeText from docs
simeonoff Mar 26, 2025
9e3b475
Merge branch 'master' into simeonoff/input/file-type
simeonoff Mar 27, 2025
d21334d
refactor(file-input): add files to formData
simeonoff Mar 27, 2025
9a24f1e
refactor(file-input): create a form value tranformer for FileList and…
simeonoff Mar 31, 2025
edd171a
spec(file-input): add form integration tests
simeonoff Mar 31, 2025
d27b63a
Merge branch 'master' into simeonoff/input/file-type
simeonoff Mar 31, 2025
9bbdffa
refactor(file-input): check for input before assigning value
simeonoff Mar 31, 2025
ddd6855
refactor(file-input): remove unnecessary value binding
simeonoff Mar 31, 2025
ef6e796
Merge branch 'master' into simeonoff/input/file-type
rkaraivanov Apr 1, 2025
b41a3bc
refactor(file-input): address review comments
simeonoff Apr 1, 2025
fb2f485
Merge branch 'master' into simeonoff/input/file-type
simeonoff Apr 2, 2025
844204d
deps(theming): bump to latest version
simeonoff Apr 2, 2025
a831a3c
Merge branch 'master' into simeonoff/input/file-type
simeonoff Apr 2, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- New File Input Component(`igc-file-input`)

## [5.3.0] - 2025-03-13
### Added
- Tile manager component [#1402](https://github.com/IgniteUI/igniteui-webcomponents/pull/1402)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"globby": "^14.1.0",
"husky": "^9.1.7",
"ig-typedoc-theme": "^6.0.0",
"igniteui-theming": "^16.1.0",
"igniteui-theming": "^17.1.0",
"keep-a-changelog": "^2.6.2",
"lint-staged": "^15.5.0",
"lit-analyzer": "^2.0.3",
Expand Down
22 changes: 22 additions & 0 deletions src/components/common/mixins/forms/form-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ export const defaultDateTimeTransformers: Partial<
setFormValue: getDateFormValue,
};

export const defaultFileListTransformer: Partial<
FormValueTransformers<FileList | null>
> = {
setValue: (value) => value || null,
getValue: (value) => value,
setDefaultValue: (value) => value || null,
getDefaultValue: (value) => value,
setFormValue: (files: FileList | null, host: IgcFormControl) => {
if (!host.name || !files) {
return null;
}

const data = new FormData();

for (const file of Array.from(files)) {
data.append(host.name, file);
}

return data;
},
};

/* blazorSuppress */
export class FormValue<T> {
private static readonly setFormValueKey = '_setFormValue' as const;
Expand Down
31 changes: 31 additions & 0 deletions src/components/common/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,37 @@ export function simulateWheel(node: Element, options?: WheelEventInit) {
);
}

/**
* Simulates file upload for an input of type file.
*
* @param element - The custom element containing the file input
* @param files - Array of File objects to upload
* @param shadowRoot - Whether to look for the input in shadow DOM (default: true)
* @returns Promise that resolves when element updates
*/
export async function simulateFileUpload(
element: HTMLElement,
files: File[],
shadowRoot = true
): Promise<void> {
const input = shadowRoot
? (element.shadowRoot!.querySelector(
'input[type="file"]'
) as HTMLInputElement)
: (element.querySelector('input[type="file"]') as HTMLInputElement);

if (!input) {
throw new Error('File input not found');
}

const dataTransfer = new DataTransfer();
files.forEach((file) => dataTransfer.items.add(file));

input.files = dataTransfer.files;
input.dispatchEvent(new Event('change', { bubbles: true }));
await elementUpdated(element);
}

export function simulateDoubleClick(node: Element) {
node.dispatchEvent(
new PointerEvent('dblclick', { bubbles: true, composed: true })
Expand Down
Loading