Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit f799659

Browse files
authored
fix(top-app-bar): Move scroll target initialization; improve test (#4106)
1 parent 7abfd5d commit f799659

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/mdc-top-app-bar/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class MDCTopAppBar extends MDCComponent {
6363
ripple.unbounded = true;
6464
return ripple;
6565
});
66+
67+
this.scrollTarget_ = window;
6668
}
6769

6870
destroy() {
@@ -119,8 +121,6 @@ class MDCTopAppBar extends MDCComponent {
119121
})
120122
);
121123

122-
this.scrollTarget_ = window;
123-
124124
/** @type {!MDCTopAppBarBaseFoundation} */
125125
let foundation;
126126
if (this.root_.classList.contains(cssClasses.SHORT_CLASS)) {

test/unit/mdc-top-app-bar/mdc-top-app-bar.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function getFixture(removeIcon) {
6262
</header>
6363
<main class="mdc-top-app-bar-fixed-adjust">
6464
</main>
65-
<div class="content">Content</div>
6665
</div>
6766
`;
6867

@@ -291,10 +290,10 @@ test('adapter#getViewportScrollY returns scroll distance', () => {
291290
});
292291

293292
test('adapter#getViewportScrollY returns scroll distance when scrollTarget_ is not window', () => {
294-
const {component, fixture} = setupTest();
295-
const content = fixture.querySelector('.content');
296-
component.scrollTarget_ = content;
297-
assert.equal(component.getDefaultFoundation().adapter_.getViewportScrollY(), content.scrollTop);
293+
const {component} = setupTest();
294+
const mockContent = {addEventListener: () => {}, scrollTop: 20};
295+
component.setScrollTarget(mockContent);
296+
assert.equal(component.getDefaultFoundation().adapter_.getViewportScrollY(), mockContent.scrollTop);
298297
});
299298

300299
test('adapter#getTotalActionItems returns the number of action items on the opposite side of the menu', () => {

0 commit comments

Comments
 (0)