16.2.0 • Published 11 months ago

ngx-mentions v16.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Angular @Mentions Component

ngx-mentions

Flexible, lightweight, easy-to-use, without external dependencies - Mentions component for Angular.

Docs and demo

Click here for a Demo

Stackblitz working example

Github Repo

Mentions GIF

Getting Started

Installation:

$ npm i ngx-mentions

After importing the module the lib is ready to use:

import { NgxMentionsModule } from 'ngx-mentions';

@NgModule({
  imports: [NgxMentionsModule],
  declarations: [],
})

export class DemoModule {}

Compatibility

Latest version available for each version of Angular

ngx-mentionsAngular
9.x>=9
10.x>=10
11.x>=11
12.x>=12
13.x>=13
14.x>=14
15.x>=15
16.x>=16

ngx-mentions component

@Inputs

NameDescriptionTypeDefault
textInputElementReference to the text input element.HTMLTextAreaElementRequired
menuTemplateReference to the menu template (used to display the search results).TemplateRefRequired
mentionsConfigAn array of objects representing the configuration for mentions. Each object should have the following properties:---triggerCharacter: The character that will trigger the menu to appear.getChoiceLabel: A function that formats the selected choice and returns the label for the choice.ArrayRequired
mentionsAn array of objects containing all the selected mentionsChoiceWithIndices[]Required
searchRegexpThe regular expression that will match the search text after the trigger character. No match will hide the menu.RegExp/^\w*$/
closeMenuOnBlurWhether to close the menu when the host textInputElement loses focus.booleanfalse
selectedChoicesPre-set choices for edit text mode, or to select/mark choices from outside the mentions component.any[][]
tagCssClassThe CSS class to add to highlighted tags.string''
removeWholeTagOnBackspaceWhether to remove whole tag on backspace.booleanfalse

@Outputs

NameDescriptionOutput type
searchCalled on user input after entering trigger character. Emits search term to search by and the char which trigger the current mention search.{ searchText: string, triggerCharacter: string }
menuShowCalled when the choices menu is shown.void
menuHideCalled when the choices menu is hidden.void
choiceSelectedCalled when a choice is selected.ChoiceWithIndices
choiceRemovedCalled when a choice is removed.ChoiceWithIndices
selectedChoicesChangeCalled when a choice is selected, removed, or if any of the choices' indices change.ChoiceWithIndices[]
tagClickCalled when the area over a tag is clicked.TagMouseEvent
tagMouseEnterCalled when the area over a tag is moused over.TagMouseEvent
tagMouseLeaveCalled when the area over the tag has the mouse removed from it.TagMouseEvent

ngx-text-input-autocomplete-menu

@Inputs

NameDescriptionTypeDefault
getDisplayLabelA function that formats the selected choice once selected. The result (label) is also used as a choice identifier (e.g. when editing choices).(choice: any) => stringRequired
choicesPre-set choices to show in dropdown.any[][]

@Outputs

NameDescriptionOutput type
selectChoicechoiceSelectedCalled when a choice is selected.any

Basic example

<div class="relative-block-container">
  <textarea cols="42"
            rows="6"
            wrap="hard"
            #textareaRef
            placeholder="Enter '@' and start typing..."
            [(ngModel)]="text"></textarea>

  <ngx-mentions [textInputElement]="textareaRef"
                [menuTemplate]="menuTemplate"
                [mentionsConfig]="mentionsConfig"
                [searchRegexp]="'^([-&.\\w]+ *){0,3}$'"
                [mentions]="mentions"
                [removeWholeTagOnBackspace]="true"
                (search)="loadChoices($event)"
                (selectedChoicesChange)="onSelectedChoicesChange($event)"
                (menuShow)="onMenuShow()"
                (menuHide)="onMenuHide()"></ngx-mentions>

  <ng-template #menuTemplate
               let-selectChoice="selectChoice">
    <ngx-text-input-autocomplete-menu [choices]="choices"
            [getDisplayLabel]="getDisplayLabel"
            (selectChoice)="selectChoice($event)">
    </ngx-text-input-autocomplete-menu>
  </ng-template>
</div>
<div class="relative-block-container">
  <textarea cols="42"
            rows="6"
            wrap="hard"
            #textareaRef
            placeholder="Enter '@' and start typing..."
            [(ngModel)]="text"></textarea>

  <ngx-mentions [textInputElement]="textareaRef"
                [menuTemplate]="menuTemplate"
                [mentionsConfig]="mentionsConfig"
                [searchRegexp]="'^([-&.\\w]+ *){0,3}$'"
                [mentions]="mentions"
                [removeWholeTagOnBackspace]="true"
                (search)="loadChoices($event)"
                (selectedChoicesChange)="onSelectedChoicesChange($event)"
                (menuShow)="onMenuShow()"
                (menuHide)="onMenuHide()"></ngx-mentions>

  <ng-template #menuTemplate
               let-selectChoice="selectChoice">
    <ul class="ngx-selectable-list"
      ngxKbListNavigation
      [choices]="choices"
      (selectChoice)="selectChoice($event)"
      [class.loader-only]="!choices.length && loading">
      <li *ngFor="let user of choices"
        class="ngx-selectable-list-item"
        (click)="selectChoice(user)">
        <span title="{{user.name}}">{{user.name}}</span>
      </li>
    </ul>
  </ng-template>
</div>

Author

Abhijit Chikane

Github | LinkedIn

Sumit Basak

Github | LinkedIn

Support

All suggestions and improvements are welcome and appreciated.

License

The MIT License.

11.0.17

11 months ago

11.0.18

11 months ago

11.0.15

11 months ago

11.0.16

11 months ago

10.0.2

12 months ago

14.1.0

11 months ago

14.0.13

11 months ago

14.0.12

11 months ago

11.0.10

12 months ago

14.0.11

11 months ago

14.0.10

11 months ago

11.0.13

12 months ago

11.0.14

11 months ago

11.0.11

12 months ago

14.0.14

11 months ago

11.0.12

12 months ago

12.0.7

12 months ago

12.0.8

12 months ago

12.0.9

12 months ago

12.0.3

12 months ago

12.0.4

12 months ago

12.0.5

12 months ago

12.0.6

12 months ago

12.0.1

12 months ago

12.0.2

12 months ago

16.1.0

11 months ago

11.2.0

11 months ago

15.0.2

12 months ago

15.0.3

12 months ago

15.0.1

12 months ago

15.0.6

12 months ago

15.0.7

12 months ago

15.0.4

12 months ago

15.0.5

12 months ago

13.0.8

12 months ago

13.0.9

12 months ago

15.0.8

12 months ago

13.0.6

12 months ago

15.0.9

12 months ago

13.0.7

12 months ago

13.0.4

12 months ago

13.0.5

12 months ago

13.0.2

12 months ago

13.0.3

12 months ago

14.2.0

11 months ago

13.0.1

12 months ago

16.2.0

11 months ago

11.1.0

11 months ago

15.1.0

11 months ago

13.1.0

11 months ago

13.0.10

11 months ago

13.0.11

11 months ago

13.0.12

11 months ago

13.0.13

11 months ago

13.0.14

11 months ago

12.2.0

11 months ago

12.0.17

11 months ago

12.0.16

11 months ago

12.0.13

11 months ago

11.0.6

12 months ago

12.0.12

12 months ago

11.0.7

12 months ago

12.0.15

11 months ago

11.0.4

12 months ago

12.0.14

11 months ago

12.0.11

12 months ago

11.0.8

12 months ago

12.0.10

12 months ago

11.0.9

12 months ago

11.0.2

12 months ago

11.0.3

12 months ago

11.0.1

12 months ago

14.0.9

12 months ago

15.2.0

11 months ago

16.0.21

11 months ago

16.0.20

11 months ago

13.2.0

11 months ago

14.0.1

12 months ago

14.0.2

12 months ago

14.0.3

12 months ago

14.0.4

12 months ago

14.0.5

12 months ago

14.0.6

12 months ago

14.0.7

12 months ago

14.0.8

12 months ago

16.0.14

12 months ago

16.0.15

12 months ago

16.0.9

12 months ago

16.0.12

12 months ago

16.0.8

12 months ago

16.0.13

12 months ago

16.0.7

12 months ago

16.0.18

11 months ago

16.0.19

11 months ago

16.0.16

11 months ago

16.0.17

11 months ago

12.1.0

11 months ago

16.0.10

12 months ago

16.0.11

12 months ago

15.0.16

11 months ago

15.0.15

11 months ago

15.0.14

11 months ago

15.0.13

11 months ago

15.0.12

11 months ago

15.0.11

11 months ago

15.0.10

12 months ago

16.0.6

12 months ago

16.0.5

12 months ago

16.0.4

1 year ago

16.0.3

1 year ago

16.0.2

1 year ago

16.0.1

1 year ago

16.0.0

1 year ago

15.0.0

1 year ago

14.0.0

1 year ago

13.0.0

1 year ago

12.0.0

1 year ago

11.0.0

1 year ago

10.0.1

1 year ago

10.0.0

1 year ago

9.0.2

1 year ago

9.0.1

1 year ago

9.0.0

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago