Lynx/Modules/Markdown/SuggestionPopup
@sigx/lynx-markdown · Stable · Component library

SuggestionPopup#

The neutral suggestion popup for trigger sessions such as @-mentions. It positions itself from a caret rect and the container's frame, picks the side of the caret with room, and clamps above the keyboard; rows are replaceable.

Import#

TSX
import { SuggestionPopup } from '@sigx/lynx-markdown/editor';

MarkdownEditor renders this popup for you — inside the block the session belongs to — whenever a plugin's trigger opens a session. You rarely mount it yourself:

  • To style it, pass suggestionPopup to MarkdownEditor (see below).
  • To replace it with your own list, pass suggestions="none" and renderSuggestions to MarkdownEditor — see Rendering suggestions yourself.
  • To skin the rows, give the trigger a renderItem (createMentionPlugin({ renderItem }), createEmojiPlugin({ renderItem })).

Sessions come from the core's trigger machinery: they are derived from the block's text and caret, so whitespace, a caret leaving the run, blur and a selection all close them.

The popup reads keyboard height through @sigx/lynx-keyboard's useKeyboard(), so it needs a <SafeAreaProvider> ancestor.

Styling through the editor#

TSX
// Auto-tinted from the dark editor text — no popup colours needed.
<MarkdownEditor value={draft} onChange={save} textColor="#e5e7eb" plugins={plugins} />

// Or set only the fields you care about; the rest still auto-tint.
<MarkdownEditor value={draft} onChange={save} suggestionPopup={{ width: 280, placement: 'above' }} plugins={plugins} />

SuggestionPopupStyle fields are all optional: width (dp, default 240, clamped to the editor width), maxHeight (dp, default 220), placement ('auto' measures for room; a composer pinned to the bottom of the screen can pin 'above'), surfaceColor, borderColor, activeColor, textColor and class. derivePopupStyleFromText(textColor) is the auto-tint the editor applies.

Props#

PropTypeDescription
itemsTriggerItem[]Rows for the active session.
caretRectCaretRect | nullCaret rectangle the popup anchors to.
containerFrameElementLayout | nullViewport frame of the relative container.
onMeasureRequest() => voidAsks the owner to re-measure containerFrame — on mount and whenever the keyboard changes.
renderItemSuggestionRenderItemPer-row render override: (item, active) => JSXElement.
onSelect(item: TriggerItem) => voidFired when a row is chosen.
activeIndexnumberHighlighted row; -1 or omitted means none.
maxHeight / widthnumberSize in dp.
placement'auto' | 'above' | 'below'Pin the side of the caret.
surfaceColor / borderColor / activeColor / textColorstringColours; neutral defaults.
classstringExtra classes on the popup root.

See the API reference for SuggestionPopupStyle and the trigger types.