mirror of https://github.com/buster-so/buster.git
interacting should fall out
This commit is contained in:
parent
3dc7cd31cb
commit
db7d623b9a
|
@ -54,7 +54,7 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const [hasClickedSelect, setHasClickedSelect] = useState(false);
|
const [hasClickedSelect, setHasClickedSelect] = useState(false);
|
||||||
const [hasInteracted, setHasInteracted] = useState(behavior === 'default');
|
const [isInteracting, setIsInteracting] = useState(behavior === 'default');
|
||||||
const [value, setValue] = useState(valueProp ?? defaultValue);
|
const [value, setValue] = useState(valueProp ?? defaultValue);
|
||||||
|
|
||||||
const commandListNavigatedRef = useRef(false);
|
const commandListNavigatedRef = useRef(false);
|
||||||
|
@ -64,7 +64,7 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
const showSuggestionList =
|
const showSuggestionList =
|
||||||
behavior === 'default'
|
behavior === 'default'
|
||||||
? !hasClickedSelect && suggestionItems.length > 0
|
? !hasClickedSelect && suggestionItems.length > 0
|
||||||
: hasInteracted && suggestionItems.length > 0;
|
: isInteracting && suggestionItems.length > 0;
|
||||||
|
|
||||||
const onChangeInputValue: MentionInputProps['onChange'] = useCallback(
|
const onChangeInputValue: MentionInputProps['onChange'] = useCallback(
|
||||||
(d) => {
|
(d) => {
|
||||||
|
@ -73,9 +73,9 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
onChange?.(d);
|
onChange?.(d);
|
||||||
commandListNavigatedRef.current = false;
|
commandListNavigatedRef.current = false;
|
||||||
setHasClickedSelect(false);
|
setHasClickedSelect(false);
|
||||||
setHasInteracted(true);
|
setIsInteracting(true);
|
||||||
},
|
},
|
||||||
[onChange, setHasClickedSelect, setHasInteracted]
|
[onChange, setHasClickedSelect, setIsInteracting]
|
||||||
);
|
);
|
||||||
|
|
||||||
//Exported: this is used to change the value of the input from outside the component
|
//Exported: this is used to change the value of the input from outside the component
|
||||||
|
@ -124,6 +124,10 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
const addMentionToInput = mentionsInputRef.current?.addMentionToInput!;
|
const addMentionToInput = mentionsInputRef.current?.addMentionToInput!;
|
||||||
const mounted = useMounted();
|
const mounted = useMounted();
|
||||||
|
|
||||||
|
const onBlur = useMemoizedFn(() => {
|
||||||
|
setIsInteracting(false);
|
||||||
|
});
|
||||||
|
|
||||||
// Track arrow key navigation in the command list
|
// Track arrow key navigation in the command list
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
@ -189,9 +193,6 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
)}
|
)}
|
||||||
shouldFilter={shouldFilter}
|
shouldFilter={shouldFilter}
|
||||||
filter={filter || customFilter}
|
filter={filter || customFilter}
|
||||||
onClick={() => {
|
|
||||||
setHasInteracted(true);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<MentionInputSuggestionsContainer className={inputContainerClassName}>
|
<MentionInputSuggestionsContainer className={inputContainerClassName}>
|
||||||
<MentionInputSuggestionsMentionsInput
|
<MentionInputSuggestionsMentionsInput
|
||||||
|
@ -208,13 +209,14 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
commandListNavigatedRef={commandListNavigatedRef}
|
commandListNavigatedRef={commandListNavigatedRef}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={inputClassName}
|
className={inputClassName}
|
||||||
|
onBlur={onBlur}
|
||||||
/>
|
/>
|
||||||
{children && <div className="mt-4.5">{children}</div>}
|
{children && <div className="mt-4.5">{children}</div>}
|
||||||
</MentionInputSuggestionsContainer>
|
</MentionInputSuggestionsContainer>
|
||||||
<SuggestionsSeperator />
|
<SuggestionsSeperator />
|
||||||
<MentionInputSuggestionsList
|
<MentionInputSuggestionsList
|
||||||
show={showSuggestionList}
|
show={showSuggestionList}
|
||||||
className={cn('pt-1.5 overflow-y-auto max-h-[35vh]', suggestionsContainerClassName)}
|
className={cn('px-3 overflow-y-auto max-h-[35vh]', suggestionsContainerClassName)}
|
||||||
>
|
>
|
||||||
<MentionInputSuggestionsItemsSelector
|
<MentionInputSuggestionsItemsSelector
|
||||||
suggestionItems={suggestionItems}
|
suggestionItems={suggestionItems}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export const MentionInputSuggestionsList = ({
|
||||||
if (!show) return null;
|
if (!show) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Command.List className={cn('px-3', hasResults && 'pb-1.5', className)} style={style}>
|
<Command.List className={cn(hasResults && 'py-1.5', className)} style={style}>
|
||||||
{children}
|
{children}
|
||||||
</Command.List>
|
</Command.List>
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,6 +10,8 @@ export type MentionInputSuggestionsMentionsInputProps = Pick<
|
||||||
> & {
|
> & {
|
||||||
onChange: MentionInputProps['onChange'];
|
onChange: MentionInputProps['onChange'];
|
||||||
onPressEnter: MentionInputProps['onPressEnter'];
|
onPressEnter: MentionInputProps['onPressEnter'];
|
||||||
|
onBlur?: MentionInputProps['onBlur'];
|
||||||
|
onFocus?: MentionInputProps['onFocus'];
|
||||||
className?: string;
|
className?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
autoFocus?: boolean;
|
autoFocus?: boolean;
|
||||||
|
|
Loading…
Reference in New Issue