Autofill search box when browsing categories
This will fill the search box with "category:<category> " on all
category pages helping the user discover how to filter by category.
@@ -5,9 +5,11 @@ import { inject as service } from '@ember/service';
export default class CategoryRoute extends Route {
@service router;
@service store;
+ @service header;
async model(params, transition) {
let categoryName = params.category_id;
+ this.header.searchValue = 'category:' + params.category_id + ' '; // additional space to help user not accidentally mangle the category
try {
return await this.store.findRecord('category', categoryName);
@@ -21,4 +23,9 @@ export default class CategoryRoute extends Route {
}
}
}
+
+ deactivate() {
+ super.deactivate(...arguments);
+ this.header.searchValue = null;
+ }
}
