Mentions Input
Text input that triggers a user mention dropdown on @ character.
Preview
- ALAda Lovelace
- GHGrace Hopper
Arguments
mentions_input(name='comment', users=[{'id': 'u1', 'name': 'Ada Lovelace'}, {'id': 'u2', 'name': 'Grace Hopper'}], placeholder='Mention someone…')Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import MentionsInput
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = MentionsInput(name='comment', users=[{'id': 'u1', 'name': 'Ada Lovelace'}, {'id': 'u2', 'name': 'Grace Hopper'}], placeholder='Mention someone…')
@event_handler()
def send(self, value=None, **kwargs):
pass # your app acts on 'send'; no component state movesmy_template.html
django
{{ component }}Events this component sends to the view: send.
Needs its script on the page: <script src="{% static 'djust_components/mentions-input.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| name | str | 'message' | Input field name attribute. |
| users | List[dict] | None | None | List of user dicts with id, name, and optional avatar. |
| event | str — renames the event | 'send' | Event name fired on submit (default: "send"). |
| placeholder | str | 'Type @ to mention...' | Placeholder text. |
| disabled | bool | False | Whether the input is disabled. |
| custom_class | str | '' | Additional CSS classes. |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.mentions_input | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components-classes.css | Defines 7 of this component's classes at line 791, 793, 794, 795, 796, 798, 799. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 1744, 1746, 1749, 1750, 1753, 1755, 1756. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |