On this page

Suggested questions

Follow-up chip ngay dưới câu trả lời, theo code AI Mode đang chạy.

Copy page as MarkdownRead Markdown ↗

Key rules

  • Follow-up là button dùng class chatty-suggested-question, xếp cột dưới câu trả lời với gap 8px.
  • Chip chỉ hiện khi không streaming, không lỗi và không ở chế độ human (showSuggests).
  • Mỗi lượt hoàn tất thay bộ chip cũ; không có suggestions thì không hiện chip nào.
  • Client không cắt số chip: số lượng do server trả về trong suggestedQuestions.
On this page

Use when / Avoid

Dùng sau một câu trả lời để khách hỏi tiếp bằng một chạm. Starter ở lần mở đầu thuộc pattern Welcome / first open. Classic không có implementation follow-up tương ứng trong source nên không nằm trong trang này.

Use instead

Component Use when
button Follow-up dưới câu trả lời trong thread.
CommonlyAskedSection Starter ở thread mở đầu, trước tin nhắn đầu tiên của khách.

Entry points

Surface Owner
AI Mode ChatThread render nhóm chip trong Presence khi showSuggests.

Flow

Surface Step Trigger UI shown Component Copy + i18n key Timing
AI Mode Lượt trả lời hoàn tất Server trả suggestedQuestions Store giữ danh sách chip mới Store suggestedQuestions Server-provided Khi lượt kết thúc
AI Mode Hiện chip showSuggests true Nhóm chip dưới câu trả lời button Server-provided Theo Presence
AI Mode Click chip Khách chọn một chip Chip gửi như lượt hỏi mới button Server-provided Khi click
AI Mode Lượt kế tiếp Lượt mới kết thúc Bộ chip cũ bị thay hoặc xóa Store suggestedQuestions Server-provided Khi lượt kết thúc

Edge cases

Surface Case Behaviour
AI Mode Không có suggestions Danh sách rỗng nên showSuggests false và không có chip
AI Mode Đang streaming, lỗi hoặc human mode Chip ẩn
AI Mode Click khi lượt trước còn chạy Bị bỏ qua và không tracking
AI Mode Label dài Chip giữ max-width 100% và ngắt chữ bằng overflow-wrap

Live preview

AI Mode: SignIn, EmailContinue, Reset và Bag ở header: N/A trong preview.

Standard

Chip gửi như lượt hỏi mới; câu trả lời và bộ chip tiếp theo là fixture, không gọi AI.

Current

AI Mode

Standard
LightDarkDesktopMobile

Widget thread Standard; tương tác bằng dữ liệu fixture.

Show code
chatty-pattern-suggested-questions.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import {IconClose, IconMessage} from '@avada/chatty-ui/elements/icon-glyphs.js';
import '@avada/chatty-ui/elements/surface.js';
import '@avada/chatty-ui/elements/avatar.js';
import '@avada/chatty-ui/elements/badge.js';
import '@avada/chatty-ui/elements/icon-button.js';
import '@avada/chatty-ui/elements/launcher.js';
import '@avada/chatty-ui/elements/button.js';
import {sameGroup} from '@avada/chatty-ui/behaviors/messages.js';

// Reference viewport: 1280 × 900 desktop, 390 × 900 mobile.
const sizes = {
  classic: {width: 400, height: 700},
  'ai-mode': {width: 820, height: 657},
  admin: {width: 527, height: 842}
};
const question = {
  id: 'question',
  senderType: 'customer',
  text: 'Can you help me?',
  createdAt: '2026-01-15T10:00:00Z'
};

/** Viewport-relative sizing survives the initial hidden iframe layout. */
function widgetSize(surface) {
  const mode = new URLSearchParams(location.search).get('mobile');
  const isMobile = mode === null ? innerWidth < 900 : mode === 'true';
  const width = `min(${sizes[surface].width}px, max(0px, 100vw - 40px))`;
  const height = isMobile
    ? `min(${surface === 'admin' ? 848 : 888}px, round(down, calc(${width} * 2.2), 1px))`
    : `${sizes[surface].height}px`;
  return {...sizes[surface], height, mobile: isMobile};
}

/** Local immutable message state with real subscriptions for live previews. */
function fixtureStore(initial) {
  let state = {messages: initial};
  const listeners = new Set();
  return {
    getState: () => state,
    subscribe(listener) {
      listeners.add(listener);
      return () => listeners.delete(listener);
    },
    setMessages(messages) {
      state = {messages};
      listeners.forEach(listener => listener());
    }
  };
}

/** Appends the viewer message without replacing the existing conversation. */
function appendViewer(store, surface, text) {
  const message = {
    id: `viewer-${store.getState().messages.length}`,
    senderType: surface === 'admin' ? 'agent' : 'customer',
    senderMeta: {name: surface === 'admin' ? 'Alex' : 'You'},
    text,
    createdAt: new Date().toISOString()
  };
  store.setMessages([...store.getState().messages, message]);
}

/**
 * One shell owns surface sizing, header, thread and composer for every pattern.
 * @param {string} surface
 * @param {Object} store
 * @param {Object} strings
 * @param {Object} content
 * @param {Function} renderMessage
 * @param {Function} onSend
 * @param {Object} registry
 * @param {boolean} composerHidden
 * @param {string} title
 * @param {Object} headerStart
 * @param {Object} headerActions
 * @param {boolean} sheet
 * @param {string | null} status
 * @returns {Object}
 */
function patternShell({
  surface,
  store,
  strings = {header: 'Store assistant', message: 'Message', send: 'Send'},
  content,
  renderMessage,
  onSend,
  registry,
  title,
  headerStart,
  headerActions,
  status = 'online',
  sheet = false,
  composerHidden = false
}) {
  const size = widgetSize(surface);
  const mobileSheet = sheet && size.mobile;
  if (mobileSheet) {
    size.width = 'none';
    size.height = 'calc(100dvh - 12px)';
  }
  const toggle = (event, closed) => {
    const frame = event.currentTarget.closest('[data-pattern-frame]');
    const panel = frame.querySelector('chatty-surface');
    const launcher = frame.querySelector('[data-pattern-launcher]');
    panel.hidden = closed;
    frame.dataset.closed = String(closed);
    const background = frame.querySelector('[data-sheet-page]');
    if (background) background.inert = !closed && surface === 'ai-mode';
    launcher.hidden = !closed;
    if (closed) {
      launcher.style.insetBlockEnd = `${Math.max(surface === 'ai-mode' ? 40 : 16, frame.getBoundingClientRect().bottom - innerHeight + 20)}px`;
      launcher.focus({preventScroll: true});
    } else {
      const composer = panel.querySelector('chatty-composer');
      const input = !composer.hidden
        ? composer.renderRoot.querySelector('textarea')
        : (panel
            .querySelector('chatty-contact-form:not([hidden])')
            ?.renderRoot.querySelector('chatty-text-field') ??
          panel.querySelector('form chatty-text-field') ??
          panel.querySelector('[data-welcome-invitation]:not([hidden]) chatty-button') ??
          panel
            .querySelector('chatty-pre-chat:not([hidden])')
            ?.renderRoot.querySelector('chatty-button'));
      input?.focus({preventScroll: true});
    }
  };
  const sender = message => {
    const content = renderMessage?.(message) ?? {};
    const messages = store.getState().messages;
    const previous = messages[messages.indexOf(message) - 1];
    if (message.senderType !== 'bot' || sameGroup(message, previous)) return content;
    return {
      ...content,
      sender: html`<span style="display:inline-flex;align-items:center;gap:6px"
        ><chatty-avatar size="sm" label="Assistant">A</chatty-avatar
        >${content.sender ?? message.senderName ?? message.senderMeta?.name ?? 'Assistant'}</span
      >`
    };
  };
  return html`<style>
      [data-pattern-frame] {
        display: flex;
        position: relative;
        justify-content: center;
        inline-size: 100%;
        min-inline-size: 0;
      }
      [data-pattern-frame='classic'] {
        justify-content: flex-end;
      }
      [data-pattern-frame] chatty-surface::part(header) {
        padding: 0;
      }
      [data-pattern-frame='classic'] chatty-surface::part(header),
      [data-pattern-frame='ai-mode'] chatty-surface::part(header) {
        border-bottom-width: 0;
      }
      [data-pattern-frame] [hidden] {
        display: none !important;
      }
      [data-pattern-header] {
        display: flex;
        align-items: center;
        gap: 10px;
        box-sizing: border-box;
        min-inline-size: 0;
        block-size: 52px;
        padding: 0 16px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] {
        block-size: 56px;
        background: var(--chatty-color-accent);
        color: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-icon-button {
        --chatty-color-border-focus: var(--chatty-color-on-accent);
      }
      [data-pattern-frame='admin'] [data-pattern-header] {
        block-size: 68px;
        padding: 8px 12px;
      }
      [data-pattern-header] chatty-avatar {
        --chatty-avatar-size: 32px;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar {
        --chatty-avatar-background: #fff;
      }
      [data-pattern-frame='classic'] [data-pattern-header] chatty-avatar::part(base) {
        color: #303030;
        border: 1px solid #767676;
      }
      [data-pattern-actions] {
        display: flex;
        align-items: center;
        gap: 8px;
      }
      [data-pattern-title] {
        flex: 1;
        min-inline-size: 0;
        display: flex;
        flex-direction: column;
      }
      [data-pattern-frame='admin'] [data-pattern-title] {
        gap: 4px;
      }
      [data-pattern-frame='admin'] [data-pattern-title] strong {
        display: flex;
        align-items: center;
        min-block-size: 28px;
        font: var(--p-font-weight-semibold, 650) var(--p-text-heading-md-font-size, 14px) /
          var(--p-text-heading-md-font-line-height, 20px) var(--p-font-family-sans, system-ui);
      }
      [data-pattern-title] strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      [data-pattern-header] chatty-icon-button {
        --chatty-icon-button-size: 32px;
        --chatty-icon-button-color: currentColor;
      }
      @media (max-width: 899px), (pointer: coarse) {
        [data-pattern-header] chatty-icon-button {
          --chatty-icon-button-size: 44px;
        }
      }
      [data-pattern-launcher] {
        position: absolute;
        inset-inline-end: 0;
        inset-block-end: 0;
      }
      [data-pattern-frame='ai-mode'] [data-pattern-launcher] {
        inset-inline-end: auto;
        inset-inline-start: 50%;
        transform: translateX(-50%);
      }
      [data-pattern-frame='classic'] [data-pattern-launcher] {
        --chatty-icon-button-size: 56px;
        border-radius: 50%;
        background: var(--chatty-color-accent);
        --chatty-icon-button-color: var(--chatty-color-on-accent);
      }
      [data-sheet-mobile='true'] {
        position: fixed;
        inset: 0;
        inline-size: 100vw;
      }
      [data-sheet-mobile='true'] chatty-surface::part(base) {
        border-radius: 16px 16px 0 0;
      }
      [data-sheet-mobile='true'] chatty-surface {
        position: relative;
        z-index: 2;
        margin-block-start: 12px;
      }
      [data-sheet-page],
      [data-sheet-scrim] {
        position: absolute;
        inset: 0;
        box-sizing: border-box;
      }
      [data-sheet-page] {
        padding: 20px;
        background: var(--chatty-color-bg-surface);
        color: var(--chatty-color-text);
      }
      [data-sheet-scrim] {
        z-index: 1;
        border: 0;
        background: rgb(0 0 0 / 40%);
        animation: sheet-scrim 400ms ease;
      }
      [data-sheet-mobile='true'][data-closed='true'] [data-sheet-scrim] {
        display: none;
      }
      [data-sheet-mobile='true'] [data-pattern-launcher] {
        z-index: 3;
      }
      @keyframes sheet-scrim {
        from {
          opacity: 0;
        }
        to {
          opacity: 1;
        }
      }
      @media (prefers-reduced-motion: reduce) {
        [data-sheet-scrim] {
          animation: none;
        }
      }
    </style>
    <div
      data-pattern-frame=${surface}
      data-sheet-mobile=${String(mobileSheet)}
      data-closed="false"
      style=${`block-size:calc(${size.height} + ${mobileSheet ? 12 : 0}px)`}
    >
      ${
        mobileSheet
          ? html`<div data-sheet-page .inert=${surface === 'ai-mode'}>
                <p>Example storefront</p>
                <chatty-button
                  variant="secondary"
                  type="button"
                  @click=${event => {
                    event.currentTarget.textContent = 'Products opened';
                  }}
                >
                  Browse products
                </chatty-button>
              </div>
              ${surface === 'ai-mode' ? html`<button type="button" data-sheet-scrim tabindex="-1" aria-label="Close chat background" @click=${event => toggle(event, true)}></button>` : ''}`
          : ''
      }
      <chatty-surface
        data-chatty-surface=${surface}
        data-chatty-theme=${surface === 'admin' ? 'light' : (document.documentElement.dataset.chattyTheme ?? document.documentElement.dataset.theme ?? 'light')}
        style=${`inline-size:100%;max-inline-size:${mobileSheet ? 'none' : `${size.width}px`};--chatty-surface-height:${size.height}`}
        .store=${store}
        .registry=${registry ?? null}
        viewer-type=${surface === 'admin' ? 'agent' : 'customer'}
        .selfTypes=${surface === 'admin' ? ['agent', 'bot'] : null}
        .renderMessage=${sender}
      >
        <div slot="header" data-pattern-header>
          ${headerStart ?? ''}
          ${surface === 'admin' ? '' : html`<chatty-avatar label="Store" .status=${status}>S</chatty-avatar>`}
          <span data-pattern-title
            ><strong
              >${title ?? (surface === 'admin' ? 'Customer conversation' : strings.header)}</strong
            >${surface === 'admin' ? html`<chatty-badge size="sm" variant="secondary" style="align-self:flex-start">Customer</chatty-badge>` : status == null ? '' : html`<small data-pattern-status>${status === 'online' ? 'Open' : 'Closed'}</small>`}</span
          >
          <span data-pattern-actions>${headerActions ?? ''}</span>
          ${
            surface === 'admin'
              ? ''
              : html`<chatty-icon-button label="Close panel" @click=${event => toggle(event, true)}
                  >${IconClose()}</chatty-icon-button
                >`
          }
        </div>
        <chatty-thread .strings=${{bot: 'Assistant', ...strings}}></chatty-thread>${content ?? ''}
        <chatty-composer
          slot="footer"
          ?hidden=${composerHidden}
          .label=${strings.message}
          .sendLabel=${strings.send}
          @chatty-send=${event => {
            appendViewer(store, surface, event.detail.text);
            if (onSend) onSend(event.detail.text, event.currentTarget);
            else if (surface !== 'admin')
              store.setMessages([
                ...store.getState().messages,
                {
                  id: `fixture-${store.getState().messages.length}`,
                  senderType: 'bot',
                  text: `You asked: “${event.detail.text}”. I can help with that.`,
                  hasEventTime: false
                }
              ]);
          }}
        ></chatty-composer> </chatty-surface
      >${
        surface === 'admin'
          ? ''
          : surface === 'ai-mode'
            ? html`<chatty-launcher
                data-pattern-launcher
                hidden
                label="Open chat"
                @chatty-open=${event => toggle(event, false)}
                >${IconMessage({size: 20, slot: 'icon'})}Ask a question</chatty-launcher
              >`
            : html`<chatty-icon-button
                data-pattern-launcher
                hidden
                size="lg"
                label="Open chat"
                @click=${event => toggle(event, false)}
                >${IconMessage({size: 24})}</chatty-icon-button
              >`
      }
    </div>`;
}

import '@avada/chatty-ui/elements/chatty-block-suggestions.js';
export function Standard({surface}) {
  const store = fixtureStore([
    question,
    {
      id: 'answer',
      senderType: 'bot',
      text: 'The canvas tote is reusable.',
      blocks: [
        {type: 'suggestions', data: {suggestions: ['What fits inside?', 'How do I wash it?']}}
      ]
    }
  ]);
  const reply = text => {
    const history = store
      .getState()
      .messages.map(message =>
        message.blocks?.some(block => block.type === 'suggestions')
          ? {...message, blocks: message.blocks.filter(block => block.type !== 'suggestions')}
          : message
      );
    store.setMessages([
      ...history,
      {
        id: `followup-${history.length}`,
        senderType: 'bot',
        text: `You asked: “${text}”. Here is some more information.`,
        blocks: [{type: 'suggestions', data: {suggestions: ['Tell me about the material']}}]
      }
    ]);
  };
  return html`<div
    style="inline-size:100%;min-inline-size:0"
    @chatty-suggest=${event => {
      event.currentTarget.querySelector('chatty-composer').send(event.detail.text);
    }}
  >
    ${patternShell({surface, store, onSend: reply})}
  </div>`;
}
Current (React), being replaced
LightDarkDesktopMobile

Nhóm chip đúng markup của `ChatThread`; dữ liệu cục bộ, không gọi mạng.

Show code
ChatThread.jsxWrap code linesCopy
import {Presence} from '@avada/chatty-ui/primitives/Presence.jsx';

        <Presence show={view.showSuggests}>
          <div className="chatty-chat-suggests">
            {suggestedQuestions.map(q => (
              <button
                key={q}
                type="button"
                className="chatty-chat-suggest chatty-suggested-question"
                onClick={() => askSuggested(q, navigate)}
              >
                <span className="chatty-chat-suggest-text">{q}</span>
              </button>
            ))}
          </div>
        </Presence>

Import / element

Follow-up chip

Component / element Import / file Scope root
button .chatty-ai-mode

Anatomy

Follow-up chip

Part Element
1 Nhóm chatty-chat-suggests chứa các chip.
2 button với chatty-chat-suggest + chatty-suggested-question.
3 spanchatty-chat-suggest-text giữ chữ câu hỏi.

Placement / order

Follow-up chip

Context Order
Thread viewport Sau AnswerError và ContinueWithAIButton, trước chatty-chat-spacer.
Nhóm chip Xếp cột, căn đầu dòng, cách nội dung phía trên 16px.

Props

Follow-up chip

Prop Type Values Default Notes
suggestedQuestions string[] Câu hỏi do server trả [] Không có cắt số lượng trong client; thay mới ở mỗi lượt hoàn tất.

Sizes

Follow-up chip

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Chip min-height 32px 5px 12px; mobile 10px theo block 8px giữa các chip 30px via --radius-pill button-label 14pxDerived(14px = type(button-label, desktop, size)) / 18pxDerived(18px = type(button-label, desktop, line)) desktop; 17pxDerived(17px = type(button-label, mobile, size)) / 24pxDerived(24px = type(button-label, mobile, line)) mobile Native box, mobile min-height 44px Mobile và pointer coarse tăng target

Tokens

Follow-up chip

Part Token Light Dark
Chữ chip --vib-2 rgba(20,19,24,0.74) rgba(255,255,255,0.74)
Viền chip --glass-edge rgba(20,19,24,0.08) rgba(255,255,255,0.12)
Fill hover --fill-hover rgba(20,19,24,0.1) dưới 900px; rgba(255,255,255,0.92) từ min-width 900px rgba(255,255,255,0.14)
Focus ring --focus-ring color-mix(in srgb, var(--accent) 25%, transparent) Same
Bo góc --radius-pill 30px Same

States

Follow-up chip

State Trigger Visual change (values) ARIA/attribute
Rest Chip hiển thị Viền 1px --glass-edge, chữ --vib-2, nền trong suốt button native, type button
Hover Con trỏ Nền --fill-hover Không thêm ARIA
Focus-visible Bàn phím Outline 2px solid --focus-ring, outline-offset 2px Native focus
Disabled Not available Not available; chip không có prop disabled Not available

Behaviour

Follow-up chip

Interaction Result
Click askSuggested gửi chữ chip bằng deliverTurn như lượt hỏi thường.
Chặn gửi canSendMessage sai thì bỏ qua, không tracking.
Tracking quick_reply_click với chip_type follow_up.
Hiện / ẩn Presence theo showSuggests.
Bàn phím button native nhận Enter và Space.

Copy

Follow-up chip

String i18n key Where
Chữ chip Server-provided Phần tử của suggestedQuestions

Source

Follow-up chip

File Evidence
Nhóm chip và Presence
Click gửi lượt hỏi
Điều kiện hiện chip
Layout nhóm chip
Chip material, size và focus

Do / Don't

Accessibility

Surface Role / name Keyboard / focus Live region Contrast pair / ratio
AI Mode button native; tên accessible là chữ câu hỏi Tab và Enter/Space theo button native; askSuggested không gọi hàm focus nào nên focus ở lại chip; outline 2px Not available; Presence không thêm live region cho nhóm chip Light 7.58:1Measured(rgba(20,19,24,0.74) / #f6f4f0 = 7.58:1); Dark 10.42:1Measured(rgba(255,255,255,0.74) / #131215 = 10.42:1)