From db2e958823ef1cce5b860f910fc782a19ef28093 Mon Sep 17 00:00:00 2001 From: David Langley Date: Wed, 17 Sep 2025 12:47:20 +0100 Subject: [PATCH] Disable RTE formatting buttons when the content contains a slash command (#30802) * Add ability to disable all formatting buttons * Create hook to check if the content contains a slash command * Disable the formatting buttons if the message content contains a slash command * lint * typo --- .../components/FormattingButtons.tsx | 31 ++-- .../components/WysiwygComposer.tsx | 6 +- .../hooks/useContainsCommand.ts | 53 ++++++ .../components/FormattingButtons-test.tsx | 10 ++ .../components/WysiwygComposer-test.tsx | 19 +++ .../hooks/useContainsCommand-test.tsx | 161 ++++++++++++++++++ 6 files changed, 266 insertions(+), 14 deletions(-) create mode 100644 src/components/views/rooms/wysiwyg_composer/hooks/useContainsCommand.ts create mode 100644 test/unit-tests/components/views/rooms/wysiwyg_composer/hooks/useContainsCommand-test.tsx diff --git a/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx b/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx index 27301110f3..15d6405d87 100644 --- a/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx +++ b/src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx @@ -43,6 +43,7 @@ function Button({ label, keyCombo, onClick, actionState, icon }: ButtonProps): J element="button" onClick={onClick as (e: ButtonEvent) => void} aria-label={label} + disabled={actionState === "disabled"} className={classNames("mx_FormattingButtons_Button", { mx_FormattingButtons_active: actionState === "reversed", mx_FormattingButtons_Button_hover: actionState === "enabled", @@ -64,55 +65,59 @@ function Button({ label, keyCombo, onClick, actionState, icon }: ButtonProps): J interface FormattingButtonsProps { composer: FormattingFunctions; actionStates: AllActionStates; + /** + * Whether all buttons should be disabled + */ + disabled?: boolean; } -export function FormattingButtons({ composer, actionStates }: FormattingButtonsProps): JSX.Element { +export function FormattingButtons({ composer, actionStates, disabled }: FormattingButtonsProps): JSX.Element { const composerContext = useComposerContext(); const isInList = actionStates.unorderedList === "reversed" || actionStates.orderedList === "reversed"; return (