@@ -10,6 +10,7 @@ import { chatContext } from '../common/context.js';
1010import { addKeybindings } from '../common/controllers/key-bindings.js' ;
1111import { watch } from '../common/decorators/watch.js' ;
1212import { registerComponent } from '../common/definitions/register.js' ;
13+ import { partMap } from '../common/part-map.js' ;
1314import { isEmpty } from '../common/util.js' ;
1415import IgcIconComponent from '../icon/icon.js' ;
1516import { registerIconFromText } from '../icon/icon.registry.js' ;
@@ -95,7 +96,7 @@ export default class IgcChatInputComponent extends LitElement {
9596 }
9697
9798 @state ( )
98- private containerPart = 'input-container' ;
99+ private _parts = { 'input-container' : true , dragging : false } ;
99100
100101 private _defaults : Partial < ChatRenderers > ;
101102 private _cachedRenderers ?: {
@@ -140,7 +141,6 @@ export default class IgcChatInputComponent extends LitElement {
140141 }
141142
142143 protected override firstUpdated ( ) {
143- this . setupDragAndDrop ( ) ;
144144 this . _chatState . updateAcceptedTypesCache ( ) ;
145145 this . _chatState . textArea = this . _textInputElement ;
146146
@@ -159,63 +159,51 @@ export default class IgcChatInputComponent extends LitElement {
159159 } ;
160160 }
161161
162- private setupDragAndDrop ( ) {
163- const container = this . shadowRoot ?. querySelector (
164- `div[part='input-container']`
165- ) as HTMLElement ;
166- if ( container ) {
167- container . addEventListener ( 'dragenter' , this . handleDragEnter . bind ( this ) ) ;
168- container . addEventListener ( 'dragover' , this . handleDragOver . bind ( this ) ) ;
169- container . addEventListener ( 'dragleave' , this . handleDragLeave . bind ( this ) ) ;
170- container . addEventListener ( 'drop' , this . handleDrop . bind ( this ) ) ;
171- }
172- }
173-
174162 private _handleFocusState ( event : FocusEvent ) : void {
175163 this . _chatState . emitEvent (
176164 event . type === 'focus' ? 'igcInputFocus' : 'igcInputBlur'
177165 ) ;
178166 }
179167
180- private handleDragEnter ( event : DragEvent ) {
168+ private _handleDragEnter ( event : DragEvent ) : void {
181169 event . preventDefault ( ) ;
182170 event . stopPropagation ( ) ;
183171
184172 const validFiles = getChatAcceptedFiles ( event , this . _acceptedTypes ) ;
185- this . containerPart = ` input-container ${ ! isEmpty ( validFiles ) ? ' dragging' : '' } ` ;
173+ this . _parts = { ' input-container' : true , dragging : ! isEmpty ( validFiles ) } ;
186174 this . _chatState . emitEvent ( 'igcAttachmentDrag' ) ;
187175 }
188176
189- private handleDragOver ( e : DragEvent ) {
190- e . preventDefault ( ) ;
191- e . stopPropagation ( ) ;
177+ private _handleDragOver ( event : DragEvent ) : void {
178+ event . preventDefault ( ) ;
179+ event . stopPropagation ( ) ;
192180 }
193181
194- private handleDragLeave ( e : DragEvent ) {
195- e . preventDefault ( ) ;
196- e . stopPropagation ( ) ;
182+ private _handleDragLeave ( event : DragEvent ) : void {
183+ event . preventDefault ( ) ;
184+ event . stopPropagation ( ) ;
197185
198186 // Check if we're actually leaving the container
199- const rect = ( e . currentTarget as HTMLElement ) . getBoundingClientRect ( ) ;
200- const x = e . clientX ;
201- const y = e . clientY ;
187+ const rect = ( event . currentTarget as HTMLElement ) . getBoundingClientRect ( ) ;
188+ const x = event . clientX ;
189+ const y = event . clientY ;
202190
203191 if (
204192 x <= rect . left ||
205193 x >= rect . right ||
206194 y <= rect . top ||
207195 y >= rect . bottom
208196 ) {
209- this . containerPart = 'input-container' ;
197+ this . _parts = { 'input-container' : true , dragging : false } ;
210198 }
211199 }
212200
213- private handleDrop ( e : DragEvent ) {
214- e . preventDefault ( ) ;
215- e . stopPropagation ( ) ;
216- this . containerPart = 'input-container' ;
201+ private _handleDrop ( event : DragEvent ) : void {
202+ event . preventDefault ( ) ;
203+ event . stopPropagation ( ) ;
204+ this . _parts = { 'input-container' : true , dragging : false } ;
217205
218- const validFiles = getChatAcceptedFiles ( e , this . _acceptedTypes ) ;
206+ const validFiles = getChatAcceptedFiles ( event , this . _acceptedTypes ) ;
219207 this . _chatState . emitEvent ( 'igcAttachmentDrop' ) ;
220208 this . _chatState . attachFiles ( validFiles ) ;
221209 this . requestUpdate ( ) ;
@@ -354,7 +342,13 @@ export default class IgcChatInputComponent extends LitElement {
354342 if ( ! this . _renderers ) return nothing ;
355343
356344 return html `
357- < div part ="${ this . containerPart } ">
345+ < div
346+ part =${ partMap ( this . _parts ) }
347+ @dragenter =${ this . _handleDragEnter }
348+ @dragover=${ this . _handleDragOver }
349+ @dragleave=${ this . _handleDragLeave }
350+ @drop=${ this . _handleDrop }
351+ >
358352 ${ this . _chatState . inputAttachments &&
359353 this . _chatState . inputAttachments . length > 0
360354 ? html ` < div part ="attachments " role ="list " aria-label ="Attachments ">
0 commit comments