Skip to content

Commit

Permalink
Fixed collapsed bug when clearing filter
Browse files Browse the repository at this point in the history
Optimized unit of work per item for match check
  • Loading branch information
Sleeckx committed Sep 16, 2016
1 parent 6098ea4 commit 5fa4591
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/WebComponents/Menu/menu.ts
Original file line number Diff line number Diff line change
@@ -187,7 +187,8 @@ namespace Vidyano.WebComponents {
type: Boolean,
readOnly: true,
reflectToAttribute: true,
observer: "_expandChanged"
observer: "_expandChanged",
value: false
},
filtering: {
type: Boolean,
@@ -212,7 +213,7 @@ namespace Vidyano.WebComponents {
observers: [
"_updateItemTitle(item, filter, filtering, collapsed)",
"_updateIndentVariable(level)",
"_updateOpened(filtering, item)"
"_updateOpened(filtering, item, expand)"
],
listeners: {
"tap": "_tap"
@@ -275,23 +276,19 @@ namespace Vidyano.WebComponents {
this.hidden = this.filtering && !this._hasMatch(<ProgramUnitItem><any>this.item, this.filter.toUpperCase());
}

private _updateOpened(filtering: boolean, item: Vidyano.ProgramUnitItem) {
(<any>this.$["subItems"]).opened = filtering || item === this.programUnit;
private _updateOpened(filtering: boolean, item: Vidyano.ProgramUnitItem, expand: boolean) {
(<any>this.$["subItems"]).opened = filtering || item === this.programUnit || expand;
}

private _hasMatch(item: ProgramUnitItem, search: string): boolean {
const matchOnItem = item.title.toUpperCase().contains(search);
const items = (<any>item).items;
const matchOnSubItems = (items != null && items.filter(i => this._hasMatch(i, search)).length > 0);
if (item.title.toUpperCase().contains(search))
return true;

let hasMatch = matchOnItem || matchOnSubItems;
if (!hasMatch && this.filterParent instanceof Vidyano.ProgramUnitItemGroup && this.filterParent.title.toUpperCase().contains(search))
hasMatch = true;

if (hasMatch && item instanceof ProgramUnit && !matchOnSubItems)
hasMatch = false;
const items = (<any>item).items;
if (items != null && items.filter(i => this._hasMatch(i, search)).length > 0)
return true;

return hasMatch;
return this.filterParent instanceof Vidyano.ProgramUnitItemGroup && this.filterParent.title.toUpperCase().contains(search);
}

private _programUnitChanged() {

0 comments on commit 5fa4591

Please sign in to comment.