Skip to content

Commit e984b07

Browse files
committed
feat(chat): use input type=file instead of igc-file-input
1 parent 6bfd5ae commit e984b07

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/components/chat/chat-input.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { consume } from '@lit/context';
22
import { html, LitElement, nothing, type TemplateResult } from 'lit';
33
import { query, state } from 'lit/decorators.js';
4+
import { ifDefined } from 'lit/directives/if-defined.js';
45
import { addThemingController } from '../../theming/theming-controller.js';
56
import IgcIconButtonComponent from '../button/icon-button.js';
67
import IgcChipComponent from '../chip/chip.js';
78
import { chatContext } from '../common/context.js';
89
import { watch } from '../common/decorators/watch.js';
910
import { registerComponent } from '../common/definitions/register.js';
10-
import IgcFileInputComponent from '../file-input/file-input.js';
1111
import IgcIconComponent from '../icon/icon.js';
1212
import { registerIconFromText } from '../icon/icon.registry.js';
1313
import IgcTextareaComponent from '../textarea/textarea.js';
@@ -61,17 +61,13 @@ export default class IgcChatInputComponent extends LitElement {
6161
IgcTextareaComponent,
6262
IgcIconButtonComponent,
6363
IgcChipComponent,
64-
IgcFileInputComponent,
6564
IgcIconComponent
6665
);
6766
}
6867

6968
@query(IgcTextareaComponent.tagName)
7069
private textInputElement!: IgcTextareaComponent;
7170

72-
@query(IgcFileInputComponent.tagName)
73-
private fileInputElement!: IgcFileInputComponent;
74-
7571
@watch('acceptedFiles', { waitUntilFirstUpdate: true })
7672
protected acceptedFilesChange(): void {
7773
this._chatState?.updateAcceptedTypesCache();
@@ -121,17 +117,22 @@ export default class IgcChatInputComponent extends LitElement {
121117

122118
public get defaultFileUploadButton(): TemplateResult {
123119
return html`
124-
<igc-file-input
125-
multiple
126-
.accept=${this._chatState?.options?.acceptedFiles}
127-
@igcChange=${this.handleFileUpload}
128-
>
120+
<label for="input_attachments">
129121
<igc-icon
130122
slot="file-selector-text"
131123
name="attachment"
132124
collection="material"
133125
></igc-icon>
134-
</igc-file-input>
126+
</label>
127+
<input
128+
type="file"
129+
id="input_attachments"
130+
name="input_attachments"
131+
style="opacity: 0"
132+
multiple
133+
accept=${ifDefined(this._chatState?.options?.acceptedFiles === '' ? undefined : this._chatState?.options?.acceptedFiles)}
134+
@change=${this.handleFileUpload}>
135+
</input>
135136
`;
136137
}
137138

@@ -302,16 +303,14 @@ export default class IgcChatInputComponent extends LitElement {
302303
}
303304

304305
private handleFileUpload(e: Event) {
305-
const input = (e.target as any).input as HTMLInputElement;
306+
const input = e.target as HTMLInputElement;
306307
if (!input.files || input.files.length === 0) return;
307308

308309
const files = Array.from(input.files);
309310
this._chatState?.attachFiles(files);
310311
this.requestUpdate();
311312

312-
if (this.fileInputElement) {
313-
this.fileInputElement.value = '';
314-
}
313+
input.value = '';
315314
}
316315

317316
private removeAttachment(index: number) {

src/components/chat/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ export type AttachmentTemplate = (
9191
*/
9292
export type MessageTemplate = (message: IgcMessage) => unknown;
9393

94-
// export type MarkdownRenderer = (text: string) => TemplateResult;
95-
9694
/**
9795
* Configuration options for customizing the behavior and appearance of the chat component.
9896
*/

0 commit comments

Comments
 (0)