Key rules
chatty-dialogkhai 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.jslà definechatty-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- |
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- |
CustomEvent<{ |
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 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 |
|---|---|---|
- |
– | Dialog width before the viewport clamps it. |
- |
– | 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ộ.
Default: trạng thái mặc định và nội dung mẫu của element.
Show code
<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ả.
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 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- |
| 2 | CSS part header |
chatty- |
| 3 | CSS part close |
chatty- |
| 4 | CSS part body |
chatty- |
| 5 | CSS part footer |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Escape | Close the dialog and return focus. |
| Tab / Shift+Tab | Move through the modal controls. |
Source
- chatty-ui/custom-elements.json