Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/filtering-changes #47

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/app/modules/ngx-magic-search/ngx-magic-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
this.filteredObj = this.facetsObj;
for (i = 0; i < this.filteredObj.length; i++) {
const facet = this.filteredObj[i];
idx = facet.label.toLowerCase().indexOf(searchVal);
idx = facet.label.toLowerCase().indexOf(searchVal.toLowerCase());
if (idx > -1) {
label = [
facet.label.substring(0, idx),
Expand All @@ -252,6 +252,7 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
this.filteredObj = filtered;
}, 0.1);
} else {
this.filteredObj = [];
this.textSearchEvent.emit(searchVal);
this.hideMenu();
}
Expand All @@ -262,7 +263,7 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
}
for (i = 0; i < this.filteredOptions.length; i++) {
const option = this.filteredOptions[i];
idx = option.label.toLowerCase().indexOf(searchVal);
idx = option.label.toLowerCase().indexOf(searchVal.toLowerCase());
if (idx > -1) {
label = [
option.label.substring(0, idx),
Expand All @@ -277,6 +278,8 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
setTimeout(() => {
this.filteredOptions = filtered;
}, 0.1);
} else {
this.filteredObj = [];
}
}
}
Expand Down Expand Up @@ -426,11 +429,23 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
const searchVal = this.searchInput;
const key = event.keyCode || event.charCode;
if (key === 9) { // tab, so select facet if narrowed down to 1
if (this.facetSelected === undefined) {
if (this.filteredObj.length !== 1) { return; }
if (this.facetSelected === undefined && this.filteredObj.length > 0) {
this.facetClicked(0, this.filteredObj[0].name);
} else if (this.facetSelected === undefined && this.filteredObj.length === 0) {
// If there's nothing to select treat it as text search
for (let i = 0; i < this.currentSearch.length; i++) {
if (this.currentSearch[i].name.indexOf('text') === 0) {
this.currentSearch.splice(i, 1);
}
}
this.currentSearch.push({ 'name': 'text=' + searchVal, 'label': [this.strings.text, searchVal] });

this.hideMenu();
this.searchInput = '';
this.textSearchEvent.emit(searchVal);
this.textSearch = searchVal;
} else {
if (this.filteredOptions === undefined || this.filteredOptions.length !== 1) { return; }
if (this.filteredOptions === undefined || this.filteredOptions.length === 0) { return; }
this.optionClicked(0, this.filteredOptions[0].key);
this.resetState();
}
Expand Down