Material: Modals do not appear to respect theming

Created on 3 Nov 2014  路  23Comments  路  Source: angular/material

When instantiating a modal, the modal always uses the "default" theme (e.g. the class md-default-theme), even though the modals DOM element is a child of <body> on which I have md-theme="custom-theme-name".

I thought maybe we could use the $mdTheming service in our application's .config block to set the default theme name by calling setDefaultTheme('custom-theme-name') but from my initial investigation it seems as though this function is not public and so cannot be called from outside Angular Material.

What is the intended solution for applying themes to modals?

theme

Most helpful comment

1.3.0 broke dialog theme inheritance from designated parent in dialog config. Anything we can do?

All 23 comments

I will take a look at this. Which build are you using?

We are using the source at the tag v0.5.1.

Many thanks

The same issue happens for toasts too. This toast should have the theme mytheme as per the md-theme attribute set on the body, but instead it's set to md-default-theme

screen shot 2014-11-05 at 13 25 01

Indeed, this appears to be an issue with $interimElement not respecting theming. Expect a fix to ship within the next release. Thank you for reporting this!

I'm still seeing this issue. Has it re-appeared or what?
If I specifically add md-theme="sometheme" to md-dialog, that works.
But if I append the dialog to an element that has md-theme set, the styles won't apply.
I'm at 0.11.4

@hkjels I'm having the same issue, can you share a snippet how you are adding to dialog?

snippet

var alert = $mdDialog.alert({
            parent: parentEl,
            targetEvent: $event,
            scope: $scope,        // use parent scope in template
            preserveScope: true,
            theme:"my_theme",
            template:'my_html'
});
$mdDialog.show(alert);

theme shows up in the alert object but does not apply to toolbar and button elements.

I just went around the issue by passing the theme as a local. It's just two extra lines of code, so I can live with it. Still think this should be fixed, but I'm spending my time elsewhere.

+1

I'm also still experiencing this issue. Are we required to use md-theme in out dialogs, and pass the theme variable through locals?

+1

+1

EDIT:
As it was written in #1399 the theme is inherited from the parent element. So one fix is to use the element where you set the md-theme as parent:

....
<body>
    <div md-theme="myTheme" id="md-theme-div">
        CONTENT
    </div>
</body>
....
$mdDialog.show({
    // ...
    parent: angular.element(document.getElementById("md-theme-div")),
});

It is a bit confusing because the behavior makes you think it uses the default theme which is only true because the parent element was set wrong. I think the best option would be to provide some general service in angular that has methods to switch the overall theme of the app and use the md-theme directive only when deviating from the overall theme.

@dpoetzsch even setting the parent explicitly to one with the correct theme does not solve the issue. The theme must be set within the dialog itself.

@hkjels http://codepen.io/dpoetzsch/pen/GjRdWp or did I misunderstand the problem?

One important thing is to have a current version of angular material (this one is with angular 1.5.8 and angular material 1.1.0)

Great! I missed the part with

// This is the absolutely vital part, without this, changes will not cascade down through the DOM.

Can probably close this one now

@dpoetzsch fix doesn't work for me either unfortunately. Isn't there any way to set the dialog theme programmatically at least?

1.3.0 broke dialog theme inheritance from designated parent in dialog config. Anything we can do?

@johannesjo As I just noticed this used to work with angular-material 1.1.1 and was broken in 1.1.2. Well, this sucks!

See here (only thing change from above is the use of angular-material 1.1.2): http://codepen.io/anon/pen/vgovwd

I'm also having the same issue as dlombardi & dpoetzsch

some news about this issue?

on version 1.1.7 the issue persist

Hey @thorvx I fixed this issue with https://github.com/angular/material/pull/11078

The merge request is approved and scheduled for 1.1.8 馃悢

@Splaktar You should be able to close this with https://github.com/angular/material/pull/11078 馃悢

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dona278 picture Dona278  路  3Comments

robertmesserle picture robertmesserle  路  3Comments

ghost picture ghost  路  3Comments

WebTechnolog picture WebTechnolog  路  3Comments

nikhildev picture nikhildev  路  3Comments