Skip to content

fix(designer): Prevent Key Stroke propagation in Lexical #4145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libs/designer-ui/src/lib/editor/base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import IgnoreTab from './plugins/IgnoreTab';
import InsertTokenNode from './plugins/InsertTokenNode';
import OpenTokenPicker from './plugins/OpenTokenPicker';
import { PastePlugin } from './plugins/Paste';
import { PreventPropagationPlugin } from './plugins/PreventPropagation';
import { ReadOnly } from './plugins/ReadOnly';
import SingleValueSegment from './plugins/SingleValueSegment';
import { TokenTypeAheadPlugin } from './plugins/TokenTypeahead';
Expand Down Expand Up @@ -81,6 +82,7 @@ export interface BasePlugins {
history?: boolean;
tokens?: boolean;
treeView?: boolean;
preventPropagation?: boolean;
htmlEditor?: 'rich-html' | 'raw-html' | false;
tabbable?: boolean;
singleValueSegment?: boolean;
Expand Down Expand Up @@ -135,6 +137,7 @@ export const BaseEditor = ({
htmlEditor = false,
tabbable,
singleValueSegment = false,
preventPropagation = true,
} = basePlugins;

const describedByMessage = intl.formatMessage({
Expand Down Expand Up @@ -205,6 +208,7 @@ export const BaseEditor = ({
{autoLink ? <AutoLink /> : null}
{clearEditor ? <ClearEditor showButton={false} /> : null}
{singleValueSegment ? <SingleValueSegment /> : null}
{preventPropagation ? <PreventPropagationPlugin /> : null}
<FocusChangePlugin onFocus={handleFocus} onBlur={handleBlur} onClick={handleClick} />
<ReadOnly readonly={readonly} />
{tabbable ? null : <IgnoreTab />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { COMMAND_PRIORITY_EDITOR, KEY_DOWN_COMMAND } from 'lexical';

export const PreventPropagationPlugin = () => {
const [editor] = useLexicalComposerContext();
editor.registerCommand(
KEY_DOWN_COMMAND,
(event: KeyboardEvent) => {
event.stopPropagation();
return false;
},
COMMAND_PRIORITY_EDITOR
);
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
background: #fff;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
border-radius: 8px;
margin-top: 25px;
margin-top: 10px;
z-index: 1000000;
position: fixed;
ul {
Expand Down