Prevent mobile keyboards from closing when sending messages and override enter key to always be new line on mobile
This commit is contained in:
1 parent
555df76373
commit
5bd0b5cfa7
4 files changed
+16
-5
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
RenderLeafProps,
|
||||
RenderElementProps,
|
||||
RenderPlaceholderProps,
|
||||
ReactEditor,
|
||||
} from 'slate-react';
|
||||
import { withHistory } from 'slate-history';
|
||||
import { BlockType } from './types';
|
||||
@@ -23,6 +24,7 @@ import { RenderElement, RenderLeaf } from './Elements';
|
||||
import { CustomElement } from './slate';
|
||||
import * as css from './Editor.css';
|
||||
import { toggleKeyboardShortcut } from './keyboard';
|
||||
import { mobileOrTablet } from '../../utils/user-agent';
|
||||
|
||||
const initialValue: CustomElement[] = [
|
||||
{
|
||||
@@ -99,7 +101,13 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
|
||||
|
||||
const handleKeydown: KeyboardEventHandler = useCallback(
|
||||
(evt) => {
|
||||
// mobile ignores config option
|
||||
if (mobileOrTablet() && evt.key === 'Enter' && !evt.shiftKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
onKeyDown?.(evt);
|
||||
|
||||
const shortcutToggled = toggleKeyboardShortcut(editor, evt);
|
||||
if (shortcutToggled) evt.preventDefault();
|
||||
},
|
||||
@@ -146,6 +154,8 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
|
||||
onKeyDown={handleKeydown}
|
||||
onKeyUp={onKeyUp}
|
||||
onPaste={onPaste}
|
||||
// keeps focus after pressing send.
|
||||
onBlur={() => { if (mobileOrTablet()) ReactEditor.focus(editor); }}
|
||||
/>
|
||||
</Scroll>
|
||||
{after && (
|
||||
|
||||
@@ -309,6 +309,8 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
resetEditor(editor);
|
||||
resetEditorHistory(editor);
|
||||
sendTypingStatus(false);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -643,7 +645,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
</PopOut>
|
||||
)}
|
||||
</UseStateProvider>
|
||||
<IconButton onClick={submit} variant="SurfaceVariant" size="300" radii="300">
|
||||
<IconButton onClick={submit} onMouseDown={(e) => e.preventDefault()} variant="SurfaceVariant" size="300" radii="300">
|
||||
<Icon src={Icons.Send} />
|
||||
</IconButton>
|
||||
</>
|
||||
|
||||
@@ -718,9 +718,8 @@ function Editor() {
|
||||
<SequenceCard className={SequenceCardStyle} variant="SurfaceVariant" direction="Column">
|
||||
<SettingTile
|
||||
title="ENTER for Newline"
|
||||
description={`Use ${
|
||||
isMacOS() ? KeySymbol.Command : 'Ctrl'
|
||||
} + ENTER to send message and ENTER for newline.`}
|
||||
description={`Use ${isMacOS() ? KeySymbol.Command : 'Ctrl'
|
||||
} + ENTER to send message and ENTER for newline. Ignored on mobile.`}
|
||||
after={<Switch variant="Primary" value={enterForNewline} onChange={setEnterForNewline} />}
|
||||
/>
|
||||
</SequenceCard>
|
||||
|
||||
+1
-1
@@ -1,5 +1,6 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
import { wasm } from '@rollup/plugin-wasm';
|
||||
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
||||
@@ -10,7 +11,6 @@ import { VitePWA } from 'vite-plugin-pwa';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import buildConfig from './build.config';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
const copyFiles = {
|
||||
targets: [
|
||||
|
||||
Reference in new issue
Block a user