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

Commit e4b26e6

Browse files
Googlernshahan
authored andcommitted
Paper tooltips: Allow paper tooltip CSS to be customizable.
Currently, paper tooltips are styled by applying "paper-container" to a container DIV that wraps the tooltip's transcluded content. This makes it difficult for clients to conditionally style .paper-container, since parent selectors don't exist in CSS -- i.e. while it is easy to style `.paper-container > transposed-content`, but tough to style `.paper-container:has(transposed-content)` PiperOrigin-RevId: 189416785
1 parent afdf2bd commit e4b26e6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/src/material_tooltip/paper_tooltip.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:html';
67

78
import 'package:angular/angular.dart';
9+
import 'package:angular_components/utils/angular/css/css.dart';
810
import 'package:angular_components/content/deferred_content.dart';
911
import 'package:angular_components/content/deferred_content_aware.dart';
1012
import 'package:angular_components/laminate/enums/alignment.dart';
@@ -61,6 +63,7 @@ getTooltipHandle(MaterialPaperTooltipComponent tooltip) =>
6163
[offsetX]="offsetX"
6264
[offsetY]="offsetY"
6365
[autoDismiss]="false"
66+
[class]="popupClassName"
6467
[source]="popupSource"
6568
role="tooltip">
6669
<div class="paper-container"
@@ -79,6 +82,10 @@ getTooltipHandle(MaterialPaperTooltipComponent tooltip) =>
7982
visibility: Visibility.all,
8083
)
8184
class MaterialPaperTooltipComponent implements DeferredContentAware, Tooltip {
85+
// To allow for more flexible styling, classes specified on the host are
86+
// re-applied to material-popup.
87+
final String popupClassName;
88+
8289
PopupSource _tooltipSource;
8390
PopupSource get popupSource => _tooltipSource;
8491

@@ -106,7 +113,10 @@ class MaterialPaperTooltipComponent implements DeferredContentAware, Tooltip {
106113
final TooltipController _tooltipController;
107114
final ChangeDetectorRef _changeDetector;
108115

109-
MaterialPaperTooltipComponent(this._tooltipController, this._changeDetector);
116+
MaterialPaperTooltipComponent(this._tooltipController, this._changeDetector,
117+
HtmlElement hostElement, @Attribute('tooltipClass') String tooltipClass)
118+
: popupClassName =
119+
constructEncapsulatedCss(tooltipClass, hostElement.classes);
110120

111121
@ViewChild(MaterialPopupComponent)
112122
set popupChild(MaterialPopupComponent popup) {

0 commit comments

Comments
 (0)