From 3281d37bdf80098c411a4101736bfd7c5e568d8d Mon Sep 17 00:00:00 2001 From: Priyanshu Bartwal Date: Tue, 19 May 2026 15:17:18 +0530 Subject: [PATCH] Fix(twenty-front): BlockNote slash command shows empty state when no match (#20689) Fixes: #20625 Original PR: #20626 New changes: - Now the text says "Close menu" instead of "No command found". - "Close menu" is interactive like other commands ( With keyboard and with mouse ). - It closes automatically when user type 3 extra character past the point of no result. https://github.com/user-attachments/assets/9c1315b4-5a63-424d-8da8-dc1283535725 --------- Co-authored-by: Charles Bochet --- .../components/BlockEditor.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx b/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx index c0689304e88..da05f543751 100644 --- a/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx +++ b/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx @@ -1,6 +1,10 @@ -import { filterSuggestionItems } from '@blocknote/core/extensions'; +import { + filterSuggestionItems, + SuggestionMenu, +} from '@blocknote/core/extensions'; import { BlockNoteView } from '@blocknote/mantine'; import { SuggestionMenuController } from '@blocknote/react'; +import { useLingui } from '@lingui/react/macro'; import { styled } from '@linaria/react'; import { type ClipboardEvent, useContext } from 'react'; import { type BLOCK_SCHEMA } from '@/blocknote-editor/blocks/Schema'; @@ -12,6 +16,7 @@ import { type SuggestionItem, } from '@/blocknote-editor/components/CustomSlashMenu'; import { useMentionMenu } from '@/mention/hooks/useMentionMenu'; +import { IconX } from 'twenty-ui/display'; import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants'; interface BlockEditorProps { @@ -149,10 +154,30 @@ export const BlockEditor = ({ readonly, }: BlockEditorProps) => { const { colorScheme } = useContext(ThemeContext); + const { t } = useLingui(); const blockNoteTheme = colorScheme === 'light' ? 'light' : 'dark'; const getMentionItems = useMentionMenu(editor); + const getSlashMenuItems = async (query: string) => { + const filtered = filterSuggestionItems( + getSlashMenu(editor), + query, + ); + + if (filtered.length > 0) { + return filtered; + } + + return [ + { + title: t`Close menu`, + Icon: IconX, + onItemClick: () => editor.getExtension(SuggestionMenu)?.closeMenu(), + }, + ]; + }; + const handleFocus = () => { onFocus?.(); }; @@ -185,9 +210,7 @@ export const BlockEditor = ({ - filterSuggestionItems(getSlashMenu(editor), query) - } + getItems={getSlashMenuItems} suggestionMenuComponent={CustomSlashMenu} />