On this page

chatty-menu

API chuẩn của element chatty-menu, sinh từ custom-elements.json của prototype trong guide.

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-menu khai báo 3 attribute, 0 property không có attribute, 1 event, 2 slot, 1 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/menu.js là define chatty-menu; chunk chỉ import element nó dùng. Prototype chuẩn: trong guide.
  • Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.
On this page

Overview

An action menu: a chatty-popover whose panel is role menu over chatty-menu-item children. Opening from the trigger focuses the first item; Arrow Up / Down (wrapping), Home and End move between enabled items; activating an item closes the menu and returns focus to the trigger. Class ChattyMenu.

Attributes

Name Property Type Default Description
open open boolean false Shows the panel; the trigger's aria-expanded follows it.
placement placement 'top' | 'bottom' 'bottom' Preferred side of the trigger; the panel flips when that side has no room.
label label string '' Accessible name of the panel.

Properties

Attributes also expose the properties listed in the Property column above.

Not declared in the manifest.

Events

Name Detail type Description
toggle ToggleEvent The menu opened or closed; newState is open or closed.

Slots

Name Description
default chatty-menu-item rows (any element with role menuitem works).
trigger The control that opens the menu; it receives aria-haspopup menu and aria-expanded.

Parts

Name Description
base The top-layer menu panel.

CSS custom properties

Name Default Description
--chatty-popover-min-width – Minimum panel width.
--chatty-popover-padding – Panel padding.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import {
  IconDots,
  IconHeadset,
  IconPaperclip,
  IconSmile,
  IconStar
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-menu prototype chatty-ui ports from (chatty-ui/src/elements/menu.js, menu-item.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/menu.js';
import '@avada/chatty-ui/elements/menu-item.js';

export function Standard() {
  return html`
    <chatty-menu open style="margin-block-end: 220px">
      <button
        slot="trigger"
        type="button"
        aria-label="More"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconDots({size: 16})}
      </button>
      <chatty-menu-item>${IconHeadset({slot: 'icon', size: 16})}Talk to a person</chatty-menu-item>
      <chatty-menu-item>${IconStar({slot: 'icon', size: 16})}Rate this chat</chatty-menu-item>
      <chatty-menu-item>${IconPaperclip({slot: 'icon', size: 16})}Upload file</chatty-menu-item>
      <chatty-menu-item>${IconSmile({slot: 'icon', size: 16})}Emoji</chatty-menu-item>
    </chatty-menu>
  `;
}

Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Standard
LightDarkDesktopMobile

Default: trạng thái mặc định và nội dung mẫu của element.

Show code
chatty-menu.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  IconDots,
  IconHeadset,
  IconPaperclip,
  IconSmile,
  IconStar
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-menu prototype chatty-ui ports from (chatty-ui/src/elements/menu.js, menu-item.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/menu.js';
import '@avada/chatty-ui/elements/menu-item.js';

export function Standard() {
  return html`
    <chatty-menu open style="margin-block-end: 220px">
      <button
        slot="trigger"
        type="button"
        aria-label="More"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconDots({size: 16})}
      </button>
      <chatty-menu-item>${IconHeadset({slot: 'icon', size: 16})}Talk to a person</chatty-menu-item>
      <chatty-menu-item>${IconStar({slot: 'icon', size: 16})}Rate this chat</chatty-menu-item>
      <chatty-menu-item>${IconPaperclip({slot: 'icon', size: 16})}Upload file</chatty-menu-item>
      <chatty-menu-item>${IconSmile({slot: 'icon', size: 16})}Emoji</chatty-menu-item>
    </chatty-menu>
  `;
}
Standard
LightDarkDesktopMobile

Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.

Show code
chatty-menu.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  IconDots,
  IconHeadset,
  IconPaperclip,
  IconSmile,
  IconStar
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-menu prototype chatty-ui ports from (chatty-ui/src/elements/menu.js, menu-item.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/menu.js';
import '@avada/chatty-ui/elements/menu-item.js';

export function States() {
  return html`
    <chatty-menu open style="margin-block-end: 180px">
      <button
        slot="trigger"
        type="button"
        aria-label="More"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconDots({size: 16})}
      </button>
      <chatty-menu-item>Talk to a person</chatty-menu-item>
      <chatty-menu-item disabled>Rate this chat</chatty-menu-item>
      <chatty-menu-item>Emoji</chatty-menu-item>
    </chatty-menu>
  `;
}

Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Standard
LightDarkDesktopMobile

Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

Show code
chatty-menu.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  IconDots,
  IconHeadset,
  IconPaperclip,
  IconSmile,
  IconStar
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-menu prototype chatty-ui ports from (chatty-ui/src/elements/menu.js, menu-item.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/menu.js';
import '@avada/chatty-ui/elements/menu-item.js';

export function Standard() {
  return html`
    <chatty-menu open style="margin-block-end: 220px">
      <button
        slot="trigger"
        type="button"
        aria-label="More"
        style="display:inline-grid;place-items:center;width:32px;height:32px;padding:0;border:1px solid var(--chatty-color-border);border-radius:999px;background:var(--chatty-color-bg-surface);color:var(--chatty-color-text);cursor:pointer"
      >
        ${IconDots({size: 16})}
      </button>
      <chatty-menu-item>${IconHeadset({slot: 'icon', size: 16})}Talk to a person</chatty-menu-item>
      <chatty-menu-item>${IconStar({slot: 'icon', size: 16})}Rate this chat</chatty-menu-item>
      <chatty-menu-item>${IconPaperclip({slot: 'icon', size: 16})}Upload file</chatty-menu-item>
      <chatty-menu-item>${IconSmile({slot: 'icon', size: 16})}Emoji</chatty-menu-item>
    </chatty-menu>
  `;
}
Part Element Source
1 CSS part base chatty-ui/custom-elements.json

Keyboard

Key Action
Enter / Space Open the menu or activate the focused item.
ArrowUp / ArrowDown Move through enabled items, wrapping.
Home / End Focus the first / last item.
Escape Dismiss and return focus.

Source

  • chatty-ui/custom-elements.json