-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(top app bar): Add short top app bar always collapsed feature #2327
Changes from 3 commits
667361e
8455cfb
8a1a961
99b066b
47317a4
7593d0b
12528ab
3d2d231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,16 +160,20 @@ | |
<div class="demo-controls-container"> | ||
<h3>Demo Controls</h3> | ||
<div> | ||
<input type="checkbox" id="rtl-checkbox"/> | ||
<label for="rtl-checkbox">RTL</label> | ||
<input type="checkbox" id="rtl-checkbox"/> | ||
<label for="rtl-checkbox">RTL</label> | ||
</div> | ||
<div> | ||
<input type="checkbox" id="short-checkbox"/> | ||
<label for="short-checkbox">Short</label> | ||
<input type="checkbox" id="short-checkbox"/> | ||
<label for="short-checkbox">Short</label> | ||
</div> | ||
<div> | ||
<input type="checkbox" id="no-action-item-checkbox"/> | ||
<label for="no-action-item-checkbox">No Action Item</label> | ||
<input type="checkbox" id="no-action-item-checkbox"/> | ||
<label for="no-action-item-checkbox">No Action Item</label> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move this one up before Short to keep the Short-related things together |
||
</div> | ||
<div> | ||
<input type="checkbox" id="always-closed-checkbox" disabled/> | ||
<label for="always-closed-checkbox">Always Closed (Short Only)‎</label> | ||
</div> | ||
</div> | ||
|
||
|
@@ -188,6 +192,7 @@ <h3>Demo Controls</h3> | |
var shortCheckbox = document.getElementById('short-checkbox'); | ||
var noActionItemCheckbox = document.getElementById('no-action-item-checkbox'); | ||
var rtlCheckbox = document.getElementById('rtl-checkbox'); | ||
var alwaysClosedCheckbox = document.getElementById('always-closed-checkbox'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: reorder these to match DOM? |
||
|
||
appBarEl.addEventListener('MDCTopAppBar:nav', function() { | ||
drawer.open = true; | ||
|
@@ -203,7 +208,17 @@ <h3>Demo Controls</h3> | |
if (!this.checked) { | ||
appBarEl.classList.remove('mdc-top-app-bar--short-collapsed'); | ||
appBarEl.classList.remove('mdc-top-app-bar--short-has-action-item'); | ||
alwaysClosedCheckbox.checked = false; | ||
} | ||
|
||
alwaysClosedCheckbox.disabled = !this.checked; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding a disabled label style like in our text field demo page, to make the disabled state more obvious. |
||
}); | ||
|
||
alwaysClosedCheckbox.addEventListener('change', function() { | ||
this.checked ? appBarEl.classList.add('mdc-top-app-bar--short-collapsed') : appBarEl.classList.remove('mdc-top-app-bar--short-collapsed'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as last time, move the ternary to within square brackets like what was done for shortCheckbox in the previous PR |
||
|
||
appBar.destroy(); | ||
appBar = mdc.topAppBar.MDCTopAppBar.attachTo(appBarEl); | ||
}); | ||
|
||
noActionItemCheckbox.addEventListener('change', function() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,22 @@ Short top app bars should only be used with one action item: | |
</header> | ||
``` | ||
|
||
Short top app bars can be configured to stay collapsed by applying the `mdc-top-app-bar--short-collapsed` before instantiating the component : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might re-word "stay" to "always appear" |
||
|
||
```html | ||
<header class="mdc-top-app-bar mdc-top-app-bar--short mdc-top-app-bar--short-collapsed"> | ||
<div class="mdc-top-app-bar__row"> | ||
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start"> | ||
<a href="#" class="material-icons mdc-top-app-bar__navigation-icon">menu</a> | ||
<span class="mdc-top-app-bar__title">Title</span> | ||
</section> | ||
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="top-app-bar"> | ||
<a href="#" class="material-icons mdc-top-app-bar__icon" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a> | ||
</section> | ||
</div> | ||
</header> | ||
``` | ||
|
||
### JavaScript | ||
|
||
```js | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,14 +67,13 @@ class MDCTopAppBarFoundation extends MDCFoundation { | |
} | ||
|
||
init() { | ||
this.adapter_.registerNavigationIconInteractionHandler('click', this.navClickHandler_); | ||
|
||
const isShortTopAppBar = this.adapter_.hasClass(cssClasses.SHORT_CLASS); | ||
|
||
if (isShortTopAppBar) { | ||
this.adapter_.registerScrollHandler(this.scrollHandler_); | ||
this.initShortAppBar_(); | ||
this.initShortTopAppBar_(); | ||
} | ||
|
||
this.adapter_.registerNavigationIconInteractionHandler('click', this.navClickHandler_); | ||
} | ||
|
||
destroy() { | ||
|
@@ -85,14 +84,21 @@ class MDCTopAppBarFoundation extends MDCFoundation { | |
/** | ||
* Used to set the initial style of the short top app bar | ||
*/ | ||
initShortAppBar_() { | ||
initShortTopAppBar_() { | ||
const isAlwaysCollapsed = this.adapter_.hasClass(cssClasses.SHORT_COLLAPSED_CLASS); | ||
|
||
if (this.adapter_.getTotalActionItems() > 0) { | ||
this.adapter_.addClass(cssClasses.SHORT_HAS_ACTION_ITEM_CLASS); | ||
} | ||
|
||
if (!isAlwaysCollapsed) { | ||
this.adapter_.registerScrollHandler(this.scrollHandler_); | ||
this.shortAppBarScrollHandler_(); | ||
} | ||
} | ||
|
||
/** | ||
* Scroll handler for applying/removing the closed modifier class | ||
* Scroll handler for applying/removing the collapsed modifier class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey I missed this one last time didn't I 👀 |
||
* on the short top app bar. | ||
*/ | ||
shortAppBarScrollHandler_() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,15 @@ test('applyPassive returns false for browsers that do not support passive event | |
}; | ||
assert.isFalse(util.applyPassive(mockWindow, true)); | ||
}); | ||
|
||
test('applyPassive returns previous value when called twice without refresh', () => { | ||
const mockWindow = { | ||
document: { | ||
addEventListener: function(name, method, options) { | ||
return options.passive; | ||
}, | ||
}, | ||
}; | ||
util.applyPassive(mockWindow, true); | ||
assert.deepEqual(util.applyPassive(mockWindow, false), {passive: true}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of tangential to this PR anyway, but is this really testing what we need it to test? I think this would pass whether we called it with force=true or false. (Also force=true mainly exists for tests to begin with.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this to improve branch coverage to 100%. However, after referencing |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason these are now double-nested?