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):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: send.
Needs a client hook djust does not ship: dj-hook="MentionsInput". The markup renders, but the interaction described above is yours to add — register window.djust.hooks.MentionsInput = { mounted() { … } } before client.js loads (see the hooks guide).
Parameters
| Name | Type | Default |
|---|---|---|
| name | str | 'message' |
| users | List[dict] | None | None |
| event | str — renames the event | 'send' |
| placeholder | str | 'Type @ to mention...' |
| disabled | bool | False |
| custom_class | str | '' |
| **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 789, 791, 792, 793, 794, 796, 797. 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 1718, 1720, 1723, 1724, 1726, 1728, 1729. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |