Skip to content

Commit 3f8b958

Browse files
samoussHaroenv
authored andcommitted
fix(hitsPerPage): avoid sync default value (#4086)
This PR avoid to sync the default value into the `uiState`. This behavior is consistent with the one from `sortBy`. The default value doesn't have to be inside the `uiState` because as the name suggests it's the default one. The option is defined statically, it can't change.
1 parent 9f68da5 commit 3f8b958

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/connectors/hits-per-page/__tests__/connectHitsPerPage-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,30 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hits-per-pa
570570
expect(actual).toEqual({});
571571
});
572572

573+
test('returns the `uiState` empty with default value selected', () => {
574+
const render = jest.fn();
575+
const makeWidget = connectHitsPerPage(render);
576+
const helper = algoliasearchHelper({}, 'indexName', {
577+
hitsPerPage: 3,
578+
});
579+
580+
const widget = makeWidget({
581+
items: [
582+
{ value: 3, label: '3 items per page', default: true },
583+
{ value: 22, label: '22 items per page' },
584+
],
585+
});
586+
587+
const actual = widget.getWidgetState(
588+
{},
589+
{
590+
searchParameters: helper.state,
591+
}
592+
);
593+
594+
expect(actual).toEqual({});
595+
});
596+
573597
test('returns the `uiState` with a refinement', () => {
574598
const render = jest.fn();
575599
const makeWidget = connectHitsPerPage(render);

src/connectors/hits-per-page/connectHitsPerPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ You may want to add another entry to the \`items\` option with this value.`
217217
getWidgetState(uiState, { searchParameters }) {
218218
const hitsPerPage = searchParameters.hitsPerPage;
219219

220-
if (hitsPerPage === undefined) {
220+
if (hitsPerPage === undefined || hitsPerPage === defaultItem.value) {
221221
return uiState;
222222
}
223223

0 commit comments

Comments
 (0)