Skip to content

Commit 0695c31

Browse files
committed
chat-widget: submit on keydown
1 parent ca00802 commit 0695c31

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/resources/chat-widget/src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type WidgetConfig = {
3737
api_key: string;
3838
firebaseconfig: any;
3939
dbpath: string;
40+
submitOnKeydown: boolean;
4041
};
4142

4243

@@ -81,6 +82,7 @@ const config: WidgetConfig = {
8182
api_key: "",
8283
firebaseconfig: {},
8384
dbpath: "xyz",
85+
submitOnKeydown: false,
8486
...(window as any).ChatWidget?.config,
8587
};
8688

@@ -284,6 +286,18 @@ function open(e: Event) {
284286
.getElementById("chat-widget__form")!
285287
.addEventListener("submit", submit);
286288

289+
if (config.submitOnKeydown) {
290+
document
291+
.getElementById("chat-widget__input")!
292+
.addEventListener("keydown", (e: KeyboardEvent)=> {
293+
if (e.which === 13 && !e.shiftKey) {
294+
e.preventDefault();
295+
const submitBtn = document.getElementById("chat-widget__submit") as HTMLButtonElement;;
296+
submitBtn.click();
297+
}
298+
});
299+
}
300+
287301
const peerchatSwitchElem = document.getElementById("peerchat-switch") as HTMLInputElement;
288302
if (peerchatSwitchElem) {
289303
peerchatSwitchElem.checked = peerchatmode;

src/resources/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ <h3 class="section__title">Share/Collaborate</h3>
699699
window.ChatWidget.config.dbpath=getExampleRef();
700700
if (!ismob()) {
701701
window.ChatWidget.config.openOnLoad = true;
702+
window.ChatWidget.config.submitOnKeydown = true;
702703
}
703704
window.insertcodesnippet = (encodedcode) => {
704705
const code = atob(encodedcode);

0 commit comments

Comments
 (0)