Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autocomplete close button functionality #1297

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/fuselage/src/components/AutoComplete/AutoComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,32 @@ export function AutoComplete({
useCursor(value, memoizedOptions, handleSelect);

const handleOnBlur = useEffectEvent((event) => {
hide();
onBlurAction(event);
const isI = event.relatedTarget?.nodeName === 'I';
if (optionsAreVisible === AnimatedVisibility.VISIBLE && !isI) {
hide();
onBlurAction(event);
}
});

useEffect(reset, [filter]);

const handleIconClick = (event) => {
event.preventDefault();
event.stopPropagation();
if (optionsAreVisible === AnimatedVisibility.VISIBLE) {
ref.current.blur();
hide();
} else {
ref.current.focus();
show();
}
};
return (
<Box
rcx-autocomplete
ref={containerRef}
onClick={useEffectEvent(() => ref.current.focus())}
flexGrow={1}
onBlur={handleOnBlur}
className={useMemo(
() => [error && 'invalid', disabled && 'disabled'],
[error, disabled]
Expand All @@ -149,7 +163,6 @@ export function AutoComplete({
<InputBox.Input
ref={ref}
onChange={useEffectEvent((e) => setFilter(e.currentTarget.value))}
onBlur={handleOnBlur}
onFocus={show}
onKeyDown={handleKeyDown}
placeholder={
Expand Down Expand Up @@ -191,6 +204,9 @@ export function AutoComplete({
? 'cross'
: 'magnifier'
}
style={{ cursor: 'pointer' }}
onClick={handleIconClick}
tabIndex='-1'
size='x20'
/>
}
Expand Down
Loading