Trigger Menu

Suggestions as you type a trigger — @ for people, / for commands — in a Token Input, a textarea or an input: a list at the character, filtered by what follows it; the one chosen becomes a token, or its text.

FormsExperimental

Usage

Usage

Message
import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScTokenInput,  ScTokenInputEditor,  ScTokenInputToken,  type ScTrigger,  ScTriggerMenu,  ScTriggerMenuEmpty,

Anatomy

Inside a Token Input — or around a textarea or an input with scTriggerMenuInput (its look from scTextarea, scInput). Its template is stamped in an overlay at the trigger: the popup, the list of menu.items() (already filtered), the empty text, a status.

import { ScTriggerMenu, ScTriggerMenuEmpty, ScTriggerMenuItem, ScTriggerMenuList, ScTriggerMenuPopup, ScTriggerMenuPortal, ScTriggerMenuStatus } from '@semantic-components/ui';
<div scTokenInput>  <div scTokenInputEditor></div>  <div scTriggerMenu #menu="scTriggerMenu" [triggers]="triggers">    <ng-template scTriggerMenuPortal>      <div scTriggerMenuPopup>        <div scTriggerMenuEmpty>No one found.</div>        <div scTriggerMenuList aria-label="People">          @for (item of menu.items(); track item.value) {            <div scTriggerMenuItem [item]="item">{{ item.label }}</div>          }        </div>        <div scTriggerMenuStatus>…</div>      </div>    </ng-template>  </div></div>

Triggers

Each trigger is { char, type, items, boundary?: 'word' | 'start', insert? }. It opens after a space, a token or a line's start — or, with boundary: 'start', only at the start of a line. What follows it, up to a space, is the query: it filters the items by label and keywords, or is given to a loader. With an empty part, the menu shows when nothing is found; without one, it closes until something matches. Choosing puts a token of the trigger's type, and a space, in place of the trigger and the query — in a textarea or an input, its text: the trigger and the label, or what the trigger's insert writes (@username); the value stays plain text.

Keyboard

KeyDoes (the caret stays in the editor)
↓ / ↑The next / previous item (wrapping)
Enter / Tab Chooses the highlighted item — Enter never sends while the menu is open
EscapeDismisses this trigger
Ctrl + SpaceBrings a dismissed trigger back

Accessibility

  • The list is a listbox, its items options; the editor points at it (aria-autocomplete="list", aria-controls) and at the highlighted item (aria-activedescendant). Name the list.
  • scTriggerMenuStatus is a polite live region in the popup: write how many were found, or that it is loading; the list is aria-busy while it loads.

Examples

Commands

import { Component, ViewEncapsulation } from '@angular/core';import {  ScTokenInput,  ScTokenInputEditor,  ScTokenInputToken,  type ScTrigger,  ScTriggerMenu,  ScTriggerMenuEmpty,  ScTriggerMenuItem,  ScTriggerMenuList,

Loading

import { Component, ViewEncapsulation } from '@angular/core';import {  ScTokenInput,  ScTokenInputEditor,  ScTokenInputToken,  type ScTrigger,  ScTriggerMenu,  ScTriggerMenuEmpty,  ScTriggerMenuItem,  ScTriggerMenuList,

In a textarea

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScField,  ScLabel,  ScTextarea,  type ScTrigger,  ScTriggerMenu,  ScTriggerMenuEmpty,  ScTriggerMenuInput,  ScTriggerMenuItem,

In an input

import { Component, ViewEncapsulation } from '@angular/core';import {  ScField,  ScInput,  ScLabel,  type ScTrigger,  ScTriggerMenu,  ScTriggerMenuInput,  ScTriggerMenuItem,  ScTriggerMenuList,

In a form

import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import {  ScButton,  ScField,  ScFieldErrors,  ScLabel,  ScTextarea,  type ScTrigger,  ScTriggerMenu,

RTL

الرسالة
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScField,  ScLabel,  ScTokenInput,  ScTokenInputEditor,  ScTokenInputToken,  type ScTrigger,  ScTriggerMenu,

API reference

Each part takes class, merged over its own (cn: a later class wins). The popup, the list and the items have the style's combobox look.

PartSelectorDescription
ScTriggerMenudiv[scTriggerMenu] The root, in a Token Input or around a text field. exportAs scTriggerMenu: match(), items(), active(), loading(), visible(), pick(); (choose) the item chosen.
ScTriggerMenuInputtextarea[scTriggerMenuInput], input[scTriggerMenuInput] A text field it suggests in: the value stays text; a choice is typed in (forms see it).
ScTriggerMenuPortalng-template[scTriggerMenuPortal] Its template, stamped at the trigger while one is typed.
ScTriggerMenuPopupdiv[scTriggerMenuPopup] The popup: below the trigger, above without room.
ScTriggerMenuListdiv[scTriggerMenuList] The listbox. Name it.
ScTriggerMenuItemdiv[scTriggerMenuItem] An option: [item], one of menu.items().
ScTriggerMenuEmpty[scTriggerMenuEmpty] Shown when nothing is found; keeps the menu open then.
ScTriggerMenuStatus[scTriggerMenuStatus] A polite live region (sr-only): your words.
InputTypeDefaultDescription
triggersScTrigger[]— The characters that open it: { char, type, items (an array or a loader), boundary?, insert? (the text an item puts in a text field) }.