material-components-web icon indicating copy to clipboard operation
material-components-web copied to clipboard

Investigate adding flexible variant to mdc-top-app-bar

Open lynnelainejepsen opened this issue 8 years ago • 4 comments

Our existing mdc-toolbar component has a flexible variant (changes the height as the user scrolls). However this functionality was never specified in the material design guidelines. Given that people in the community want this flexible feature, we think we should add it to the new mdc-top-app-bar component...but we need to first work with our designers to specify this flexible feature in the material design guidelines.

If you want to influence the specifications of this flexible variant of mdc-top-app-bar, please leave comments on this thread about how you would like to use this feature in your website.

lynnelainejepsen avatar Jul 06 '18 19:07 lynnelainejepsen

Yes! A "fixed last row" feature would be nice. It's not that hard to do it on the developer side, but it would be a small and useful addition that would simplify devs' work. I personally use it to show a welcoming title then for content that should always be at the top, on scroll. Please check #3945 for future reference.

touficbatache avatar Oct 22 '18 19:10 touficbatache

This what I've done:

var topAppBar = document.querySelector('.mdc-top-app-bar');
var calculatedPeekHeight = topAppBar.clientHeight - document.querySelector('.mdc-top-app-bar .mdc-top-app-bar__row:last-of-type').clientHeight;
window.onscroll = function() {
  var peekHeight = Math.min(scrollY, calculatedPeekHeight);
  document.querySelector(".mdc-top-app-bar").style.transform = 'translateY(' + peekHeight * -1 + 'px)';
}
  • calculatedPeekHeight is the (height of the top app bar) - (height of the last/fixed row): for instance 56px
  • peekHeight is the scroll value, at max 56px
  • apply those two variables to the top app bar on scroll

I hope this small piece of code will be useful :smiley:

touficbatache avatar Oct 22 '18 19:10 touficbatache

We have used the mdc-toolbar mdc-toolbar--fixed mdc-toolbar--waterfall mdc-toolbar--flexible mdc-toolbar--flexible-default-behavior classes. The behavior is found on: material.io/design/components/app-bars-top.html#behavior

We would like to remain this look and feel when using the new mdc-top-app-bar component.

kvdheuvel avatar Oct 24 '18 13:10 kvdheuvel

Something new on the mdc-top-app-bar with scrollable prominent header? The header is scrolling outside the window in the current implementation. As @kvdheuvel mentioned, the docs keeps the prominent app-bar in window all the time. mdc-toolbar had that feature enabled.

KentuckyMC avatar Jan 15 '19 13:01 KentuckyMC