PhoenixKit.Mentions.Live (phoenix_kit v2.1.0)

Copy Markdown View Source

Everything a LiveView needs to let people WRITE mentions and act on them:

use PhoenixKit.Mentions.Live

That injects the typeahead's search handler and the access-request events. In the template, swap a textarea for <.mention_input> and drop the dialog somewhere:

<.mention_input field={@form[:description]} label="Description" />
<.access_request_dialog request={@pk_access_request} />

Reading mentions needs none of this — <.mention_text> is a plain function component. This module is only for the two INTERACTIVE halves, which is why it is opt-in per LiveView rather than global.

Injected clauses follow the MediaBrowser embed precedent: a host adds one use instead of copying four handlers and getting one subtly wrong. Every one of them degrades rather than crashes — a click with no dialog rendered, or a search with the feature switched off, is a no-op.

Summary

Functions

The "ask for access" dialog. Renders nothing until a redacted mention is clicked.

A textarea that offers @ and # as you type.

Functions

access_request_dialog(assigns)

The "ask for access" dialog. Renders nothing until a redacted mention is clicked.

Deliberately says nothing about WHAT is being requested beyond its kind — the whole point of the redaction is that the reader does not learn the title, and a dialog headed with it would undo that in the one place they are most likely to read.

Attributes

  • request (:any) - Defaults to nil.

mention_input(assigns)

A textarea that offers @ and # as you type.

Identical to a plain textarea in every other way, and identical to one entirely when JavaScript is off — the hook is the only difference, and what it inserts is text the field could have held anyway. That is the whole reason the token format is what it is.

Attributes

  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:string) - Defaults to nil.
  • rows (:integer) - Defaults to 4.
  • class (:any) - Defaults to nil.
  • placeholder (:string) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["required", "maxlength", "phx-debounce"].