Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit a05f6a4

Browse files
authored
fix(SearchBox): Adds inputId prop to SearchBox (#3074)
1 parent 3739d5c commit a05f6a4

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

packages/react-instantsearch-dom/src/components/SearchBox.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class SearchBox extends Component {
8686
PropTypes.func,
8787
PropTypes.exact({ current: PropTypes.object }),
8888
]),
89+
inputId: PropTypes.string,
8990
};
9091

9192
static defaultProps = {
@@ -221,6 +222,7 @@ class SearchBox extends Component {
221222
render() {
222223
const {
223224
className,
225+
inputId,
224226
translate,
225227
autoFocus,
226228
loadingIndicator,
@@ -257,6 +259,7 @@ class SearchBox extends Component {
257259
>
258260
<input
259261
ref={this.onInputMount}
262+
id={inputId}
260263
type="search"
261264
placeholder={translate('placeholder')}
262265
autoFocus={autoFocus}

packages/react-instantsearch-dom/src/components/__tests__/SearchBox.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ describe('SearchBox', () => {
2525
instance.unmount();
2626
});
2727

28+
it('applies its default props with custom inputId', () => {
29+
const inputId = 'search-box';
30+
const wrapper = mount(<SearchBox inputId={inputId} refine={() => null} />);
31+
32+
const input = wrapper.find('input').getDOMNode();
33+
expect(input.getAttribute('id')).toEqual(inputId);
34+
});
35+
2836
it('transfers the autoFocus prop to the underlying input element', () => {
2937
const instance = renderer.create(
3038
<SearchBox refine={() => null} autoFocus />

packages/react-instantsearch-dom/src/widgets/SearchBox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import SearchBox from '../components/SearchBox';
1515
* @propType {node} [reset] - Change the apparence of the default reset button (cross).
1616
* @propType {node} [loadingIndicator] - Change the apparence of the default loading indicator (spinning circle).
1717
* @propType {string} [defaultRefinement] - Provide default refinement value when component is mounted.
18+
* @propType {string} [inputId] - The id of the search input
1819
* @propType {boolean} [showLoadingIndicator=false] - Display that the search is loading. This only happens after a certain amount of time to avoid a blinking effect. This timer can be configured with `stalledSearchDelay` props on <InstantSearch>. By default, the value is 200ms.
1920
* @themeKey ais-SearchBox - the root div of the widget
2021
* @themeKey ais-SearchBox-form - the wrapping form

0 commit comments

Comments
 (0)