Key rules
chatty-composerkhai báo 7 attribute, 1 property không có attribute, 2 event, 2 slot, 3 part và 0 CSS custom property.- Import 1 module
@avada/chatty-ui/elements/composer.jslà definechatty-composer; 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
Form-associated chat input; the host owns sending and attachment upload. Class ChattyComposer.
Attributes
| Name | Property | Type | Default | Description |
|---|---|---|---|---|
value |
value |
string |
'' |
Draft text and form value. |
name |
name |
string |
'message' |
Name used by the enclosing form. |
label |
label |
string |
'Message' |
Accessible input label. |
send- |
sendLabel |
string |
'Send' |
Translated send button text. |
placeholder |
placeholder |
string |
'Write a message…' |
Optional draft hint. |
disabled |
disabled |
boolean |
false |
Prevents edits and submission while pending. |
sending |
sending |
boolean |
false |
Host- |
Properties
Attributes also expose the properties listed in the Property column above.
| Name | Type | Default | Description |
|---|---|---|---|
attachments |
array |
[] |
Attachment descriptors supplied by the host. |
Events
| Name | Detail type | Description |
|---|---|---|
chatty- |
CustomEvent<{ |
Nonempty submission; cancel to retain the draft. |
click |
MouseEvent |
Native send button click. |
Slots
| Name | Description |
|---|---|
toolbar |
Suggestion or prefill actions before the typing row. |
attachments |
Selected attachment previews. |
Parts
| Name | Description |
|---|---|
base |
Composer container. |
control |
Textarea. |
send |
Send button. |
CSS custom properties
Not declared in the manifest.
Usage
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/composer.js';
import '@avada/chatty-ui/elements/button.js';
export function Standard() {
return html`<div
@chatty-send=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
}}
>
<chatty-composer>
<chatty-button
slot="toolbar"
@click=${(event) => event.currentTarget.closest('chatty-composer').send('Track my order')}
>Track my order</chatty-button
>
</chatty-composer>
<p role="status"></p>
</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
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/composer.js';
import '@avada/chatty-ui/elements/button.js';
export function Standard() {
return html`<div
@chatty-send=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
}}
>
<chatty-composer>
<chatty-button
slot="toolbar"
@click=${(event) => event.currentTarget.closest('chatty-composer').send('Track my order')}
>Track my order</chatty-button
>
</chatty-composer>
<p role="status"></p>
</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
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/composer.js';
import '@avada/chatty-ui/elements/button.js';
export function Standard() {
return html`<div
@chatty-send=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent = `Sent: ${event.detail.text}`;
}}
>
<chatty-composer>
<chatty-button
slot="toolbar"
@click=${(event) => event.currentTarget.closest('chatty-composer').send('Track my order')}
>Track my order</chatty-button
>
</chatty-composer>
<p role="status"></p>
</div>`;
}| Part | Element | Source |
|---|---|---|
| 1 | CSS part base |
chatty- |
| 2 | CSS part control |
chatty- |
| 3 | CSS part send |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Enter | Send a nonempty draft; IME composition does not send. |
| Shift+Enter | Insert a new line. |
Source
- chatty-ui/custom-elements.json