Skip to content

Commit 36cfbe3

Browse files
committed
Auto merge of #1875 - jtescher:nav-clear-search-box, r=carols10cents
Clear search input on index route Not sure what the correct product choice is here, but this clears the search input when navigating back to index route if that is in fact the behavior that is preferred. Fixes #1230 (for some context both npm and rubygems.org do NOT clear the index if you search and then navigate back via browser, but both clear if you navigate forward to the index route via top left icon clicks)
2 parents 9885991 + 145bafb commit 36cfbe3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

app/routes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default Route.extend({
1414
},
1515

1616
setupController(controller) {
17+
this.controllerFor('application').set('searchQuery', null);
1718
controller.dataTask.perform();
1819
},
1920
});

app/routes/search.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default Route.extend({
1414
},
1515

1616
setupController(controller, params) {
17+
this.controllerFor('application').set('searchQuery', params.q);
1718
controller.dataTask.perform(params);
1819
},
1920
});

tests/acceptance/search-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ module('Acceptance | search', function(hooks) {
6262
assert.dom('[data-test-search-nav]').hasText('Displaying 1-8 of 8 total results');
6363
});
6464

65+
test('clearing search results', async function(assert) {
66+
this.server.loadFixtures();
67+
68+
await visit('/search?q=rust');
69+
70+
assert.equal(currentURL(), '/search?q=rust');
71+
assert.dom('[data-test-search-input]').hasValue('rust');
72+
73+
await visit('/');
74+
75+
assert.equal(currentURL(), '/');
76+
assert.dom('[data-test-search-input]').hasValue('');
77+
});
78+
6579
test('pressing S key to focus the search bar', async function(assert) {
6680
this.server.loadFixtures();
6781

0 commit comments

Comments
 (0)