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

Commit 81b44a4

Browse files
fix(themes): anchor should inherit theme to support colors
Without theme inheritance, classname uses of md-primary, md-accent, md-warn will not work properly. * add theming.js spec url > Developers must still apply the classname to the stand-alone anchor tags.
1 parent 9245f54 commit 81b44a4

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

src/components/button/button-theme.scss

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,36 +157,38 @@
157157
}
158158

159159

160-
._md a.md-THEME_NAME-theme:not(.md-button) {
161-
&.md-primary {
162-
color: '{{primary-color}}';
160+
._md {
161+
a.md-THEME_NAME-theme:not(.md-button) {
162+
&.md-primary {
163+
color: '{{primary-color}}';
163164

164-
&:hover {
165-
color: '{{primary-700}}';
165+
&:hover {
166+
color: '{{primary-700}}';
167+
}
166168
}
167-
}
168-
169-
&.md-accent {
170-
color: '{{accent-color}}';
171169

172-
&:hover {
173-
color: '{{accent-700}}';
170+
&.md-accent {
171+
color: '{{accent-color}}';
172+
173+
&:hover {
174+
color: '{{accent-700}}';
175+
}
174176
}
175-
}
176177

177-
&.md-accent {
178-
color: '{{accent-color}}';
178+
&.md-accent {
179+
color: '{{accent-color}}';
179180

180-
&:hover {
181-
color: '{{accent-A700}}';
181+
&:hover {
182+
color: '{{accent-A700}}';
183+
}
182184
}
183-
}
184185

185-
&.md-warn {
186-
color: '{{warn-color}}';
186+
&.md-warn {
187+
color: '{{warn-color}}';
187188

188-
&:hover {
189-
color: '{{warn-700}}';
189+
&:hover {
190+
color: '{{warn-700}}';
191+
}
190192
}
191193
}
192194
}

src/components/button/button.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,40 @@
77
*/
88
angular
99
.module('material.components.button', [ 'material.core' ])
10-
.directive('mdButton', MdButtonDirective);
10+
.directive('mdButton', MdButtonDirective)
11+
.directive('a', MdAnchorDirective);
12+
13+
14+
/**
15+
* @ngdoc directive
16+
* @name a
17+
* @module material.components.button
18+
*
19+
* @restrict E
20+
*
21+
* @description
22+
* `a` is a anchnor directive used to inherit theme so stand-alone anchors.
23+
* This allows standalone `a` tags to support theme colors for md-primary, md-accent, etc.
24+
*
25+
* @usage
26+
*
27+
* <hljs lang="html">
28+
* <md-content md-theme="myTheme">
29+
* <a href="#chapter1" class="md-accent"></a>
30+
* </md-content>
31+
* </hljs>
32+
*/
33+
function MdAnchorDirective($mdTheming) {
34+
return {
35+
restrict : 'E',
36+
link : function postLink(scope, element) {
37+
// Make sure to inherit theme so stand-alone anchors
38+
// support theme colors for md-primary, md-accent, etc.
39+
$mdTheming(element);
40+
}
41+
};
42+
}
43+
1144

1245
/**
1346
* @ngdoc directive

src/core/services/theming/theming.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ var GENERATED = { };
6363
var PALETTES;
6464
var THEMES;
6565

66+
// Text Colors on light and dakr backgrounds
67+
// @see https://www.google.com/design/spec/style/color.html#color-text-background-colors
6668
var DARK_FOREGROUND = {
6769
name: 'dark',
6870
'1': 'rgba(0,0,0,0.87)',

0 commit comments

Comments
 (0)