Skip to content

Commit 7ae1156

Browse files
use ids
1 parent c7eac5f commit 7ae1156

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

packages/instantsearch-ui-components/src/components/autocomplete/AutocompleteSearch.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/** @jsx createElement */
2-
import type { Renderer } from '../..';
2+
import type { ComponentProps, Renderer } from '../..';
33

44
export type AutocompleteSearchProps = {
5-
inputProps: Partial<React.DOMAttributes<HTMLInputElement>>;
5+
inputProps: Partial<ComponentProps<'input'>>;
66
onClear: () => void;
77
query: string;
8+
isSearchStalled: boolean;
89
};
910

1011
export function createAutocompleteSearchComponent({ createElement }: Renderer) {
1112
return function AutocompleteSearch({
1213
inputProps,
1314
onClear,
1415
query,
16+
isSearchStalled,
1517
}: AutocompleteSearchProps) {
1618
return (
1719
<form
@@ -25,8 +27,8 @@ export function createAutocompleteSearchComponent({ createElement }: Renderer) {
2527
<label
2628
className="ais-AutocompleteLabel"
2729
aria-label="Submit"
28-
htmlFor="autocomplete-input"
29-
id="autocomplete-label"
30+
htmlFor={inputProps.id}
31+
id={`${inputProps.id}-label`}
3032
>
3133
<button
3234
className="ais-AutocompleteSubmitButton"
@@ -44,7 +46,10 @@ export function createAutocompleteSearchComponent({ createElement }: Renderer) {
4446
</svg>
4547
</button>
4648
</label>
47-
<div className="ais-AutocompleteLoadingIndicator" hidden>
49+
<div
50+
className="ais-AutocompleteLoadingIndicator"
51+
hidden={!isSearchStalled}
52+
>
4853
<svg
4954
className="ais-AutocompleteLoadingIcon"
5055
viewBox="0 0 100 100"
@@ -76,8 +81,7 @@ export function createAutocompleteSearchComponent({ createElement }: Renderer) {
7681
<input
7782
className="ais-AutocompleteInput"
7883
aria-autocomplete="both"
79-
aria-labelledby="autocomplete-label"
80-
id="autocomplete-input"
84+
aria-labelledby={`${inputProps.id}-label`}
8185
autoComplete="off"
8286
autoCorrect="off"
8387
autoCapitalize="off"
@@ -95,7 +99,7 @@ export function createAutocompleteSearchComponent({ createElement }: Renderer) {
9599
className="ais-AutocompleteClearButton"
96100
type="reset"
97101
title="Clear"
98-
hidden={!query}
102+
hidden={query.length === 0 || isSearchStalled}
99103
onClick={onClear}
100104
>
101105
<svg

packages/react-instantsearch/src/components/AutocompleteSearch.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ export function AutocompleteSearch({
1818
inputProps,
1919
clearQuery,
2020
}: AutocompleteSearchProps) {
21-
const { query, refine } = useSearchBox();
21+
const { query, refine, isSearchStalled } = useSearchBox();
2222

2323
return (
2424
<AutocompleteSearchComponent
2525
inputProps={{
2626
...inputProps,
27-
onChange: (event) => refine(event.currentTarget.value),
27+
onChange: (event: React.ChangeEvent<HTMLInputElement>) =>
28+
refine(event.currentTarget.value),
2829
}}
2930
onClear={clearQuery}
3031
query={query}
32+
isSearchStalled={isSearchStalled}
3133
/>
3234
);
3335
}

0 commit comments

Comments
 (0)