Skip to content

Commit

Permalink
fix(connectSearchBox): handle defaultRefinement (#1829)
Browse files Browse the repository at this point in the history
* fix(connectSearchBox): handle `defaultRefinement`

fixes #1826

* add storybook story
  • Loading branch information
vvo authored Jan 16, 2017
1 parent 2ed9b49 commit 7a730e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function getCurrentRefinement(props, searchState) {
if (typeof searchState[id] !== 'undefined') {
return searchState[id];
}
if (typeof props.defaultRefinement === 'string') {
return props.defaultRefinement;
}
return '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('connectSearchBox', () => {
});
});

it('supports defaultRefinement', () => {
expect(
getProvidedProps({defaultRefinement: 'yaw'}, {})
).toEqual({
currentRefinement: 'yaw',
});
});

it('refines the query parameter', () => {
params = getSP(new SearchParameters(), {}, {query: 'bar'});
expect(params.query).toBe('bar');
Expand Down
7 changes: 6 additions & 1 deletion stories/SearchBox.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ stories.add('default', () =>
<WrapWithHits searchBox={false} hasPlayground={true} linkedStoryGroup="SearchBox">
<SearchBox/>
</WrapWithHits>
).add('playground', () =>
).add('with a default query', () =>
<WrapWithHits searchBox={false} hasPlayground={true} linkedStoryGroup="SearchBox">
<SearchBox defaultRefinement="battery" />
</WrapWithHits>
)
.add('playground', () =>
<WrapWithHits searchBox={false}>
<SearchBox
focusShortcuts={['s']}
Expand Down

0 comments on commit 7a730e2

Please sign in to comment.