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

Commit 9c56383

Browse files
committed
feat(tabs): ink ripple color syncs with ink bar
1 parent 6c4413e commit 9c56383

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

src/components/tabs/js/inkBarDirective.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ function MdTabInkDirective($mdConstant, $window, $$rAF, $timeout) {
2525

2626
if (nobar) return;
2727

28+
tabsCtrl.inkBarElement = element;
29+
2830
scope.$watch(tabsCtrl.selected, updateBar);
2931
scope.$on('$mdTabsChanged', updateBar);
3032

3133
function updateBar() {
3234
var selected = tabsCtrl.selected();
3335

34-
var hideInkBar = !selected || tabsCtrl.count() < 2 ||
36+
var hideInkBar = !selected || tabsCtrl.count() < 2 ||
3537
(scope.pagination && scope.pagination.itemsPerPage === 1);
3638
element.css('display', hideInkBar ? 'none' : 'block');
3739

38-
if (!hideInkBar) {
40+
if (!hideInkBar) {
3941
var count = tabsCtrl.count();
4042
var scale = 1 / count;
4143
var left = tabsCtrl.indexOf(selected);

src/components/tabs/js/tabItemDirective.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ function MdTabDirective($mdInkRipple, $compile, $mdAria, $mdUtil, $mdConstant) {
9494
transcludeTabContent();
9595
configureAria();
9696

97-
var detachRippleFn = $mdInkRipple.attachTabBehavior(scope, element);
97+
var detachRippleFn = $mdInkRipple.attachTabBehavior(scope, element, {
98+
colorElement: tabsCtrl.inkBarElement
99+
});
98100
tabsCtrl.add(tabItemCtrl);
99101
scope.$on('$destroy', function() {
100102
detachRippleFn();
@@ -171,7 +173,7 @@ function MdTabDirective($mdInkRipple, $compile, $mdAria, $mdUtil, $mdConstant) {
171173
function watchActiveAttribute() {
172174
var unwatch = scope.$parent.$watch('!!(' + attr.mdActive + ')', activeWatchAction);
173175
scope.$on('$destroy', unwatch);
174-
176+
175177
function activeWatchAction(isActive) {
176178
var isSelected = tabsCtrl.selected() === tabItemCtrl;
177179

@@ -185,7 +187,7 @@ function MdTabDirective($mdInkRipple, $compile, $mdAria, $mdUtil, $mdConstant) {
185187

186188
function watchDisabled() {
187189
scope.$watch(tabItemCtrl.isDisabled, disabledWatchAction);
188-
190+
189191
function disabledWatchAction(isDisabled) {
190192
element.attr('aria-disabled', isDisabled);
191193

src/components/tabs/tabs-theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ md-tabs.md-#{$theme-name}-theme {
1212
}
1313

1414
md-tabs-ink-bar {
15+
color: $tabs-highlight-color;
1516
md-tabs-ink-bar-inner {
1617
background: $tabs-highlight-color;
1718
}

src/core/services/ripple/ripple.js

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,35 @@ function InkRippleService($window, $timeout) {
3030
attach: attach
3131
};
3232

33-
function attachButtonBehavior(scope, element) {
34-
return attach(scope, element, {
33+
function attachButtonBehavior(scope, element, options) {
34+
return attach(scope, element, angular.extend({
3535
isFAB: element.hasClass('md-fab'),
3636
isMenuItem: element.hasClass('md-menu-item'),
3737
center: false,
3838
dimBackground: true
39-
});
39+
}, options));
4040
}
4141

42-
function attachCheckboxBehavior(scope, element) {
43-
return attach(scope, element, {
42+
function attachCheckboxBehavior(scope, element, options) {
43+
return attach(scope, element, angular.extend({
4444
center: true,
4545
dimBackground: false
46-
});
46+
}, options));
4747
}
4848

49-
function attachTabBehavior(scope, element) {
50-
return attach(scope, element, {
49+
function attachTabBehavior(scope, element, options) {
50+
return attach(scope, element, angular.extend({
5151
center: false,
5252
dimBackground: true,
5353
outline: true
54-
});
54+
}, options));
5555
}
5656

5757
function attach(scope, element, options) {
5858
if (element.controller('mdNoInk')) return angular.noop;
5959

60-
var rippleContainer, rippleSize,
61-
controller = element.controller('mdInkRipple') || {},
62-
counter = 0,
63-
ripples = [],
64-
states = [],
65-
isActiveExpr = element.attr('md-highlight'),
66-
isActive = false,
67-
isHeld = false,
68-
node = element[0],
69-
hammertime = new Hammer(node),
70-
color = parseColor(element.attr('md-ink-ripple')) || parseColor($window.getComputedStyle(node).color || 'rgb(0, 0, 0)');
71-
7260
options = angular.extend({
61+
colorElement: element,
7362
mousedown: true,
7463
hover: true,
7564
focus: true,
@@ -79,27 +68,34 @@ function InkRippleService($window, $timeout) {
7968
outline: false,
8069
isFAB: false,
8170
isMenuItem: false
82-
}, options || {});
71+
}, options);
72+
73+
var rippleContainer, rippleSize,
74+
controller = element.controller('mdInkRipple') || {},
75+
counter = 0,
76+
ripples = [],
77+
states = [],
78+
isActiveExpr = element.attr('md-highlight'),
79+
isActive = false,
80+
isHeld = false,
81+
node = element[0],
82+
hammertime = new Hammer(node),
83+
color = parseColor(element.attr('md-ink-ripple')) || parseColor($window.getComputedStyle(options.colorElement[0]).color || 'rgb(0, 0, 0)');
8384

8485
options.mousedown && hammertime.on('hammer.input', onInput);
8586

8687
controller.createRipple = createRipple;
8788

8889
if (isActiveExpr) {
89-
scope.$watch(
90-
function () {
91-
return scope.$eval(isActiveExpr);
92-
},
93-
function (newValue) {
94-
isActive = newValue;
95-
if (isActive && !ripples.length) {
96-
$timeout(function () {
97-
createRipple(0, 0);
98-
}, 0, false);
99-
}
100-
angular.forEach(ripples, updateElement);
101-
}
102-
);
90+
scope.$watch(isActiveExpr, function watchActive(newValue) {
91+
isActive = newValue;
92+
if (isActive && !ripples.length) {
93+
$timeout(function () {
94+
createRipple(0, 0);
95+
}, 0, false);
96+
}
97+
angular.forEach(ripples, updateElement);
98+
});
10399
}
104100

105101
// Publish self-detach method if desired...

0 commit comments

Comments
 (0)