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

SuggestionPopup#

The neutral suggestion popup for trigger sessions such as @-mentions. Positions itself from a caret rect and the container's page frame; rows are replaceable.

Import#

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

SuggestionPopup is the presentational surface; createTriggerSessionManager is the state machine that decides when a session is open and what to show. Most apps get this wired automatically by passing a mention plugin to MarkdownEditor — reach for the popup directly only when building a custom trigger UI.

The popup imports @sigx/lynx-keyboard's useKeyboard(), so it needs a <SafeAreaProvider> ancestor while open.

Usage#

Drive the popup from a trigger session: feed the editor's text and caret to the manager, and render the popup whenever a session is active.

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

export const Mentions = component(({ signal }) => {
  const state = signal({ session: null as any });

  const sessions = createTriggerSessionManager({
    triggers: [{ char: '@', search: (q) => findPeople(q) }],
    onUpdate: (session) => (state.session = session),
  });

  return () => state.session && (
    <SuggestionPopup
      items={state.session.items}
      caretRect={state.session.caretRect}
      containerFrame={state.session.containerFrame}
      activeIndex={state.session.activeIndex}
      onSelect={(item) => sessions.close()}
    />
  );
});

Whitespace, caret exits, blur, and selection all close the session for free — the manager derives state purely from bindchange text and the collapsed caret offset.

Props#

PropTypeDescription
itemsTriggerItem[]Rows for the active session.
caretRectRectCaret rectangle the popup anchors to.
containerFrameRectPage frame of the relative container, for positioning.
renderItemSuggestionRenderItemPer-row render override: (item, active) => JSXElement.
onSelect(item: TriggerItem) => voidFired when a row is chosen.
activeIndexnumberHighlighted row; -1 or omitted means none.
maxHeightnumberMax popup height.
widthnumberPopup width.
classstringExtra classes on the popup root.

See the API reference for createTriggerSessionManager, TriggerSession, and the trigger contract types.