Skip to content

Commit

Permalink
feat: slash commands only activate for first chartacter
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Sep 15, 2023
1 parent 5fb9916 commit 0121d3c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</ng-template>

<ng-template #defaultCommandTemplate let-item="item">
<div class="str-chat__slash-command">
<div class="str-chat__slash-command str-chat-angular__slash-command">
<span class="str-chat__slash-command-header">
<strong
class="str-chat__slash-command-name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,66 @@ describe('AutocompleteTextareaComponent', () => {

expect(height).toBeGreaterThan(0);
});

it('should control slash command auto complete visibility', () => {
expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeUndefined();

component.value = '/';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeUndefined();

component.value = '/ban';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeUndefined();

component.value = '/ban ';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeTrue();

component.value = '/ban @';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeUndefined();

component.value = 'http:/';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeTrue();

component.value = 'http://getstream.io @';
fixture.detectChanges();

expect(
fixture.debugElement.classes[
'str-chat__message-textarea-angular-host--autocomplete-hidden'
]
).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ import { ThemeService } from '../../theme.service';
export class AutocompleteTextareaComponent
implements TextareaInterface, OnChanges, AfterViewInit
{
@HostBinding() class =
'str-chat__textarea str-chat__message-textarea-angular-host';
/**
* The value of the input HTML element.
*/
@Input() value = '';

/**
* Placeholder of the textarea
*/
Expand Down Expand Up @@ -173,6 +172,19 @@ export class AutocompleteTextareaComponent
this.themeVersion = this.themeService.themeVersion;
}

@HostBinding()
get class() {
return `str-chat__textarea str-chat__message-textarea-angular-host ${
(this.value.includes(' ') ||
!this.value.startsWith(this.commandTriggerChar) ||
this.value.lastIndexOf(this.commandTriggerChar) !== 0) &&
this.value.lastIndexOf(this.commandTriggerChar) >
this.value.lastIndexOf(this.mentionTriggerChar)
? 'str-chat__message-textarea-angular-host--autocomplete-hidden'
: ''
}`;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.areMentionsEnabled) {
if (this.areMentionsEnabled) {
Expand Down

0 comments on commit 0121d3c

Please sign in to comment.