Mention

Bootstrap 5 Mention plugin

Responsive Mention plugin built with the latest Bootstrap 5. Mention is an autocomplete dropdown menu for your search inputs. It is useful for tagging users or topics.

Note: Read the API tab to find all available options and advanced customization


Basic example

Type @ and use up/down arrows, home/end keys to navigate. Click enter or use mouse click to choose item


Data from HTML

Mention component can be reached without JavaScript initialization.

Items data has to be passed as an HTML list element with a data-mdb-target attribute pointing ID of input/textarea element. List items should have proper data-mdb- attributes.


Toggle show list on trigger

Showing all items on trigger key is turned on by default. Set showListOnTrigger option to false to turn it off and show items only after user search input


Placement example

Use placement options to change placement of the component

Position of the component will be flipped to opposite side when no free space is available. Once enough space is detected, component will flip back to its original placement


Textarea example

Mention works also with textarea



Customize no results text

Set noResultsText to a text of your choice to change the message for no results found


Trigger sign

Use trigger option to change search triggering sign


Show image

Use showImg option to show images in the mentions list


Visible items

Use visibleItems option to change the number of options that will be displayed in the select dropdown without scrolling.


Multiple lists

Assign multiple mentions to the element by giving each mention different trigger key


Asynchronous data

Use getAsync option to use asynchronous data loading


Mention - API


Usage

Via HTML


        <div class="form-outline">
          <input
            type="text"
            id="html-data"
            class="form-control mention"
          />
          <label class="form-label" for="html-data">Data from HTML list</label>
        </div>
        <ul class="mention-data-mdb-items" data-mdb-target="html-data">
          <li data-name="James" data-mdb-username="james123" data-mdb-img="..."></li>
          <li data-name="John" data-mdb-username="john322" data-mdb-img="..."></li>
          <li data-name="Mary" data-mdb-username="maryx" data-mdb-img="..."></li>
        </ul>
      

Via JavaScript


        <div class="form-outline">
          <input type="text" id="basic-example" class="form-control mention" />
          <label class="form-label" for="basic-example">Basic example</label>
        </div>
      

        const options = { items: [ { name: 'James', username: 'james123', image: '' }, { name:
        'John', username: 'john322', image: '' }, ] } const myMention = new
        Mention(document.getElementById('basic-example'), options);
      

Via jQuery

Note: By default, MDB does not include jQuery and you have to add it to the project on your own.


        <div class="form-outline">
          <input type="text" id="basic-example" class="form-control mention" />
          <label class="form-label" for="basic-example">Basic example</label>
        </div>
      

        $('#basic-example').mention(options);
      

Options

Name Type Default Description
items Array '[]' An array of items to display on the list. Each user should contain the required username key value. Other key values are optional e.g. user, image
noResultsText String 'No results found' The text that will be displayed when no item is found after using mention filter
trigger String '@' Changes trigger sign that allows to search for items
queryBy String 'name' Changes the key by which list will be rendered and filtered
placement String 'bottom' Changes placement of the component relative to the reference element
showListOnTrigger Boolean 'true' Specifies whether whole list has to be opened before search input
showImg Boolean 'true' Displays user image on the list
visibleItems Number 5 The maximum number of items which are visible in the mention dropdown without scrolling.

Methods

Name Description Example
getInstance Retuns instance of element mdb.Mention.getInstance(element)
open Manually opens a mention instance.open()
close Manually close a mention instance.close()
dispose Disposes a mention instance instance.dispose()

        const mentionEl = document.getElementById('mentionEl');
        const mention = new Mention(mentionEl, {
            items: [
              { name: 'James', username: 'james123', image: '' },
              { name: 'John', username: 'john322', image: '' },
              { name: 'Mary', username: 'maryx', image: '' },
            ],
          });
        mention.open()
      

Events

Name Description
open.mdb.mention This event fires immediately when the mention is opened.
close.mdb.mention This event fires immediately when the mention is closed.
select.mdb.mention This event fires immediately when the list item is selected
change.mdb.mention This event fires immediately when the mention reference element value changes
fetchError.mdb.mention This event fires immediately when getting asynchronous data fails

        document.addEventListener('open.mdb.mention', (e) => {
          // do something...
        })
      

Import

MDB UI KIT also works with module bundlers. Use the following code to import this component:


        import Mention from 'mdb-mention';