Skip to content

Commit

Permalink
Add classes argments for styling the options
Browse files Browse the repository at this point in the history
  • Loading branch information
Zefling committed Aug 3, 2017
1 parent 27bf8e5 commit 95bfa69
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/angular.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<li *ngIf="groupOrOption.options"
class="select2-results__option"
role="group">
<strong class="select2-results__group">{{groupOrOption.label}}</strong>
<strong [attr.class]="'select2-results__group' + (groupOrOption.classes ? ' ' + groupOrOption.classes : '')">{{groupOrOption.label}}</strong>
<ul class="select2-results__options select2-results__options--nested">
<li *ngFor="let option of groupOrOption.options"
[class]="getOptionStyle(option.value)"
[class]="getOptionStyle(option)"
role="treeitem"
[attr.aria-selected]="isSelected(option)"
[attr.aria-disabled]="isDisabled(option)"
Expand All @@ -63,7 +63,7 @@
</ul>
</li>
<li *ngIf="!groupOrOption.options"
[class]="getOptionStyle(groupOrOption.value)"
[class]="getOptionStyle(groupOrOption)"
role="treeitem"
[attr.aria-selected]="isSelected(groupOrOption)"
[attr.aria-disabled]="isDisabled(groupOrOption)"
Expand Down
5 changes: 3 additions & 2 deletions src/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ export class Select2 implements ControlValueAccessor {
this._dirtyCheckNativeValue();
}

getOptionStyle(value: string) {
return common.getOptionStyle(value, this.hoveringValue);
getOptionStyle(option: common.Select2Option) {
return common.getOptionStyle(option.value, this.hoveringValue)
+ (option.classes ? ' ' + option.classes : '');
}

mouseenter(option: common.Select2Option) {
Expand Down
2 changes: 2 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type Select2Group = {
label: string;
options: Select2Option[];
classes?: string;
};

export type Select2Option = {
Expand All @@ -9,6 +10,7 @@ export type Select2Option = {
disabled?: boolean;
// tslint:disable-next-line:ban-types
component?: string | Function;
classes?: string;
};

export type Select2Value = string | number;
Expand Down

0 comments on commit 95bfa69

Please sign in to comment.