material icon indicating copy to clipboard operation
material copied to clipboard

Modals do not appear to respect theming

Open WillsB3 opened this issue 12 years ago • 23 comments

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?

WillsB3 avatar Nov 03 '14 13:11 WillsB3

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

rschmukler avatar Nov 03 '14 17:11 rschmukler

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

Many thanks

WillsB3 avatar Nov 03 '14 18:11 WillsB3

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

WillsB3 avatar Nov 05 '14 13:11 WillsB3

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!

rschmukler avatar Nov 05 '14 13:11 rschmukler

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 avatar Dec 01 '15 13:12 hkjels

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

vikassaklecha avatar Jan 28 '16 10:01 vikassaklecha

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.

vikassaklecha avatar Jan 28 '16 10:01 vikassaklecha

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.

hkjels avatar Jan 28 '16 11:01 hkjels

+1

bobwah avatar Mar 13 '16 11:03 bobwah

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

mjt60 avatar Apr 06 '16 21:04 mjt60

+1

oostmeijer avatar Jul 06 '16 06:07 oostmeijer

+1

Soren234 avatar Aug 08 '16 11:08 Soren234

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 avatar Aug 31 '16 12:08 dpoetzsch

@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 avatar Sep 02 '16 10:09 hkjels

@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)

dpoetzsch avatar Sep 02 '16 14:09 dpoetzsch

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

hkjels avatar Sep 02 '16 15:09 hkjels

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

johannesjo avatar Feb 10 '17 15:02 johannesjo

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

dlombardi avatar Feb 16 '17 15:02 dlombardi

@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

dpoetzsch avatar Feb 21 '17 20:02 dpoetzsch

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

ghost avatar Apr 19 '17 12:04 ghost