Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit 8c68b2c

Browse files
TedSandernshahan
authored andcommitted
Add an attribute to pass classes from material-dropdown-select to the internal material-popup to allow scoping the content in the popup.
PiperOrigin-RevId: 176564169
1 parent 8fdfece commit 8c68b2c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/material_select/material_dropdown_select.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,40 @@ class MaterialDropdownSelectComponent extends MaterialSelectBase
185185
@Input()
186186
ComponentRenderer labelRenderer;
187187

188+
/// CSS classes from the root element, passed to the popup to allow scoping of
189+
/// mixins.
190+
///
191+
/// Only visible for the template.
192+
final String popupClassName;
193+
188194
MaterialDropdownSelectComponent(
189195
@Optional() IdGenerator idGenerator,
190196
@Optional() @SkipSelf() this._popupSizeDelegate,
191-
@Optional() @Inject(rtlToken) bool rtl)
192-
: activeModel = new ActiveItemModel(idGenerator) {
197+
@Optional() @Inject(rtlToken) bool rtl,
198+
@Attribute('popupClass') String popupClass,
199+
HtmlElement element)
200+
: activeModel = new ActiveItemModel(idGenerator),
201+
popupClassName =
202+
_constructEncapsulatedCss(popupClass, element.classes) {
193203
isRtl = rtl;
194204
preferredPositions = RelativePosition.overlapAlignments;
195205
iconName = 'arrow_drop_down';
196206
}
197207

208+
/// Return a string representing the encapsulated classes from [classes]
209+
/// combined with the classes from [className].
210+
// TODO(google): Move this somewhere more common if this becomes common
211+
// practice.
212+
static String _constructEncapsulatedCss(
213+
String className, CssClassSet classes) {
214+
var result = className ?? '';
215+
for (var i in classes) {
216+
// Add encapsulation classes from host
217+
if (i.startsWith('_')) result += ' $i';
218+
}
219+
return result;
220+
}
221+
198222
@Input()
199223
@override
200224
set componentRenderer(ComponentRenderer value) {

lib/material_select/material_dropdown_select.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
&ngsp;<ng-content select="[buttonContent]"></ng-content>
2424
</dropdown-button>
2525
<material-popup enforceSpaceConstraints
26+
[class]="popupClassName"
2627
[preferredPositions]="preferredPositions"
2728
[matchMinSourceWidth]="popupMatchInputWidth"
2829
[slide]="slide"

0 commit comments

Comments
 (0)