Skip to content

The open alternative to Salesforce, designed for AI.

prevent shortcuts in other response input (#24562)

Sankalp Karad13f7da0079
diff --git a/packages/twenty-front/src/modules/ai/components/internal/AiChatQuestionOtherOption.tsx b/packages/twenty-front/src/modules/ai/components/internal/AiChatQuestionOtherOption.tsx
index f66597f18b2..f49a10f6d3a 100644
--- a/packages/twenty-front/src/modules/ai/components/internal/AiChatQuestionOtherOption.tsx
+++ b/packages/twenty-front/src/modules/ai/components/internal/AiChatQuestionOtherOption.tsx
@@ -1,9 +1,13 @@
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
-import { type KeyboardEvent, useContext, useRef } from 'react';
+import { type KeyboardEvent, useContext, useId, useRef } from 'react';
import { type IconComponent } from 'twenty-ui/icon';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
+import { usePushFocusItemToFocusStack } from '@/ui/utilities/focus/hooks/usePushFocusItemToFocusStack';
+import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';
+import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
+
const StyledContainer = styled.div<{ isHighlighted: boolean }>`
background: ${({ isHighlighted }) =>
isHighlighted
@@ -79,12 +83,34 @@ export const AiChatQuestionOtherOption = ({
const { t } = useLingui();
const { theme } = useContext(ThemeContext);
const textareaRef = useRef<HTMLTextAreaElement>(null);
+ const textAreaFocusId = useId();
+
+ const { pushFocusItemToFocusStack } = usePushFocusItemToFocusStack();
+ const { removeFocusItemFromFocusStackById } =
+ useRemoveFocusItemFromFocusStackById();
const selectAndFocus = () => {
onSelect();
textareaRef.current?.focus();
};
+ const handleTextareaFocus = () => {
+ pushFocusItemToFocusStack({
+ focusId: textAreaFocusId,
+ component: {
+ type: FocusComponentType.TEXT_AREA,
+ instanceId: textAreaFocusId,
+ },
+ globalHotkeysConfig: {
+ enableGlobalHotkeysConflictingWithKeyboard: false,
+ },
+ });
+ };
+
+ const handleTextareaBlur = () => {
+ removeFocusItemFromFocusStackById({ focusId: textAreaFocusId });
+ };
+
return (
<StyledContainer isHighlighted={isHighlighted} onClick={selectAndFocus}>
<StyledLabelRow
@@ -117,6 +143,8 @@ export const AiChatQuestionOtherOption = ({
}}
onChange={(event) => onChange(event.target.value)}
onKeyDown={onTextareaKeyDown}
+ onFocus={handleTextareaFocus}
+ onBlur={handleTextareaBlur}
/>
</StyledContainer>
);