From 7fe569ec6ad2696f2766758570077490bc793379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tha=C3=AFs?= Date: Mon, 30 Oct 2023 19:23:12 +0100 Subject: [PATCH] fix: disable page shortcuts on TextArea focus (#2288) Fixes #2275 --- .../modules/ui/input/components/TextArea.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/front/src/modules/ui/input/components/TextArea.tsx b/front/src/modules/ui/input/components/TextArea.tsx index 14a6244d9..aab39b97b 100644 --- a/front/src/modules/ui/input/components/TextArea.tsx +++ b/front/src/modules/ui/input/components/TextArea.tsx @@ -1,6 +1,11 @@ +import { FocusEventHandler } from 'react'; import TextareaAutosize from 'react-textarea-autosize'; import styled from '@emotion/styled'; +import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope'; + +import { InputHotkeyScope } from '../types/InputHotkeyScope'; + const MAX_ROWS = 5; export type TextAreaProps = { @@ -50,6 +55,19 @@ export const TextArea = ({ }: TextAreaProps) => { const computedMinRows = Math.min(minRows, MAX_ROWS); + const { + goBackToPreviousHotkeyScope, + setHotkeyScopeAndMemorizePreviousScope, + } = usePreviousHotkeyScope(); + + const handleFocus: FocusEventHandler = () => { + setHotkeyScopeAndMemorizePreviousScope(InputHotkeyScope.TextInput); + }; + + const handleBlur: FocusEventHandler = () => { + goBackToPreviousHotkeyScope(); + }; + return ( onChange?.(event.target.value)} + onFocus={handleFocus} + onBlur={handleBlur} disabled={disabled} /> );