Skip to content

Commit 7ffa4d2

Browse files
author
marker dao ®
committed
improve(CTA && MB): Improve types
1 parent b0d0249 commit 7ffa4d2

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

packages/devextreme/js/__internal/ui/chat/message_box/chat_text_area.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import type { DefaultOptionsRule } from '@js/core/options/utils';
44
import type { dxElementWrapper } from '@js/core/renderer';
55
import $ from '@js/core/renderer';
66
import { getOuterHeight } from '@js/core/utils/size';
7+
import type { NativeEventInfo } from '@js/events';
78
import type {
89
ClickEvent,
910
InitializedEvent,
1011
} from '@js/ui/button';
1112
import type Button from '@js/ui/button';
1213
import type { Properties as FileUploaderProperties } from '@js/ui/file_uploader';
13-
import type { EnterKeyEvent } from '@js/ui/text_area';
1414
import { current, isMaterial } from '@js/ui/themes';
1515
import type { Item as ToolbarItem } from '@js/ui/toolbar';
1616
import Toolbar from '@js/ui/toolbar';
@@ -24,10 +24,14 @@ const TEXT_AREA_WITH_TOOLBAR = 'dx-textarea-with-toolbar';
2424

2525
const isMobile = (): boolean => devices.current().deviceType !== 'desktop';
2626

27+
type EnterKeyEvent = NativeEventInfo<ChatTextArea, KeyboardEvent>;
28+
29+
export type SendEvent = ClickEvent | EnterKeyEvent;
30+
2731
export type Properties = TextAreaProperties & {
2832
fileUploaderOptions?: FileUploaderProperties;
2933

30-
onSend?: (e: ClickEvent | EnterKeyEvent) => void;
34+
onSend?: (e: SendEvent) => void;
3135
};
3236

3337
class ChatTextArea extends TextArea<Properties> {
@@ -37,8 +41,7 @@ class ChatTextArea extends TextArea<Properties> {
3741

3842
_sendButton?: Button;
3943

40-
/** KeyboardEvent should be replaced with EnterKeyEvent */
41-
_sendAction?: (e: Partial<ClickEvent | KeyboardEvent>) => void;
44+
_sendAction?: (e: SendEvent) => void;
4245

4346
_getDefaultOptions(): Properties {
4447
return {
@@ -72,7 +75,11 @@ class ChatTextArea extends TextArea<Properties> {
7275
enter: (e): void => {
7376
if (!e?.shiftKey && this._isValuableTextEntered() && !isMobile()) {
7477
e.preventDefault();
75-
this._processSendPress(e);
78+
this._processSendButtonActivation({
79+
component: this,
80+
element: this.element(),
81+
event: e,
82+
});
7683
}
7784
},
7885
};
@@ -172,7 +179,7 @@ class ChatTextArea extends TextArea<Properties> {
172179
'aria-label': messageLocalization.format('dxChat-sendButtonAriaLabel'),
173180
},
174181
onClick: (e: ClickEvent): void => {
175-
this._processSendPress(e);
182+
this._processSendButtonActivation(e);
176183
},
177184
onInitialized: (e: InitializedEvent): void => {
178185
this._sendButton = e.component;
@@ -204,7 +211,7 @@ class ChatTextArea extends TextArea<Properties> {
204211
this._toggleButtonDisableState(shouldButtonBeDisabled);
205212
}
206213

207-
_processSendPress(e: ClickEvent | KeyboardEvent): void {
214+
_processSendButtonActivation(e: SendEvent): void {
208215
this._sendAction?.(e);
209216
this.reset();
210217
this._toggleButtonDisableState(true);

packages/devextreme/js/__internal/ui/chat/message_box/message_box.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import type { NativeEventInfo } from '@js/common/core/events';
22
import $, { type dxElementWrapper } from '@js/core/renderer';
33
import type { InteractionEvent } from '@js/events';
4-
import type { ClickEvent } from '@js/ui/button';
54
import type { Properties as FileUploaderProperties } from '@js/ui/file_uploader';
5+
import type { InputEvent } from '@js/ui/text_area';
66
import type { DOMComponentProperties } from '@ts/core/widget/dom_component';
77
import DOMComponent from '@ts/core/widget/dom_component';
88
import type { OptionChanged } from '@ts/core/widget/types';
9-
import type { Properties as ChatTextAreaProperties } from '@ts/ui/chat/message_box/chat_text_area';
9+
import type {
10+
Properties as ChatTextAreaProperties,
11+
SendEvent,
12+
} from '@ts/ui/chat/message_box/chat_text_area';
1013
import ChatTextArea from '@ts/ui/chat/message_box/chat_text_area';
1114
import EditingPreview from '@ts/ui/chat/message_box/editing_preview';
1215

13-
import type { EnterKeyEvent, InputEvent } from '../../../../ui/text_area';
14-
1516
export const CHAT_MESSAGEBOX_CLASS = 'dx-chat-messagebox';
1617
export const CHAT_MESSAGEBOX_TEXTAREA_CONTAINER_CLASS = 'dx-chat-messagebox-textarea-container';
1718
export const CHAT_MESSAGEBOX_TEXTAREA_CLASS = 'dx-chat-messagebox-textarea';
@@ -167,7 +168,7 @@ class MessageBox extends DOMComponent<MessageBox, Properties> {
167168
this._triggerTypingStartAction(e);
168169
this._updateTypingEndTimeout();
169170
},
170-
onSend: (e: ClickEvent | EnterKeyEvent): void => {
171+
onSend: (e: SendEvent): void => {
171172
this._sendHandler(e);
172173
},
173174
};
@@ -219,7 +220,7 @@ class MessageBox extends DOMComponent<MessageBox, Properties> {
219220
this._typingEndTimeoutId = undefined;
220221
}
221222

222-
_sendHandler(e: ClickEvent | EnterKeyEvent): void {
223+
_sendHandler(e: SendEvent): void {
223224
this._clearTypingEndTimeout();
224225
this._typingEndAction?.();
225226

0 commit comments

Comments
 (0)