Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46493d5

Browse files
authored
Merge pull request google#4859 from chajath/mdl-1.x
Add layout tab class to disable js layout switching
2 parents 2eaf506 + b353f83 commit 46493d5

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

src/layout/layout.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
TAB_BAR_BUTTON: 'mdl-layout__tab-bar-button',
111111
TAB_BAR_LEFT_BUTTON: 'mdl-layout__tab-bar-left-button',
112112
TAB_BAR_RIGHT_BUTTON: 'mdl-layout__tab-bar-right-button',
113+
TAB_MANUAL_SWITCH: 'mdl-layout__tab-manual-switch',
113114
PANEL: 'mdl-layout__tab-panel',
114115

115116
HAS_DRAWER: 'has-drawer',
@@ -549,12 +550,15 @@
549550
tab.appendChild(rippleContainer);
550551
}
551552

552-
tab.addEventListener('click', function(e) {
553-
if (tab.getAttribute('href').charAt(0) === '#') {
554-
e.preventDefault();
555-
selectTab();
556-
}
557-
});
553+
if (!layout.tabBar_.classList.contains(
554+
layout.CssClasses_.TAB_MANUAL_SWITCH)) {
555+
tab.addEventListener('click', function(e) {
556+
if (tab.getAttribute('href').charAt(0) === '#') {
557+
e.preventDefault();
558+
selectTab();
559+
}
560+
});
561+
}
558562

559563
tab.show = selectTab;
560564
}

test/unit/layout.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,49 @@ describe('MaterialLayout', function () {
151151
expect($(drawerBtn)).to.have.attr('aria-expanded', 'false');
152152
});
153153
});
154+
155+
describe('Manual switch mode', function () {
156+
it('should disable content switching', function (done) {
157+
var el = document.createElement('div');
158+
el.innerHTML = '' +
159+
' <header class="mdl-layout__header">' +
160+
' <div class="mdl-layout__tab-bar mdl-js-ripple-effect mdl-layout__tab-manual-switch">' +
161+
' <a id="tab1" href="#scroll-tab-1" class="mdl-layout__tab is-active">Tab 1</a>' +
162+
' <a id="tab2" href="#scroll-tab-2" class="mdl-layout__tab">Tab 2</a>' +
163+
' </div>' +
164+
' </header>' +
165+
' <main class="mdl-layout__content">' +
166+
' <section class="mdl-layout__tab-panel is-active" id="scroll-tab-1">' +
167+
' <div class="page-content"><!-- Your content goes here --></div>' +
168+
' </section>' +
169+
' <section class="mdl-layout__tab-panel" id="scroll-tab-2">' +
170+
' <div class="page-content"><!-- Your content goes here --></div>' +
171+
' </section>' +
172+
' </main>';
173+
174+
var parent = document.createElement('div');
175+
parent.appendChild(el); // MaterialLayout.init() expects a parent
176+
177+
var tab1 = el.querySelector('#tab1');
178+
var tab2 = el.querySelector('#tab2');
179+
var content1 = el.querySelector('#scroll-tab-1');
180+
var content2 = el.querySelector('#scroll-tab-2');
181+
182+
componentHandler.upgradeElement(el, 'MaterialLayout');
183+
184+
var ev = document.createEvent('MouseEvents');
185+
ev.initEvent('click', true, true);
186+
tab2.dispatchEvent(ev);
187+
188+
window.setTimeout(function() {
189+
// Since content switching has been set to manual, layout shouldn't
190+
// have been switched.
191+
expect($(tab1)).to.have.class('is-active');
192+
expect($(content1)).to.have.class('is-active');
193+
expect($(tab2)).to.not.have.class('is-active');
194+
expect($(content2)).to.not.have.class('is-active');
195+
done();
196+
}, 100);
197+
});
198+
});
154199
});

0 commit comments

Comments
 (0)