@@ -2,10 +2,15 @@ import { consume } from '@lit/context';
22import { html , LitElement , nothing , type TemplateResult } from 'lit' ;
33import { query , state } from 'lit/decorators.js' ;
44import { ifDefined } from 'lit/directives/if-defined.js' ;
5+ import { createRef , ref } from 'lit/directives/ref.js' ;
56import { addThemingController } from '../../theming/theming-controller.js' ;
67import IgcIconButtonComponent from '../button/icon-button.js' ;
78import IgcChipComponent from '../chip/chip.js' ;
89import { chatContext } from '../common/context.js' ;
10+ import {
11+ addKeybindings ,
12+ enterKey ,
13+ } from '../common/controllers/key-bindings.js' ;
914import { watch } from '../common/decorators/watch.js' ;
1015import { registerComponent } from '../common/definitions/register.js' ;
1116import IgcIconComponent from '../icon/icon.js' ;
@@ -77,6 +82,8 @@ export default class IgcChatInputComponent extends LitElement {
7782 @query ( IgcTextareaComponent . tagName )
7883 private textInputElement ! : IgcTextareaComponent ;
7984
85+ private readonly _textAreaRef = createRef < IgcTextareaComponent > ( ) ;
86+
8087 @watch ( 'acceptedFiles' , { waitUntilFirstUpdate : true } )
8188 protected acceptedFilesChange ( ) : void {
8289 this . _chatState ?. updateAcceptedTypesCache ( ) ;
@@ -94,6 +101,11 @@ export default class IgcChatInputComponent extends LitElement {
94101 constructor ( ) {
95102 super ( ) ;
96103 addThemingController ( this , all ) ;
104+ // Configure keybindings to not skip textarea events and bind Enter key
105+ addKeybindings ( this , {
106+ skip : [ 'input' , 'select' ] ,
107+ ref : this . _textAreaRef ,
108+ } ) . setActivateHandler ( this . handleKeyDown ) ;
97109 registerIconFromText ( 'attachment' , attachmentIcon , 'material' ) ;
98110 registerIconFromText ( 'send-message' , sendButtonIcon , 'material' ) ;
99111 registerIconFromText ( 'file-document' , fileDocumentIcon , 'material' ) ;
@@ -127,12 +139,12 @@ export default class IgcChatInputComponent extends LitElement {
127139 public get defaultTextArea ( ) : TemplateResult {
128140 return html ` < igc-textarea
129141 part ="text-input "
142+ ${ ref ( this . _textAreaRef ) }
130143 .placeholder =${ this . inputPlaceholder }
131144 resize ="auto"
132145 rows="1"
133146 .value=${ this . inputValue }
134147 @igcInput=${ this . handleInput }
135- @keydown=${ this . handleKeyDown }
136148 @focus=${ this . handleFocus }
137149 @blur=${ this . handleBlur }
138150 > </ igc-textarea > ` ;
@@ -196,7 +208,7 @@ export default class IgcChatInputComponent extends LitElement {
196208 }
197209
198210 private handleKeyDown ( e : KeyboardEvent ) {
199- if ( e . key === 'Enter' && ! e . shiftKey ) {
211+ if ( e . key === enterKey && ! e . shiftKey ) {
200212 e . preventDefault ( ) ;
201213 this . sendMessage ( ) ;
202214 } else {
0 commit comments