|
1 | 1 | import { consume } from '@lit/context'; |
2 | 2 | import { html, LitElement, nothing, type TemplateResult } from 'lit'; |
3 | 3 | import { query, state } from 'lit/decorators.js'; |
| 4 | +import { ifDefined } from 'lit/directives/if-defined.js'; |
4 | 5 | import { addThemingController } from '../../theming/theming-controller.js'; |
5 | 6 | import IgcIconButtonComponent from '../button/icon-button.js'; |
6 | 7 | import IgcChipComponent from '../chip/chip.js'; |
7 | 8 | import { chatContext } from '../common/context.js'; |
8 | 9 | import { watch } from '../common/decorators/watch.js'; |
9 | 10 | import { registerComponent } from '../common/definitions/register.js'; |
10 | | -import IgcFileInputComponent from '../file-input/file-input.js'; |
11 | 11 | import IgcIconComponent from '../icon/icon.js'; |
12 | 12 | import { registerIconFromText } from '../icon/icon.registry.js'; |
13 | 13 | import IgcTextareaComponent from '../textarea/textarea.js'; |
@@ -61,17 +61,13 @@ export default class IgcChatInputComponent extends LitElement { |
61 | 61 | IgcTextareaComponent, |
62 | 62 | IgcIconButtonComponent, |
63 | 63 | IgcChipComponent, |
64 | | - IgcFileInputComponent, |
65 | 64 | IgcIconComponent |
66 | 65 | ); |
67 | 66 | } |
68 | 67 |
|
69 | 68 | @query(IgcTextareaComponent.tagName) |
70 | 69 | private textInputElement!: IgcTextareaComponent; |
71 | 70 |
|
72 | | - @query(IgcFileInputComponent.tagName) |
73 | | - private fileInputElement!: IgcFileInputComponent; |
74 | | - |
75 | 71 | @watch('acceptedFiles', { waitUntilFirstUpdate: true }) |
76 | 72 | protected acceptedFilesChange(): void { |
77 | 73 | this._chatState?.updateAcceptedTypesCache(); |
@@ -121,17 +117,22 @@ export default class IgcChatInputComponent extends LitElement { |
121 | 117 |
|
122 | 118 | public get defaultFileUploadButton(): TemplateResult { |
123 | 119 | return html` |
124 | | - <igc-file-input |
125 | | - multiple |
126 | | - .accept=${this._chatState?.options?.acceptedFiles} |
127 | | - @igcChange=${this.handleFileUpload} |
128 | | - > |
| 120 | + <label for="input_attachments"> |
129 | 121 | <igc-icon |
130 | 122 | slot="file-selector-text" |
131 | 123 | name="attachment" |
132 | 124 | collection="material" |
133 | 125 | ></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> |
135 | 136 | `; |
136 | 137 | } |
137 | 138 |
|
@@ -302,16 +303,14 @@ export default class IgcChatInputComponent extends LitElement { |
302 | 303 | } |
303 | 304 |
|
304 | 305 | private handleFileUpload(e: Event) { |
305 | | - const input = (e.target as any).input as HTMLInputElement; |
| 306 | + const input = e.target as HTMLInputElement; |
306 | 307 | if (!input.files || input.files.length === 0) return; |
307 | 308 |
|
308 | 309 | const files = Array.from(input.files); |
309 | 310 | this._chatState?.attachFiles(files); |
310 | 311 | this.requestUpdate(); |
311 | 312 |
|
312 | | - if (this.fileInputElement) { |
313 | | - this.fileInputElement.value = ''; |
314 | | - } |
| 313 | + input.value = ''; |
315 | 314 | } |
316 | 315 |
|
317 | 316 | private removeAttachment(index: number) { |
|
0 commit comments