On this page

chatty-dialog

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-dialog khai báo 3 attribute, 0 property không có attribute, 2 event, 4 slot, 5 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/dialog.js là define chatty-dialog; 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

A modal dialog on the native <dialog> in the top layer: the page behind is inert, focus moves in on open and returns to the opener on close. Escape, a press on the backdrop and the close button ask to close through a cancelable chatty-close. Class ChattyDialog.

Attributes

Name Property Type Default Description
open open boolean false Shows the dialog modally (showModal); the page behind becomes inert.
label label string '' Accessible name; when empty, the heading slot names the dialog.
close-label closeLabel string 'Close' Accessible name of the close button.

Properties

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

Not declared in the manifest.

Events

Name Detail type Description
click MouseEvent Native click of the close button; it bubbles out of the shadow root.
chatty-close CustomEvent<{reason: 'escape' | 'backdrop' | 'close-button'}> A request to close; preventDefault keeps the dialog open.

Slots

Name Description
default Dialog body.
heading Title; names the dialog when label is empty.
footer Actions, aligned to the end.
close-icon Icon of the close button; a cross by default.

Parts

Name Description
base The native dialog box.
header Heading row.
close Close button.
body Body wrapper.
footer Footer wrapper.

CSS custom properties

Name Default Description
--chatty-dialog-width – Dialog width before the viewport clamps it.
--chatty-dialog-backdrop – Backdrop colour.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/dialog.js';
import '@avada/chatty-ui/elements/button.js';
<chatty-dialog open>
  <span slot="heading">Email this chat</span>
  <p style="margin: 0">We will send a copy of this conversation to the email you entered.</p>
  <chatty-button slot="footer">Cancel</chatty-button>
  <chatty-button slot="footer" variant="primary">Send</chatty-button>
</chatty-dialog>
<div style="min-height: 340px"></div>

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-dialog.element.jsWrap code linesCopy
<chatty-dialog open>
  <span slot="heading">Email this chat</span>
  <p style="margin: 0">We will send a copy of this conversation to the email you entered.</p>
  <chatty-button slot="footer">Cancel</chatty-button>
  <chatty-button slot="footer" variant="primary">Send</chatty-button>
</chatty-dialog>
<div style="min-height: 340px"></div>

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-dialog.element.jsWrap code linesCopy
<chatty-dialog open>
  <span slot="heading">Email this chat</span>
  <p style="margin: 0">We will send a copy of this conversation to the email you entered.</p>
  <chatty-button slot="footer">Cancel</chatty-button>
  <chatty-button slot="footer" variant="primary">Send</chatty-button>
</chatty-dialog>
<div style="min-height: 340px"></div>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part header chatty-ui/custom-elements.json
3 CSS part close chatty-ui/custom-elements.json
4 CSS part body chatty-ui/custom-elements.json
5 CSS part footer chatty-ui/custom-elements.json

Keyboard

Key Action
Escape Close the dialog and return focus.
Tab / Shift+Tab Move through the modal controls.

Source

  • chatty-ui/custom-elements.json