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/backspace-remove-facet #42

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
border-radius: .25em;
}


/*-----------------------------------------
Colors
----------------------------------------- */
Expand Down Expand Up @@ -131,6 +130,11 @@
font-size: 0.80rem;
}

.search-bar .item-list .item.marked {
background-color: #2196f3;
color: #fff;
}

.search-bar .item-list .item a {
color: white;
}
Expand Down Expand Up @@ -181,4 +185,4 @@
.search-bar i.cancel:hover {
color: darkred;
cursor: pointer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<i class="fa fa-filter go"></i>
<div class="search-main-area" (click)="enableTextEntry()">
<span class="item-list" *ngIf="currentSearch">
<span *ngFor="let facet of currentSearch; let i = index;" class="ngx-label radius secondary item">
<span *ngFor="let facet of currentSearch; let i = index;" class="ngx-label radius secondary item" [class.marked]="facet.markedForDeletion">
<span>{{ facet.label[0] }}:<b>{{ facet.label[1] }}</b></span>
<a class="remove" (click)="removeFacet(i)" title="{{ strings.remove }}"><i class="fa fa-times"></i></a>
</span>
Expand Down Expand Up @@ -44,4 +44,4 @@
<i class="fa fa-times cancel"></i>
</a>
</div>
</div>
</div>
26 changes: 26 additions & 0 deletions src/app/modules/ngx-magic-search/ngx-magic-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
textFilter = '';
}
this.textSearchEvent.emit(searchVal);
this.unmarkAllFacets();
return;
}
if (key === 13) { // enter, so accept value
Expand Down Expand Up @@ -488,6 +489,28 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
this.filterFacets(searchVal);
}
}

// Remove facet on backspace
if (key === 8) {
if (this.currentSearch.length > 0) {
const rightmostFacetIndex = this.currentSearch.length - 1;

if (!this.currentSearch[rightmostFacetIndex].markedForDeletion) {
this.currentSearch[rightmostFacetIndex].markedForDeletion = true;
} else {
this.removeFacet(rightmostFacetIndex);
}
}
} else {
// If any key other than backspace is pressed we unmark all facets.
this.unmarkAllFacets();
}
}

unmarkAllFacets(): void {
for (const facet of this.currentSearch) {
facet.markedForDeletion = false;
}
}

/**
Expand Down Expand Up @@ -708,6 +731,9 @@ export class NgxMagicSearchComponent implements OnInit, OnChanges, DoCheck {
// tracked by the host.
@HostListener('document:click', ['$event'])
compareEvent( globalEvent ): void {
// Unmark all facets on document click.
this.unmarkAllFacets();

// If the last known host event and the given global event are
// the same reference, we know that the event originated within
// the host (and then bubbled up out of the host and eventually
Expand Down