Skip to content

Commit

Permalink
feat(connector): remove unused parameter to searchbox connector
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stanislawski committed Feb 15, 2017
1 parent 618dca2 commit e639f65
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
9 changes: 9 additions & 0 deletions dev/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ search.addWidget(
})
);

search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box-return',
placeholder: 'Search for products',
poweredBy: true,
searchOnEnterKeyPressOnly: true,
})
);

search.addWidget(
instantsearch.widgets.analytics({
pushFunction(/* formattedParameters, state, results*/) {
Expand Down
5 changes: 5 additions & 0 deletions dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ <h1><a href="./">Instant search demo</a> <small>using instantsearch.js</small></
</div>
<div class="col-md-9">
<div class="form-group">
<label for="hits-per-page-select">InstantSearchBox:</label>
<input id="search-box" class="form-control" />
</div>
<div class="form-group">
<label for="hits-per-page-select">EnterSearchBox:</label>
<input id="search-box-return" class="form-control" />
</div>
<div class="smooth-search smooth-search--hidden">
<div class="row">
<div class="col-md-3">
Expand Down
10 changes: 4 additions & 6 deletions src/connectors/search-box/connectSearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const connectSearchBox = searchBoxRendering => ({
poweredBy = {};
}

const search = helper => {
const makeSearch = helper => {
let previousQuery;

const setQueryAndSearch = (q, doSearch = true) => {
Expand All @@ -81,17 +81,15 @@ const connectSearchBox = searchBoxRendering => ({
};

return {
init({state, helper, onHistoryChange}) {
this._search = search(helper);
init({helper, onHistoryChange}) {
this._search = makeSearch(helper);
searchBoxRendering({
query: state.query,
query: helper.state.query,
containerNode,
onHistoryChange,
poweredBy,
helper,
wrapInput,
autofocus,
queryHook,
searchOnEnterKeyPressOnly,
placeholder,
cssClasses,
Expand Down
8 changes: 3 additions & 5 deletions src/widgets/search-box/search-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ function defaultRendering({
containerNode,
onHistoryChange,
poweredBy,
helper,
wrapInput,
autofocus,
queryHook,
searchOnEnterKeyPressOnly,
placeholder,
cssClasses,
Expand Down Expand Up @@ -90,17 +88,17 @@ function defaultRendering({
// - use back button
// - input query is empty (because <input> autocomplete = off)
window.addEventListener('pageshow', () => {
input.value = helper.state.query;
input.value = query;
});

// Update value when query change outside of the input
onHistoryChange(fullState => {
input.value = fullState.query || '';
});

if (autofocus === true || autofocus === 'auto' && helper.state.query === '') {
if (autofocus === true || autofocus === 'auto' && query === '') {
input.focus();
input.setSelectionRange(helper.state.query.length, helper.state.query.length);
input.setSelectionRange(query.length, query.length);
}

// search on enter
Expand Down

0 comments on commit e639f65

Please sign in to comment.