On this page

Feedback on answers

Survey đánh giá sao một lựa chọn, có góp ý tuỳ chọn, Submit và Skip.

Copy page as MarkdownRead Markdown ↗

Key rules

  • AI Mode: SurveyCard render SurveyView với một radiogroup; sao 24px trong nút 40px desktop, 44px mobile.
  • Classic: SatisfactionSurveyForm render SurveyView; sao 24px, nút 40px desktop, 44px mobile.
  • Cả hai surface chỉ có survey ở mức hội thoại; mã nguồn hiện không có phản hồi riêng cho từng câu trả lời.
  • Host sở hữu persistence; Skip chỉ chuyển focus về composer khi host nhận.
On this page

Use when / Avoid

Dùng survey cuối chat để lấy một rating cho cả hội thoại. Phản hồi từng câu trả lời chưa có trong mã storefront hiện tại.

Use instead

Component Use when
SurveyView Survey rating một lựa chọn kèm góp ý, Submit và Skip.
SurveyRating Chỉ hàng chọn rating, dùng bên trong SurveyView.

Entry points

Surface Owner
AI Mode SurveyCard, render từ khối survey của ChatMessage
Classic SurveyBlock gọi SatisfactionSurveyForm trong registry của widget

Flow

Surface Step Trigger UI shown Component Copy + i18n key Timing
AI Mode Hiện survey Khối survey trong thread Card với tiêu đề, gợi ý, hàng rating SurveyView Choose stars to send Caller render
AI Mode Chọn rating Click hoặc phím Textarea góp ý xuất hiện SurveyView Feedback (optional) Tức thì
AI Mode Submit Click Submit Spinner trên Submit; đóng thì card chuyển sang lời cảm ơn, lỗi thì hiện alert SurveyView Submit Caller async
AI Mode Skip Click Skip Spinner trên Skip; host nhận thì card biến mất SurveyView Skip Caller async
Classic Submit Click Submit Spinner trên Submit; thành công thì chuyển sang lời cảm ơn SurveyView Submit Caller async
Classic Skip Click Skip Spinner trên Skip; thành công thì set skipped SurveyView Skip Caller async

Edge cases

Surface Case Behaviour
AI Mode Survey đã skip SurveyCard trả về null
AI Mode Survey của ticket isTicketSurvey lấy rating và trạng thái từ surveyResult của khối
AI Mode Định dạng emoji emoji bật khi format là EMOJI, kèm renderEmoji
Classic Người xem là admin readOnly bật; submit và skip bị chặn
Classic Chế độ preview Submit và skip chỉ đổi state cục bộ, không gọi server

Live preview

Classic: bubble thu gọn là fixture từ chatty-icon-button; Current: FloatButtonWidget, chưa có element. Bag và menu (…) ở header: N/A trong preview.

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

Standard

Standard
LightDarkDesktopMobile

Thread Standard dùng fixture cục bộ.

Show code
chatty-pattern-feedback-on-answers.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 {createBlockRegistry} from '@avada/chatty-ui/behaviors/block-registry.js';
import '@avada/chatty-ui/elements/chatty-block-survey.js';
export function Standard({surface}) {
  const registry = createBlockRegistry({survey: 'chatty-block-survey'});
  const store = fixtureStore([
    question,
    {id: 'answer', senderType: 'bot', text: 'Your order is on its way.'},
    {id: 'survey', senderType: 'bot', blocks: [{type: 'survey', data: {}}]}
  ]);
  let failed = false;
  const save = (event, skip = false) => {
    const survey = event.composedPath().find(node => node.localName === 'chatty-survey');
    const composer = event.currentTarget.querySelector('chatty-composer');
    survey.busy = skip ? 'skip' : 'submit';
    const finish = async () => {
      if (skip) {
        store.setMessages(store.getState().messages.filter(m => m.id !== 'survey'));
        await composer.updateComplete;
        composer.shadowRoot.querySelector('textarea').focus();
      } else if (!failed) {
        failed = true;
        survey.busy = '';
        survey.error = true;
        await survey.updateComplete;
        const alert = survey.shadowRoot.querySelector('[role=alert]');
        alert.tabIndex = -1;
        alert.focus();
      } else {
        survey.error = false;
        survey.busy = '';
        survey.submitted = true;
        await survey.updateComplete;
        const status = survey.shadowRoot.querySelector('[role=status]');
        status.tabIndex = -1;
        status.focus();
      }
    };
    if (matchMedia('(prefers-reduced-motion: reduce)').matches) finish();
    else setTimeout(finish, 450);
  };
  return html`<div
    style="inline-size:100%;min-inline-size:0"
    @chatty-submit=${event => save(event)}
    @chatty-skip=${event => save(event, true)}
  >
    ${patternShell({surface, store, registry})}
  </div>`;
}

Survey nằm trong tin bot qua registry opt-in. Submit lần đầu trả lỗi fixture; Submit lần hai thành công. Skip dùng request fixture thành công. History và restored rating: N/A trong preview.

Current

AI Mode

Current (React), being replaced
LightDarkDesktopMobile

SurveyView thật theo CSS AI Mode; dữ liệu và callback chỉ ở mẫu, không lưu gì.

Show code
feedback-on-answers.jsxWrap code linesCopy
import React, {useState} from 'react';
import {SurveyView} from '@avada/chatty-ui/primitives/SurveyView.jsx';

export function Survey() {
  const [rating, setRating] = useState(0);
  const [comment, setComment] = useState('');
  const [submitted, setSubmitted] = useState(false);
  const [skipped, setSkipped] = useState(false);
  if (skipped) return <p role="status">Survey skipped locally.</p>;
  return (
    <SurveyView
      title="How was your experience?"
      thanks="Thank you for your feedback."
      translate={(text, values) => text.replace('{{rating}}', values?.rating ?? '')}
      ratings={[1, 2, 3, 4, 5].map(id => ({id}))}
      rating={rating}
      onRatingChange={setRating}
      comment={comment}
      onCommentChange={setComment}
      onSubmit={() => setSubmitted(true)}
      onSkip={() => {setSkipped(true); return true;}}
      submitted={submitted}
      announce
    />
  );
}

Import / element

SurveyView

Component / element Import / file Scope root
SurveyView @avada/chatty-ui/primitives/SurveyView.jsx .chatty-ai-mode

SurveyRating

Component / element Import / file Scope root
SurveyRating @avada/chatty-ui/primitives/SurveyRating.jsx .chatty-ai-mode

Anatomy

SurveyView

Part Element
1 h3 tiêu đề; sau khi gửi thay bằng khối cảm ơn.
2 p gợi ý Choose stars to send, ẩn khi đã gửi hoặc readOnly.
3 SurveyRating một hàng sao hoặc emoji.
4 label + textarea góp ý, chỉ hiện khi đã chọn rating.
5 Khối lỗi có role="alert".
6 Hai button: Submit và Skip.

SurveyRating

Part Element
1 Container radiogroup; ở chế độ readOnly là img có aria-label.
2 buttonrole="radio" cho mỗi rating.
3 span trang trí aria-hidden: svg ngôi sao hoặc emoji.

Placement / order

SurveyView

Context Order
Chưa gửi Tiêu đề, gợi ý, rating, góp ý (khi có rating), lỗi (khi error), rồi Submit và Skip.
Đã gửi Khối cảm ơn thay tiêu đề; gợi ý, góp ý và hai nút không render.

SurveyRating

Context Order
Trong SurveyView Đứng giữa gợi ý và ô góp ý, nhận labelledBy và describedBy từ tiêu đề và gợi ý.

Props

SurveyView

Prop Type Values Default Notes
rating number Rating đang chọn Caller Truyền xuống SurveyRating làm value.
onSubmit Function Callback của host Caller Host sở hữu persistence và chuyển trạng thái sau khi nhận.
onSkip Function Trả về truthy khi host nhận Skip Caller Chỉ khi truthy mới đưa focus về ô nhập của composer.
busyAction string submit hoặc skip Không có Khoá toàn bộ control; chỉ nút vừa bấm có aria-busy true.
error boolean true hoặc false Không có Hiện khối lỗi role="alert" phía trên hai nút.
submitted boolean true hoặc false Không có Chuyển sang khối cảm ơn.
announce boolean true hoặc false Không có Chỉ khi submitted và announce mới đặt role status.
readOnly boolean true hoặc false Không có Khoá control và ẩn hint, góp ý, hai nút.
emoji boolean true hoặc false Không có Chọn emoji thay sao; cần ratings và renderEmoji.

SurveyRating

Prop Type Values Default Notes
ratings Object[] Mỗi phần tử có id Bắt buộc Số phần tử quyết định số sao hoặc emoji.
value number id đang chọn 0 Sao có id nhỏ hơn hoặc bằng giá trị được tô.
onChange Function Nhận id mới Bắt buộc Gọi khi click hoặc phím.
readOnly boolean true hoặc false Không có Render img và span thay cho nút.
disabled boolean true hoặc false Không có Khoá phím, hover preview và nút.

Sizes

SurveyView

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Card Theo nội dung 16px 0 20px Tiêu đề heading-medium 15pxDerived(15px = type(heading-medium, desktop, size)) / 22pxDerived(22px = type(heading-medium, desktop, line)) → 17pxDerived(17px = type(heading-medium, mobile, size)) / 24pxDerived(24px = type(heading-medium, mobile, line)), weight 500; gợi ý body-small 14pxDerived(14px = type(body-small, desktop, size)) / 20pxDerived(20px = type(body-small, desktop, line)) → 15pxDerived(15px = type(body-small, mobile, size)) / 22pxDerived(22px = type(body-small, mobile, line)) Không tương tác width 100%, max-width 380px; mobile theo mobile mixin
Action button --survey-hit: 40px desktop → 44px mobile 0 12px; Submit thêm padding-inline 16px 6px trong nút; 8px giữa hai nút 999px button-label 14pxDerived(14px = type(button-label, desktop, size)) / 18pxDerived(18px = type(button-label, desktop, line)) → 17pxDerived(17px = type(button-label, mobile, size)) / 24pxDerived(24px = type(button-label, mobile, line)) 40px desktop → 44px mobile Mobile mixin khi có class mobile của surface hoặc max-width 899px
Comment textarea --survey-comment-height: 88px desktop → 96px mobile 12px 4px giữa nhãn và ô 10px input-value 15pxDerived(15px = type(input-value, desktop, size)) / 22pxDerived(22px = type(input-value, desktop, line)) → 18pxDerived(18px = type(input-value, mobile, size)) / 24pxDerived(24px = type(input-value, mobile, line)), weight 400 Theo textarea Mobile mixin như trên

SurveyRating

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Rating button --survey-hit: 40px desktop → 44px mobile 0 4px giữa các nút 8px Không có chữ 40px desktop → 44px mobile Mobile mixin khi có class mobile của surface hoặc max-width 899px
Star art 24px × 24px Không có Không có Không có Không có chữ Nằm trong nút Cùng kích thước ở mọi breakpoint

Tokens

SurveyView

Part Token Light Dark
Card surface --survey-surface --fill-1: rgba(20, 19, 24, 0.04) dưới 900px; rgba(255, 255, 255, 0.42) từ 900px rgba(255, 255, 255, 0.06)
Card border --chatty-color-border --glass-edge: rgba(20, 19, 24, 0.08) rgba(255, 255, 255, 0.12)
Text --chatty-color-text --vib-1: rgba(20, 19, 24, 0.94) rgba(255, 255, 255, 0.96)
Hint --chatty-color-text-secondary --vib-2: rgba(20, 19, 24, 0.74) rgba(255, 255, 255, 0.74)
Submit fill --survey-primary --accent: merchant --faqsBtnPopupColor, fallback #8b7be8 Cùng định nghĩa
Submit text --survey-on-primary --on-accent: merchant --faqsFloatBtnLabelColor, fallback #fff Cùng định nghĩa
Error --survey-error-color #c5280c color-mix(in srgb, #ff9a8a, white 60%)

SurveyRating

Part Token Light Dark
Star active --chatty-color-rating #b77900 #f5c542
Star outline --survey-star-outline --chatty-color-text-secondary: rgba(20, 19, 24, 0.74) Fallback --chatty-color-border-strong: #aaa
Focus ring --chatty-color-text --vib-1: rgba(20, 19, 24, 0.94) rgba(255, 255, 255, 0.96)

States

SurveyView

State Trigger Visual change (values) ARIA/attribute
Submit disabled !rating hoặc đang busy Nền --chatty-color-bg-surface-secondary, chữ --chatty-color-text-disabled disabled
Submit busy busyAction là submit Spinner 16px, viền 2px, 0.8s linear infinite aria-busy true
Skip busy busyAction là skip Spinner 16px cạnh nhãn Skip aria-busy true
Skip hover / active pointer Nền color-mix 8% khi hover, 12% khi active Không thêm ARIA
Focus-visible keyboard outline 2px solid --chatty-color-text, offset 2px Native focus
Error error true Chữ --chatty-color-critical, icon cạnh nội dung role="alert"
Submitted submitted true Khối cảm ơn, rating chỉ đọc role status khi announce
Reduced motion prefers-reduced-motion: reduce Spinner animation: none Không thêm ARIA

SurveyRating

State Trigger Visual change (values) ARIA/attribute
Hover pointer, không disabled Nền color-mix 8%; sao preview theo rating đang hover Không thêm ARIA
Active pointer down Nền color-mix 12% Không thêm ARIA
Checked rating.id === value Sao có id nhỏ hơn hoặc bằng giá trị đổi sang fill currentColor aria-checked
Disabled disabled opacity: 1, con trỏ mặc định disabled
Focus-visible keyboard outline 2px solid --chatty-color-text, offset 2px Native focus

Behaviour

SurveyView

Interaction Result
Skip Gọi onSkip; nếu kết quả truthy, focus chuyển tới ô nhập của composer trong surface.
Góp ý Textarea hiện sau khi có rating, giới hạn 250 ký tự.
Submit không có rating Nút disabled và mô tả bởi gợi ý.
Host Host sở hữu persistence và bước chuyển sau submit hoặc skip.

SurveyRating

Interaction Result
Phím mũi tên Phải hoặc xuống chọn rating kế tiếp, trái hoặc lên chọn rating trước, vòng tròn ở hai đầu.
Space và Enter Chọn rating của nút đang focus.
Tab stop Một tab stop: nút đang chọn, hoặc nút đầu khi chưa chọn.
Hover Chỉ xem trước; không đổi giá trị đã chọn.

Copy

SurveyView

String i18n key Where
Choose stars to send Choose stars to send Gợi ý dưới tiêu đề, qua translate
Rate your experience Rate your experience Nhãn tóm tắt khi chưa có rating
Feedback (optional) Feedback (optional) Nhãn textarea
Tell us about your experience Tell us about your experience Placeholder textarea
Something went wrong. Please try again. Something went wrong. Please try again. Khối lỗi
Submit Submit Nhãn nút gửi
Skip Skip Nhãn nút bỏ qua
Tiêu đề và lời cảm ơn Do host truyền Props title và thanks

SurveyRating

String i18n key Where
Rate {{rating}} out of 5 Rate {{rating}} out of 5 aria-label của mỗi nút

Source

SurveyView

File Evidence
API và markup
Kích thước, trạng thái, mobile mixin
Type role

SurveyRating

File Evidence
API và markup
Kích thước, trạng thái

Classic

Current (React), being replaced
LightDarkDesktopMobile

SurveyView thật trong popup Classic; dữ liệu và callback chỉ ở mẫu.

Show code
feedback-on-answers.jsxWrap code linesCopy
import React, {useState} from 'react';
import {SurveyView} from '@avada/chatty-ui/primitives/SurveyView.jsx';

export function Survey() {
  const [rating, setRating] = useState(0);
  const [comment, setComment] = useState('');
  const [submitted, setSubmitted] = useState(false);
  const [skipped, setSkipped] = useState(false);
  if (skipped) return <p role="status">Survey skipped locally.</p>;
  return (
    <SurveyView
      title="How was your experience?"
      thanks="Thank you for your feedback."
      translate={(text, values) => text.replace('{{rating}}', values?.rating ?? '')}
      ratings={[1, 2, 3, 4, 5].map(id => ({id}))}
      rating={rating}
      onRatingChange={setRating}
      comment={comment}
      onCommentChange={setComment}
      onSubmit={() => setSubmitted(true)}
      onSkip={() => {setSkipped(true); return true;}}
      submitted={submitted}
      announce
    />
  );
}

Import / element

SurveyView

Component / element Import / file Scope root
SurveyView @avada/chatty-ui/primitives/SurveyView.jsx .Avada-Faqs_Popup

SurveyRating

Component / element Import / file Scope root
SurveyRating @avada/chatty-ui/primitives/SurveyRating.jsx .Avada-Faqs_Popup

Anatomy

SurveyView

Part Element
1 h3 tiêu đề; sau khi gửi thay bằng khối cảm ơn.
2 p gợi ý Choose stars to send, ẩn khi đã gửi hoặc readOnly.
3 SurveyRating một hàng sao hoặc emoji.
4 label + textarea góp ý, chỉ hiện khi đã chọn rating.
5 Khối lỗi có role="alert".
6 Hai button: Submit và Skip.

SurveyRating

Part Element
1 Container radiogroup; ở chế độ readOnly là img có aria-label.
2 buttonrole="radio" cho mỗi rating.
3 span trang trí aria-hidden: svg ngôi sao hoặc emoji.

Placement / order

SurveyView

Context Order
Chưa gửi Tiêu đề, gợi ý, rating, góp ý (khi có rating), lỗi (khi error), rồi Submit và Skip.
Đã gửi Khối cảm ơn thay tiêu đề; gợi ý, góp ý và hai nút không render.

SurveyRating

Context Order
Trong SurveyView Đứng giữa gợi ý và ô góp ý, nhận labelledBy và describedBy từ tiêu đề và gợi ý.

Props

SurveyView

Prop Type Values Default Notes
rating number Rating đang chọn Caller Truyền xuống SurveyRating làm value.
onSubmit Function Callback của host Caller Host sở hữu persistence và chuyển trạng thái sau khi nhận.
onSkip Function Trả về truthy khi host nhận Skip Caller Chỉ khi truthy mới đưa focus về ô nhập của composer.
busyAction string submit hoặc skip Không có Khoá toàn bộ control; chỉ nút vừa bấm có aria-busy true.
error boolean true hoặc false Không có Hiện khối lỗi role="alert" phía trên hai nút.
submitted boolean true hoặc false Không có Chuyển sang khối cảm ơn.
announce boolean true hoặc false Không có Chỉ khi submitted và announce mới đặt role status.
readOnly boolean true hoặc false Không có Khoá control và ẩn hint, góp ý, hai nút.
emoji boolean true hoặc false Không có Chọn emoji thay sao; cần ratings và renderEmoji.

SurveyRating

Prop Type Values Default Notes
ratings Object[] Mỗi phần tử có id Bắt buộc Số phần tử quyết định số sao hoặc emoji.
value number id đang chọn 0 Sao có id nhỏ hơn hoặc bằng giá trị được tô.
onChange Function Nhận id mới Bắt buộc Gọi khi click hoặc phím.
readOnly boolean true hoặc false Không có Render img và span thay cho nút.
disabled boolean true hoặc false Không có Khoá phím, hover preview và nút.

Sizes

SurveyView

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Card Theo nội dung 16px 0 20px Tiêu đề heading-medium 15pxDerived(15px = type(heading-medium, desktop, size)) / 22pxDerived(22px = type(heading-medium, desktop, line)) → 17pxDerived(17px = type(heading-medium, mobile, size)) / 24pxDerived(24px = type(heading-medium, mobile, line)), weight 500; gợi ý body-small 14pxDerived(14px = type(body-small, desktop, size)) / 20pxDerived(20px = type(body-small, desktop, line)) → 15pxDerived(15px = type(body-small, mobile, size)) / 22pxDerived(22px = type(body-small, mobile, line)) Không tương tác width 100%, max-width 380px; mobile theo mobile mixin
Action button --survey-hit: 40px desktop → 44px mobile 0 12px; Submit thêm padding-inline 16px 6px trong nút; 8px giữa hai nút 999px button-label 14pxDerived(14px = type(button-label, desktop, size)) / 18pxDerived(18px = type(button-label, desktop, line)) → 17pxDerived(17px = type(button-label, mobile, size)) / 24pxDerived(24px = type(button-label, mobile, line)) 40px desktop → 44px mobile Mobile mixin khi có class mobile của surface hoặc max-width 899px
Comment textarea --survey-comment-height: 88px desktop → 96px mobile 12px 4px giữa nhãn và ô 10px input-value 15pxDerived(15px = type(input-value, desktop, size)) / 22pxDerived(22px = type(input-value, desktop, line)) → 18pxDerived(18px = type(input-value, mobile, size)) / 24pxDerived(24px = type(input-value, mobile, line)), weight 400 Theo textarea Mobile mixin như trên

SurveyRating

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
Rating button --survey-hit: 40px desktop → 44px mobile 0 4px giữa các nút 8px Không có chữ 40px desktop → 44px mobile Mobile mixin khi có class mobile của surface hoặc max-width 899px
Star art 24px × 24px Không có Không có Không có Không có chữ Nằm trong nút Cùng kích thước ở mọi breakpoint

Tokens

SurveyView

Part Token Light Dark
Card border --chatty-color-border #e3e3e3 #ffffff17
Card surface --chatty-color-bg-surface #fff #1a1a1a
Text --chatty-color-text #303030 #eee
Hint --chatty-color-text-secondary #616161 #aaa
Submit fill --survey-primary --faqsBtnPopupColor, fallback --chatty-color-accent (#303030) Fallback #eee
Submit text --survey-on-primary --faqsBtnPopupTextColor, fallback --chatty-color-on-accent (#fff) Fallback #1a1a1a
Submit disabled --chatty-color-bg-surface-secondary #f7f7f7 #282828
Error --chatty-color-critical #c5280c #ff9a8a

SurveyRating

Part Token Light Dark
Star active --chatty-color-rating #b77900 #f5c542
Star outline --chatty-color-border-strong #8a8a8a #aaa
Focus ring --chatty-color-text #303030 #eee

States

SurveyView

State Trigger Visual change (values) ARIA/attribute
Submit disabled !rating hoặc đang busy Nền --chatty-color-bg-surface-secondary, chữ --chatty-color-text-disabled disabled
Submit busy busyAction là submit Spinner 16px, viền 2px, 0.8s linear infinite aria-busy true
Skip busy busyAction là skip Spinner 16px cạnh nhãn Skip aria-busy true
Skip hover / active pointer Nền color-mix 8% khi hover, 12% khi active Không thêm ARIA
Focus-visible keyboard outline 2px solid --chatty-color-text, offset 2px Native focus
Error error true Chữ --chatty-color-critical, icon cạnh nội dung role="alert"
Submitted submitted true Khối cảm ơn, rating chỉ đọc role status khi announce
Reduced motion prefers-reduced-motion: reduce Spinner animation: none Không thêm ARIA

SurveyRating

State Trigger Visual change (values) ARIA/attribute
Hover pointer, không disabled Nền color-mix 8%; sao preview theo rating đang hover Không thêm ARIA
Active pointer down Nền color-mix 12% Không thêm ARIA
Checked rating.id === value Sao có id nhỏ hơn hoặc bằng giá trị đổi sang fill currentColor aria-checked
Disabled disabled opacity: 1, con trỏ mặc định disabled
Focus-visible keyboard outline 2px solid --chatty-color-text, offset 2px Native focus

Behaviour

SurveyView

Interaction Result
Skip Gọi onSkip; nếu kết quả truthy, focus chuyển tới ô nhập của composer trong surface.
Góp ý Textarea hiện sau khi có rating, giới hạn 250 ký tự.
Submit không có rating Nút disabled và mô tả bởi gợi ý.
Host Host sở hữu persistence và bước chuyển sau submit hoặc skip.

SurveyRating

Interaction Result
Phím mũi tên Phải hoặc xuống chọn rating kế tiếp, trái hoặc lên chọn rating trước, vòng tròn ở hai đầu.
Space và Enter Chọn rating của nút đang focus.
Tab stop Một tab stop: nút đang chọn, hoặc nút đầu khi chưa chọn.
Hover Chỉ xem trước; không đổi giá trị đã chọn.

Copy

SurveyView

String i18n key Where
Choose stars to send Choose stars to send Gợi ý dưới tiêu đề, qua translate
Rate your experience Rate your experience Nhãn tóm tắt khi chưa có rating
Feedback (optional) Feedback (optional) Nhãn textarea
Tell us about your experience Tell us about your experience Placeholder textarea
Something went wrong. Please try again. Something went wrong. Please try again. Khối lỗi
Submit Submit Nhãn nút gửi
Skip Skip Nhãn nút bỏ qua
Tiêu đề và lời cảm ơn Do host truyền Props title và thanks

SurveyRating

String i18n key Where
Rate {{rating}} out of 5 Rate {{rating}} out of 5 aria-label của mỗi nút

Source

SurveyView

File Evidence
API và markup
Kích thước, trạng thái, mobile mixin
Type role

SurveyRating

File Evidence
API và markup
Kích thước, trạng thái

Do / Don't

Accessibility

Surface Role / name Keyboard / focus Live region Contrast pair / ratio
AI Mode radiogroup tên từ tiêu đề; mỗi sao là role="radio" có aria-label Rate n out of 5 Một tab stop; mũi tên đổi lựa chọn; focus ring outline 2px solid, offset 2px; sau Skip focus về ô nhập composer role status khi announce sau submit; lỗi dùng role="alert" Không đo: nền và chữ dùng rgba trong suốt
Classic radiogroup tên từ tiêu đề; mỗi sao là role="radio" có aria-label Rate n out of 5 Một tab stop; mũi tên đổi lựa chọn; focus ring outline 2px solid, offset 2px; sau Skip focus về ô nhập composer role status khi announce sau submit; lỗi dùng role="alert" 13.2:1Measured(#303030 / #ffffff = 13.2:1) light; 15:1Measured(#eeeeee / #1a1a1a = 15:1) dark