# MentionEditorTarget (@salmonui/dropdowns/mention)

> The MentionEditorTarget interface of @salmonui/dropdowns/mention: A rich text surface Mention attaches to instead of a &lt;textarea> or &lt;input>: a plain contenteditable element through createContentEditableMentionTarget, or the @salmonui/rich-text engine. Offsets count the characters of the current text block, an inline atom (an inserted mention) as one U+FFFC character.

Canonical: https://salmonui.dev/docs/reference/dropdowns/mention/MentionEditorTarget

```ts
import type { MentionEditorTarget } from '@salmonui/dropdowns/mention';
```

Entry index: https://salmonui.dev/docs/reference/dropdowns/mention (Markdown with every symbol of the entry: https://salmonui.dev/docs/reference/dropdowns/mention.md).

## Reference

Kind: interface

```ts
interface MentionEditorTarget {
    readonly element: HTMLElement;
    getTextBeforeCaret(): string | null;
    getCaretRect(offset: number): {
        readonly left: number;
        readonly top: number;
        readonly bottom: number;
    } | null;
    insertMention(insertion: MentionEditorInsertion): void;
    subscribe(listener: () => void): () => void;
}
```

A rich text surface `Mention` attaches to instead of a `<textarea>` or
`<input>`: a plain `contenteditable` element through
`createContentEditableMentionTarget`, or the `@salmonui/rich-text` engine.
Offsets count the characters of the current text block, an inline atom
(an inserted mention) as one U+FFFC character.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `readonly element: HTMLElement;` |  | The editable element (the host gives it `role="textbox"`). `Mention` adds the combobox ARIA attributes to it while the list is open, listens for `keydown` in the capture phase (keys it handles while open call `preventDefault()` and `stopImmediatePropagation()`), for composition and for `focusout`. |
| `getTextBeforeCaret` | `getTextBeforeCaret(): string \| null;` |  | Text of the current text block from its start to the caret; `null` when the selection is not collapsed or not editable. |
| `getCaretRect` | `getCaretRect(offset: number): {     readonly left: number;     readonly top: number;     readonly bottom: number; } \| null;` |  | Viewport rectangle of the character at `offset` of that text, `null` when unknown. |
| `insertMention` | `insertMention(insertion: MentionEditorInsertion): void;` |  | Replaces `[start, end)` of the text block with the mention (and its suffix) and puts the caret after it. |
| `subscribe` | `subscribe(listener: () => void): () => void;` |  | Calls `listener` after the editor applied a text or selection change; returns the unsubscribe function. |
