The <RangeInput> component provides input fields to filter results by a numeric range.
Import
import { RangeInput } from 'react-instantsearch';
Props
The numeric attribute to filter.<RangeInput attribute="price" />
Minimum value for the range. By default, it’s automatically computed from the results.<RangeInput attribute="price" min={0} />
Maximum value for the range. By default, it’s automatically computed from the results.<RangeInput attribute="price" max={1000} />
Number of decimal places for the values.<RangeInput attribute="price" precision={2} />
Customize the text strings.<RangeInput
attribute="price"
translations={{
separatorElementText: 'to',
submitButtonText: 'Go',
}}
/>
CSS classes to customize the component styling.
Example
import { InstantSearch, RangeInput, Hits } from 'react-instantsearch';
import { liteClient as algoliasearch } from 'algoliasearch/lite';
const searchClient = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<div className="filters">
<h3>Price</h3>
<RangeInput attribute="price" />
</div>
<Hits />
</InstantSearch>
);
}
With Custom Bounds
function App() {
return (
<InstantSearch searchClient={searchClient} indexName="products">
<RangeInput
attribute="price"
min={0}
max={1000}
precision={2}
/>
<Hits />
</InstantSearch>
);
}