Skip to content

Commit 3767d61

Browse files
authored
refactor(file-input): Changed custom events return type (#1744)
Both `igcChange` and `igcCancel` will now return the file input `files` property (a FileList instance) as an event argument.
1 parent 2db4363 commit 3767d61

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
- Date Range Picker
1010

1111
### Changed
12+
- #### File input
13+
- **Breaking change**: `igcChange` & `igcCancel` events detail now returns the underlying component `files` property.
1214
- #### Tooltip
1315
- **Behavioral change**: Tooltip default `placement` is 'bottom' now.
1416
- **Behavioral change**: Tooltip will not render an arrow indicator by default unless `with-arrow` is set.

src/components/file-input/file-input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('File Input component', () => {
158158
await elementUpdated(element);
159159

160160
expect(eventSpy).calledWith('igcChange', {
161-
detail: element.value,
161+
detail: input.files,
162162
});
163163
});
164164

@@ -169,7 +169,7 @@ describe('File Input component', () => {
169169
await elementUpdated(element);
170170

171171
expect(eventSpy).calledOnceWith('igcCancel', {
172-
detail: element.value,
172+
detail: input.files,
173173
});
174174
});
175175

src/components/file-input/file-input.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ import { ifDefined } from 'lit/directives/if-defined.js';
55
import { themes } from '../../theming/theming-decorator.js';
66
import IgcButtonComponent from '../button/button.js';
77
import { registerComponent } from '../common/definitions/register.js';
8+
import type { AbstractConstructor } from '../common/mixins/constructor.js';
9+
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
810
import {
911
type FormValueOf,
1012
createFormValueState,
1113
defaultFileListTransformer,
1214
} from '../common/mixins/forms/form-value.js';
1315
import { partMap } from '../common/part-map.js';
1416
import { isEmpty } from '../common/util.js';
15-
import { IgcInputBaseComponent } from '../input/input-base.js';
17+
import {
18+
IgcInputBaseComponent,
19+
type IgcInputComponentEventMap,
20+
} from '../input/input-base.js';
1621
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
1722
import { styles } from './themes/file-input.base.css.js';
1823
import { all } from './themes/themes.js';
1924
import { fileValidators } from './validators.js';
2025

26+
export interface IgcFileInputComponentEventMap
27+
extends Omit<IgcInputComponentEventMap, 'igcChange' | 'igcInput'> {
28+
igcCancel: CustomEvent<FileList>;
29+
igcChange: CustomEvent<FileList>;
30+
}
31+
2132
/* blazorSuppress */
2233
/**
2334
* @element igc-file-input
@@ -45,9 +56,12 @@ import { fileValidators } from './validators.js';
4556
* @csspart helper-text - The helper text wrapper.
4657
*/
4758
@themes(all)
48-
export default class IgcFileInputComponent extends IgcInputBaseComponent {
59+
export default class IgcFileInputComponent extends EventEmitterMixin<
60+
IgcFileInputComponentEventMap,
61+
AbstractConstructor<IgcInputBaseComponent>
62+
>(IgcInputBaseComponent) {
4963
public static readonly tagName = 'igc-file-input';
50-
public static override styles = [...IgcInputBaseComponent.styles, styles];
64+
public static styles = [...IgcInputBaseComponent.styles, styles];
5165

5266
/* blazorSuppress */
5367
public static register(): void {
@@ -152,15 +166,15 @@ export default class IgcFileInputComponent extends IgcInputBaseComponent {
152166
this._validate();
153167

154168
this.requestUpdate();
155-
this.emitEvent('igcChange', { detail: this.value });
169+
this.emitEvent('igcChange', { detail: this.files! });
156170
}
157171

158172
private _handleCancel(): void {
159173
this._hasActivation = false;
160174
this._validate();
161175

162176
this.emitEvent('igcCancel', {
163-
detail: this.value,
177+
detail: this.files!,
164178
});
165179
}
166180

src/components/input/input-base.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export interface IgcInputComponentEventMap {
1919
igcInput: CustomEvent<string>;
2020
/* blazorSuppress */
2121
igcChange: CustomEvent<string>;
22-
/* blazorSuppress */
23-
igcCancel: CustomEvent<string>;
2422
// For analyzer meta only:
2523
/* skipWCPrefix */
2624
focus: FocusEvent;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export type { IgcDropdownComponentEventMap } from './components/dropdown/dropdow
106106
export type { IgcExpansionPanelComponentEventMap } from './components/expansion-panel/expansion-panel.js';
107107
export type { IgcInputComponentEventMap } from './components/input/input-base.js';
108108
export type { IgcInputComponentEventMap as IgcMaskInputComponentEventMap } from './components/input/input-base.js';
109-
export type { IgcInputComponentEventMap as IgcFileInputComponentEventMap } from './components/input/input-base.js';
109+
export type { IgcFileInputComponentEventMap } from './components/file-input/file-input.js';
110110
export type { IgcRadioComponentEventMap } from './components/radio/radio.js';
111111
export type { IgcRatingComponentEventMap } from './components/rating/rating.js';
112112
export type { IgcSelectComponentEventMap } from './components/select/select.js';

0 commit comments

Comments
 (0)