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
Note: Currently, the plugin is only compatible with the basic MDB package imported in UMD format. More about import MDB formats.
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 initiated without the need for any JavaScript code.
The items data has to be passed as an HTML list element with a
data-mdb-target
attribute pointing to the ID
of the input/textarea element.
Additionally, the list items should have appropriate data-mdb-
attributes.
Toggle show list on trigger
Showing all items on trigger key is turned on by default. To disable this behavior and show items only after the
user provides input, set the showListOnTrigger
option to false
.
Placement example
Use placement
options to change placement of the component.
The component's position will automatically flip to the opposite side when no free space is available. Once enough space is detected, the component will flip back to its original placement.
Textarea example
Mention works also with textarea
.
Customize search conditions
Use queryBy
option to change search conditions.
Customize no results text
Customize the message for 'no results found' by setting the noResultsText
to a text of your choice.
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
Import
Usage
Via data attributes
Using the Mention plugin doesn't require any additional JavaScript code - simply add
data-mdb-mention-init
attribute to
input
tag
and use other data attributes to set all options.
Via JavaScript
Via jQuery
Note: By default, MDB does not include jQuery and you have to add it to the project on your own.
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
data-mdb-
, as in data-mdb-trigger=""
.
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 | 'username' |
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 | false |
Displays user image on the list |
visibleItems
|
Number | 5 |
The maximum number of items which are visible in the mention dropdown without scrolling |
multiInstance
|
Boolean | false |
Allow setting multiple instances of the mention plugin on the same element for different triggers |
getAsync
|
String | '' |
Allow setting an endpoint for asynchronous data loading |
Methods
Name | Description | Example |
---|---|---|
getInstance
|
Returns instance of element |
mdb.Mention.getInstance(
|
open |
Manually opens a mention | instance.open() |
close |
Manually close a mention | instance.close() |
dispose
|
Disposes a mention instance |
instance.dispose()
|
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. |
itemSelected.mdb.mention
|
This event fires immediately after the list item is selected. |
valueChange.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. |