interaction behavior

This commit is contained in:
Nate Kelley 2025-09-30 16:21:56 -06:00
parent d0ff8cc703
commit 58b57d3492
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 13 additions and 2 deletions

View File

@ -132,6 +132,7 @@ export const BusterChatInputBase: React.FC<BusterChatInputProps> = React.memo(
ref={mentionInputSuggestionsRef}
inputContainerClassName="px-5 pt-4"
inputClassName="text-md"
behavior="open-on-focus"
>
<BusterChatInputButtons
onSubmit={onSubmitPreflight}

View File

@ -49,17 +49,22 @@ export const MentionInputSuggestions = forwardRef<
//mentions
onMentionItemClick,
mentions,
behavior = 'default',
}: MentionInputSuggestionsProps,
ref
) => {
const [hasClickedSelect, setHasClickedSelect] = useState(false);
const [hasInteracted, setHasInteracted] = useState(behavior === 'default');
const [value, setValue] = useState(valueProp ?? defaultValue);
const commandListNavigatedRef = useRef(false);
const commandRef = useRef<HTMLDivElement>(null);
const mentionsInputRef = useRef<MentionInputRef>(null);
const showSuggestionList = !hasClickedSelect && suggestionItems.length > 0;
const showSuggestionList =
behavior === 'default'
? !hasClickedSelect && suggestionItems.length > 0
: hasInteracted && suggestionItems.length > 0;
const onChangeInputValue: MentionInputProps['onChange'] = useCallback(
(d) => {
@ -68,8 +73,9 @@ export const MentionInputSuggestions = forwardRef<
onChange?.(d);
commandListNavigatedRef.current = false;
setHasClickedSelect(false);
setHasInteracted(true);
},
[onChange, setHasClickedSelect]
[onChange, setHasClickedSelect, setHasInteracted]
);
//Exported: this is used to change the value of the input from outside the component
@ -183,6 +189,9 @@ export const MentionInputSuggestions = forwardRef<
)}
shouldFilter={shouldFilter}
filter={filter || customFilter}
onClick={() => {
setHasInteracted(true);
}}
>
<MentionInputSuggestionsContainer className={inputContainerClassName}>
<MentionInputSuggestionsMentionsInput

View File

@ -86,6 +86,7 @@ export type MentionInputSuggestionsProps<T = string> = {
inputContainerClassName?: string;
suggestionsContainerClassName?: string;
inputClassName?: string;
behavior?: 'default' | 'open-on-focus';
} & Pick<React.ComponentProps<typeof Command>, 'filter' | 'shouldFilter'>;
export type MentionInputSuggestionsRef = {