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: input buttons behavior #610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export function SearchInput({
const containerRef = useRef<HTMLDivElement>(null);
const { pending } = useFormStatus();
const { dropdownRef } = useContext(SearchContext);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);

const openDropdown = hasSubmitted
? !pending
: isOpen && !pending && !!searchResult;
Expand Down Expand Up @@ -66,14 +68,20 @@ export function SearchInput({
function handleClear() {
setValue('');
close();
inputRef.current?.focus();
}

function handleFocus() {
setIsFocused(true);
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
}

function handleBlur() {
setIsFocused(false);
timeoutRef.current = setTimeout(() => {
setIsFocused(false);
}, 100);
}

function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
Expand Down Expand Up @@ -112,36 +120,36 @@ export function SearchInput({
onBlur={handleBlur}
onKeyDown={onKeyDown}
>
<div
data-show={isFocused}
<Input.Slot
side="right"
data-show={isFocused || !!inputRef.current?.value}
className={classes.inputActionsContainer()}
>
<Input.Slot side="right">
<Tooltip content="Submit">
<IconButton
type="submit"
aria-label="Submit"
icon={IconCheck}
iconColor="text-brand"
variant="link"
className="!ml-0 tablet:ml-2"
isLoading={pending}
onClick={handleSubmit}
/>
</Tooltip>
<Tooltip content="Submit">
<IconButton
aria-label="Clear"
icon={IconX}
iconColor="text-gray-11"
type="submit"
aria-label="Submit"
disabled={!value}
icon={IconCheck}
iconColor="text-brand"
variant="link"
className="m-0"
onClick={handleClear}
className="!ml-0 tablet:ml-2"
isLoading={pending}
onClick={handleSubmit}
/>
</Input.Slot>
</div>
</Tooltip>
<IconButton
aria-label="Clear"
icon={IconX}
iconColor="text-gray-11"
variant="link"
className="m-0"
onClick={handleClear}
/>
</Input.Slot>

<Input.Slot
data-show={!isFocused}
data-show={!isFocused && !inputRef.current?.value}
side="right"
className="[&[data-show=false]]:hidden"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const styles = tv({
'[&_.rt-TextFieldChrome]:[&[data-opened=true]]:rounded-b-none',
'group-[&[data-active=true]]:[&_.rt-TextFieldChrome]:shadow-none',
],
inputActionsContainer:
'[&[data-show=false]]:hidden absolute flex items-center h-full right-0 top-0 transform',
inputActionsContainer: '[&[data-show=false]]:hidden',
},
});
Loading