Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Fix jumping cursor problem in SearchBar
Browse files Browse the repository at this point in the history
As I understand it, there are some challenges with cursor placement in downshift. This is a way to handle it inspired from:

downshift-js/downshift#1108 (comment)
  • Loading branch information
kasperbirch1 committed May 4, 2023
1 parent f111f0c commit 7d3ad80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/apps/search-header/search-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ const SearchHeader: React.FC = () => {
<SearchBar
getInputProps={getInputProps}
getLabelProps={getLabelProps}
setQWithoutQuery={setQWithoutQuery}
/>
<Autosuggest
textData={textData}
Expand Down
10 changes: 8 additions & 2 deletions src/components/search-bar/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export interface SearchBarProps {
getInputProps: UseComboboxPropGetters<unknown>["getInputProps"];
getLabelProps: UseComboboxPropGetters<unknown>["getLabelProps"];
dataCy?: string;
setQWithoutQuery: (value: string) => void;
}

const SearchBar: React.FC<SearchBarProps> = ({
getInputProps,
getLabelProps,
dataCy = "search-header-input"
dataCy = "search-header-input",
setQWithoutQuery
}) => {
const t = useText();
return (
Expand All @@ -31,7 +33,11 @@ const SearchBar: React.FC<SearchBarProps> = ({
autoComplete="off"
placeholder={t("inputPlaceholderText")}
aria-label={t("inputPlaceholderText")}
{...getInputProps()}
{...getInputProps({
onChange: (e: React.ChangeEvent<HTMLInputElement>) => {
setQWithoutQuery(e.target.value);
}
})}
/>
{/* eslint-enable react/jsx-props-no-spreading */}
<input
Expand Down

0 comments on commit 7d3ad80

Please sign in to comment.