-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(select): add md-optgroup component (#4432)
* feat(select): add md-optgroup component Adds the `md-optgroup` component, which can be used to group options inside of `md-select`, in a similar way to the native `optgroup`. Fixes #3182. * fix: address feedback * fix: address feedback
- Loading branch information
1 parent
d0d79fd
commit d09aa89
Showing
15 changed files
with
443 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
margin: 24px; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import '../theming/palette'; | ||
@import '../theming/theming'; | ||
|
||
@mixin mat-optgroup-theme($theme) { | ||
$foreground: map-get($theme, foreground); | ||
|
||
.mat-optgroup-label { | ||
color: mat-color($foreground, secondary-text); | ||
} | ||
|
||
.mat-optgroup-disabled .mat-optgroup-label { | ||
color: mat-color($foreground, hint-text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import '../style/menu-common'; | ||
@import '../style/vendor-prefixes'; | ||
|
||
@mixin mat-optgroup() { | ||
.mat-optgroup-label { | ||
@include mat-menu-item-base(); | ||
@include user-select(none); | ||
cursor: default; | ||
|
||
// TODO(crisbeto): should use the typography functions once #4375 is in. | ||
font-weight: bold; | ||
font-size: 14px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {MdRippleModule} from '../ripple/index'; | ||
import {MdSelectionModule} from '../selection/index'; | ||
import {MdOption} from './option'; | ||
import {MdOptgroup} from './optgroup'; | ||
|
||
|
||
@NgModule({ | ||
imports: [MdRippleModule, CommonModule, MdSelectionModule], | ||
exports: [MdOption, MdOptgroup], | ||
declarations: [MdOption, MdOptgroup] | ||
}) | ||
export class MdOptionModule {} | ||
|
||
|
||
export * from './option'; | ||
export * from './optgroup'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<label class="mat-optgroup-label" [id]="_labelId">{{ label }}</label> | ||
<ng-content select="md-option, mat-option"></ng-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Component, ViewEncapsulation, ContentChildren, QueryList, Input} from '@angular/core'; | ||
import {mixinDisabled, CanDisable} from '../common-behaviors/disabled'; | ||
|
||
// Boilerplate for applying mixins to MdOptgroup. | ||
export class MdOptgroupBase { } | ||
export const _MdOptgroupMixinBase = mixinDisabled(MdOptgroupBase); | ||
|
||
// Counter for unique group ids. | ||
let _uniqueOptgroupIdCounter = 0; | ||
|
||
/** | ||
* Component that is used to group instances of `md-option`. | ||
*/ | ||
@Component({ | ||
moduleId: module.id, | ||
selector: 'md-optgroup, mat-optgroup', | ||
templateUrl: 'optgroup.html', | ||
encapsulation: ViewEncapsulation.None, | ||
inputs: ['disabled'], | ||
host: { | ||
'class': 'mat-optgroup', | ||
'role': 'group', | ||
'[class.mat-optgroup-disabled]': 'disabled', | ||
'[attr.aria-disabled]': 'disabled.toString()', | ||
'[attr.aria-labelledby]': '_labelId', | ||
} | ||
}) | ||
export class MdOptgroup extends _MdOptgroupMixinBase implements CanDisable { | ||
/** Label for the option group. */ | ||
@Input() label: string; | ||
|
||
/** Unique id for the underlying label. */ | ||
_labelId: string = `mat-optgroup-label-${_uniqueOptgroupIdCounter++}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.