Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e3c55f9

Browse files
codymikolmmalerba
authored andcommitted
fix(dialog) md-colors breaking inside of dialogs (#11078)
Only append an md-theme attribute if the md-dialog is propagated from an element that contains an md-theme. Fixes #10276
1 parent 52efe32 commit e3c55f9

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/components/dialog/dialog.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ function MdDialogProvider($$interimElementProvider) {
698698
var startSymbol = $interpolate.startSymbol();
699699
var endSymbol = $interpolate.endSymbol();
700700
var theme = startSymbol + (options.themeWatch ? '' : '::') + 'theme' + endSymbol;
701-
return '<div class="md-dialog-container" tabindex="-1" md-theme="' + theme + '">' + validatedTemplate(template) + '</div>';
701+
var themeAttr = (options.hasTheme) ? 'md-theme="'+theme+'"': '';
702+
return '<div class="md-dialog-container" tabindex="-1" ' + themeAttr + '>' + validatedTemplate(template) + '</div>';
702703

703704
/**
704705
* The specified template should contain a <md-dialog> wrapper element....
@@ -859,7 +860,9 @@ function MdDialogProvider($$interimElementProvider) {
859860

860861
var themeCtrl = targetEl && targetEl.controller('mdTheme');
861862

862-
if (!themeCtrl) {
863+
options.hasTheme = (!!themeCtrl);
864+
865+
if (!options.hasTheme) {
863866
return;
864867
}
865868

src/components/dialog/dialog.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,59 @@ describe('$mdDialog', function() {
18381838
});
18391839

18401840
describe('theming', function () {
1841+
1842+
it('should inherit md-theme if the child has a md-theme to inherit',
1843+
inject(function ($mdDialog, $mdTheming, $rootScope, $compile) {
1844+
1845+
var template = '<div id="rawContent">Hello</div>';
1846+
var parent = angular.element('<div>');
1847+
1848+
var button = $compile(
1849+
'<button ng-click="showDialog($event)" md-theme="coolTheme">test</button>'
1850+
)($rootScope);
1851+
1852+
$mdTheming(button);
1853+
1854+
$rootScope.showDialog = function (ev) {
1855+
$mdDialog.show({
1856+
template: template,
1857+
parent: parent,
1858+
targetEvent: ev
1859+
});
1860+
};
1861+
1862+
button[0].click();
1863+
1864+
var container = angular.element(parent[0].querySelector('.md-dialog-container'));
1865+
1866+
expect(container.attr('md-theme')).toEqual('coolTheme');
1867+
}));
1868+
1869+
it('should not set md-theme if the child does not have md-theme to inherit',
1870+
inject(function ($mdDialog, $mdTheming, $rootScope, $compile) {
1871+
1872+
var template = '<div id="rawContent">Hello</div>';
1873+
var parent = angular.element('<div>');
1874+
1875+
var button = $compile('<button ng-click="showDialog($event)">test</button>')($rootScope);
1876+
1877+
$mdTheming(button);
1878+
1879+
$rootScope.showDialog = function (ev) {
1880+
$mdDialog.show({
1881+
template: template,
1882+
parent: parent,
1883+
targetEvent: ev
1884+
});
1885+
};
1886+
1887+
button[0].click();
1888+
1889+
var container = angular.element(parent[0].querySelector('.md-dialog-container'));
1890+
1891+
expect(container.attr('md-theme')).toBeUndefined();
1892+
}));
1893+
18411894
it('should inherit targetElement theme', inject(function($mdDialog, $mdTheming, $rootScope, $compile) {
18421895
var template = '<div id="rawContent">Hello</div>';
18431896
var parent = angular.element('<div>');

0 commit comments

Comments
 (0)