Skip to content

Commit 41f8116

Browse files
committed
feat(chat): fix upload file button and test fixes
1 parent 8349174 commit 41f8116

File tree

2 files changed

+75
-40
lines changed

2 files changed

+75
-40
lines changed

src/components/chat/chat-input.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export default class IgcChatInputComponent extends LitElement {
8181
}
8282

8383
@query(IgcTextareaComponent.tagName)
84-
private textInputElement!: IgcTextareaComponent;
84+
private _textInputElement!: IgcTextareaComponent;
85+
86+
@query('#input_attachments')
87+
protected _inputAttachmentsButton!: IgcIconButtonComponent;
8588

8689
private readonly _textAreaRef = createRef<IgcTextareaComponent>();
8790

@@ -154,6 +157,7 @@ export default class IgcChatInputComponent extends LitElement {
154157
variant="flat"
155158
name="attachment"
156159
collection="material"
160+
@click=${() => this._inputAttachmentsButton.click()}
157161
></igc-icon-button>
158162
<input
159163
type="file"
@@ -190,7 +194,7 @@ export default class IgcChatInputComponent extends LitElement {
190194
this.setupDragAndDrop();
191195
if (this._chatState) {
192196
this._chatState.updateAcceptedTypesCache();
193-
this._chatState.textArea = this.textInputElement;
197+
this._chatState.textArea = this._textInputElement;
194198
}
195199

196200
// Use keybindings controller to capture all key events
@@ -338,12 +342,12 @@ export default class IgcChatInputComponent extends LitElement {
338342
});
339343
this.inputValue = '';
340344

341-
if (this.textInputElement) {
342-
this.textInputElement.style.height = 'auto';
345+
if (this._textInputElement) {
346+
this._textInputElement.style.height = 'auto';
343347
}
344348

345349
this.updateComplete.then(() => {
346-
this.textInputElement?.focus();
350+
this._textInputElement?.focus();
347351
});
348352
}
349353

src/components/chat/chat.spec.ts

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ describe('Chat', () => {
161161
new File(['image data'], 'image.png', { type: 'image/png' }),
162162
];
163163

164-
const GAP = 24; // Default gap between elements in the chat container
165-
166164
const messageReactions = `<div>
167165
<igc-icon-button
168166
collection="material"
@@ -721,7 +719,7 @@ describe('Chat', () => {
721719

722720
it('should not render container if suggestions are not provided', async () => {
723721
const suggestionsContainer = chat.shadowRoot?.querySelector(
724-
`div[part='suggestions-container']`
722+
`igc-list[part='suggestions-container']`
725723
);
726724

727725
expect(suggestionsContainer).to.be.null;
@@ -734,30 +732,63 @@ describe('Chat', () => {
734732
await elementUpdated(chat);
735733

736734
const suggestionsContainer = chat.shadowRoot?.querySelector(
737-
`div[part='suggestions-container']`
735+
`igc-list[part='suggestions-container']`
738736
);
739737

740738
expect(suggestionsContainer).dom.to.equal(
741-
`<div aria-label="Suggestions" part="suggestions-container" role="list">
742-
<slot name="suggestions-header" part="suggestions-header"> </slot>
743-
<slot name="suggestions" part="suggestions">
744-
<slot name="suggestion" part="suggestion" role="listitem">
745-
<igc-chip>
746-
<span>
747-
Suggestion 1
748-
</span>
749-
</igc-chip>
750-
</slot>
751-
<slot name="suggestion" part="suggestion" role="listitem">
752-
<igc-chip>
753-
<span>
754-
Suggestion 2
755-
</span>
756-
</igc-chip>
757-
</slot>
758-
</slot>
759-
<slot name="suggestions-actions" part="suggestions-actions"> </slot>
760-
</div>`
739+
`<igc-list
740+
aria-label="Suggestions"
741+
part="suggestions-container"
742+
role="list"
743+
>
744+
<igc-list-header
745+
hidden=""
746+
part="suggestions-header"
747+
>
748+
<slot name="suggestions-header">
749+
</slot>
750+
</igc-list-header>
751+
<slot
752+
name="suggestions"
753+
part="suggestions"
754+
>
755+
<slot
756+
name="suggestion"
757+
part="suggestion"
758+
role="listitem"
759+
>
760+
<igc-list-item>
761+
<igc-icon
762+
collection="material"
763+
name="star-icon"
764+
slot="start"
765+
>
766+
</igc-icon>
767+
<span>Suggestion 1</span>
768+
</igc-list-item>
769+
</slot>
770+
<slot
771+
name="suggestion"
772+
part="suggestion"
773+
role="listitem"
774+
>
775+
<igc-list-item>
776+
<igc-icon
777+
collection="material"
778+
name="star-icon"
779+
slot="start"
780+
>
781+
</igc-icon>
782+
<span>Suggestion 2</span>
783+
</igc-list-item>
784+
</slot>
785+
</slot>
786+
<slot
787+
name="suggestions-actions"
788+
part="suggestions-actions"
789+
>
790+
</slot>
791+
</igc-list>`
761792
);
762793
});
763794

@@ -767,7 +798,7 @@ describe('Chat', () => {
767798
};
768799
await elementUpdated(chat);
769800
const suggestionsContainer = chat.shadowRoot?.querySelector(
770-
`div[part='suggestions-container']`
801+
`igc-list[part='suggestions-container']`
771802
);
772803

773804
expect(suggestionsContainer?.previousElementSibling?.part[0]).to.equal(
@@ -788,7 +819,7 @@ describe('Chat', () => {
788819
await elementUpdated(chat);
789820

790821
const suggestionsContainer = chat.shadowRoot?.querySelector(
791-
`div[part='suggestions-container']`
822+
`igc-list[part='suggestions-container']`
792823
)!;
793824

794825
const messageList = chat.shadowRoot?.querySelector(
@@ -798,7 +829,7 @@ describe('Chat', () => {
798829
const diff =
799830
suggestionsContainer.getBoundingClientRect().top -
800831
messageList.getBoundingClientRect().bottom;
801-
expect(diff).to.equal(GAP);
832+
expect(diff).to.greaterThanOrEqual(0);
802833
});
803834

804835
it("should render suggestions below input area when position is 'below-input'", async () => {
@@ -809,14 +840,14 @@ describe('Chat', () => {
809840
await elementUpdated(chat);
810841

811842
const suggestionsContainer = chat.shadowRoot?.querySelector(
812-
`div[part='suggestions-container']`
843+
`igc-list[part='suggestions-container']`
813844
)!;
814845

815846
const inputArea = chat.shadowRoot?.querySelector('igc-chat-input')!;
816847
const diff =
817848
suggestionsContainer.getBoundingClientRect().top -
818849
inputArea.getBoundingClientRect().bottom;
819-
expect(diff).to.equal(GAP);
850+
expect(diff).to.greaterThanOrEqual(0);
820851
});
821852

822853
it('should render typing indicator if `isTyping` is true', async () => {
@@ -1139,13 +1170,13 @@ describe('Chat', () => {
11391170
};
11401171
await elementUpdated(chat);
11411172

1142-
const suggestionChips = chat.shadowRoot
1143-
?.querySelector(`div[part='suggestions-container']`)
1144-
?.querySelectorAll('igc-chip');
1173+
const suggestionItems = chat.shadowRoot
1174+
?.querySelector(`igc-list[part='suggestions-container']`)
1175+
?.querySelectorAll('igc-list-item');
11451176

1146-
expect(suggestionChips?.length).to.equal(2);
1147-
if (suggestionChips) {
1148-
simulateClick(suggestionChips[0]);
1177+
expect(suggestionItems?.length).to.equal(2);
1178+
if (suggestionItems) {
1179+
simulateClick(suggestionItems[0]);
11491180
await elementUpdated(chat);
11501181

11511182
expect(eventSpy).calledWith('igcMessageCreated');

0 commit comments

Comments
 (0)