Skip to content

Commit

Permalink
fix: highlighted text calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb committed Sep 30, 2018
1 parent 0c24833 commit ad2f9a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/app/lib/ngx-select/ngx-select.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const escapeString = escapeStringNs;
export class NgxSelectOption implements INgxSelectOption, INgxSelectOptionBase {
readonly type: TNgxSelectOptionType = 'option';

constructor(public value: number | string,
highlightedText: SafeHtml;

constructor(public value: number | string,
public text: string,
public disabled: boolean,
public data: any,
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/ngx-select/ngx-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
})"
(click)="optionSelect(option, $event)">
<ng-container [ngTemplateOutlet]="templateOption || defaultTemplateOption"
[ngTemplateOutletContext]="{$implicit: option, text: highlightOption(option),
[ngTemplateOutletContext]="{$implicit: option, text: option.highlightedText,
index: idxGroup, subIndex: idxOption}"></ng-container>
</a>
</li>
Expand Down
14 changes: 13 additions & 1 deletion src/app/lib/ngx-select/ngx-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,19 @@ export class NgxSelectComponent implements INgxSelectOptions, ControlValueAccess
this.subjOptions
.combineLatest(this.subjOptionsSelected, this.subjSearchText,
(options: TSelectOption[], selectedOptions: NgxSelectOption[], search: string) => {
this.optionsFiltered = this.filterOptions(search, options, selectedOptions);
this.optionsFiltered = this.filterOptions(search, options, selectedOptions)
.map(option => {
if (option instanceof NgxSelectOption) {
option.highlightedText = this.highlightOption(option);
} else if (option instanceof NgxSelectOptGroup) {
option.options.map(x => {
x.highlightedText = this.highlightOption(x);
return x;
});
}

return option;
});
this.cacheOptionsFilteredFlat = null;
this.navigateOption(ENavigation.firstIfOptionActiveInvisible);
return selectedOptions;
Expand Down

0 comments on commit ad2f9a1

Please sign in to comment.