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

Commit 97cbe69

Browse files
devversionjelbourn
authored andcommitted
feat(navBar): option to disable ink bar (#9866)
* Adds support for the `md-no-ink-bar` attribute for the navBar (as same as in the tabs) Closes #9862.
1 parent 1ed298b commit 97cbe69

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/components/navBar/demoBasicUsage/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<div ng-controller="AppCtrl" ng-cloak>
22
<md-content class="md-padding">
3-
<md-nav-bar md-selected-nav-item="currentNavItem" nav-bar-aria-label="navigation links">
3+
<md-nav-bar md-selected-nav-item="currentNavItem"
4+
md-no-ink-bar="disableInkBar"
5+
nav-bar-aria-label="navigation links">
6+
47
<md-nav-item md-nav-click="goto('page1')" name="page1">Page One</md-nav-item>
58
<md-nav-item md-nav-click="goto('page2')" name="page2">Page Two</md-nav-item>
69
<md-nav-item md-nav-click="goto('page3')" name="page3">Page Three</md-nav-item>
@@ -12,5 +15,8 @@
1215
<div class="ext-content">
1316
External content for `<span>{{currentNavItem}}</span>`.
1417
</div>
18+
19+
<md-checkbox ng-model="disableInkBar">Disable Ink Bar</md-checkbox>
20+
1521
</md-content>
1622
</div>

src/components/navBar/navBar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ angular.module('material.components.navBar', ['material.core'])
3636
*
3737
* @param {string=} mdSelectedNavItem The name of the current tab; this must
3838
* match the name attribute of `<md-nav-item>`
39+
* @param {boolean=} mdNoInkBar If set to true, the ink bar will be hidden.
3940
* @param {string=} navBarAriaLabel An aria-label for the nav-bar
4041
*
4142
* @usage
@@ -101,6 +102,7 @@ function MdNavBar($mdAria, $mdTheming) {
101102
bindToController: true,
102103
scope: {
103104
'mdSelectedNavItem': '=?',
105+
'mdNoInkBar': '=?',
104106
'navBarAriaLabel': '@?',
105107
},
106108
template:
@@ -114,7 +116,7 @@ function MdNavBar($mdAria, $mdTheming) {
114116
'aria-label="{{ctrl.navBarAriaLabel}}">' +
115117
'</ul>' +
116118
'</nav>' +
117-
'<md-nav-ink-bar></md-nav-ink-bar>' +
119+
'<md-nav-ink-bar ng-hide="ctrl.mdNoInkBar"></md-nav-ink-bar>' +
118120
'</div>',
119121
link: function(scope, element, attrs, ctrl) {
120122
$mdTheming(element);
@@ -240,7 +242,7 @@ MdNavBarController.prototype._updateInkBarStyles = function(tab, newIndex, oldIn
240242

241243
this._inkbar.css({display: newIndex < 0 ? 'none' : ''});
242244

243-
if(tab){
245+
if (tab) {
244246
var tabEl = tab.getButtonEl();
245247
var left = tabEl.offsetLeft;
246248

src/components/navBar/navBar.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ md-nav-ink-bar {
5858
transition: left $duration $swift-ease-in-out-timing-function,
5959
right ($duration * $multiplier) $swift-ease-in-out-timing-function;
6060
}
61+
62+
// By default $ngAnimate looks for transition durations on the element, when using ng-hide, ng-if, ng-show.
63+
// The ink bar has a transition duration applied, which means, that $ngAnimate delays the hide process.
64+
// To avoid this, we need to reset the transition, when $ngAnimate looks for the duration.
65+
&.ng-animate {
66+
transition: none;
67+
}
68+
6169
}
6270

6371
md-nav-extra-content {

src/components/navBar/navBar.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ describe('mdNavBar', function() {
3333

3434
function createTabs() {
3535
create(
36-
'<md-nav-bar md-selected-nav-item="selectedTabRoute" nav-bar-aria-label="{{ariaLabel}}">' +
36+
'<md-nav-bar md-selected-nav-item="selectedTabRoute" ' +
37+
' md-no-ink-bar="noInkBar" ' +
38+
' nav-bar-aria-label="{{ariaLabel}}">' +
3739
' <md-nav-item md-nav-href="#1" name="tab1">' +
3840
' tab1' +
3941
' </md-nav-item>' +
@@ -173,6 +175,21 @@ describe('mdNavBar', function() {
173175
expect(parseInt(getInkbarEl().style.left))
174176
.toBeCloseTo(getTab('tab3')[0].offsetLeft, 0.1);
175177
});
178+
179+
it('should hide if md-no-ink-bar is enabled', function() {
180+
$scope.noInkBar = false;
181+
$scope.selectedTabRoute = 'tab1';
182+
183+
createTabs();
184+
185+
expect(getInkbarEl().offsetParent).toBeTruthy();
186+
187+
$scope.$apply('noInkBar = true');
188+
expect(getInkbarEl().offsetParent).not.toBeTruthy();
189+
190+
$scope.$apply('noInkBar = false');
191+
expect(getInkbarEl().offsetParent).toBeTruthy();
192+
});
176193
});
177194

178195
describe('a11y', function() {

0 commit comments

Comments
 (0)