JSPM

@material/top-app-bar

0.32.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 443927
  • Score
    100M100P100Q196078F
  • License Apache-2.0

The Material Components for the web top app bar component

Package Exports

  • @material/top-app-bar
  • @material/top-app-bar/constants
  • @material/top-app-bar/constants.js
  • @material/top-app-bar/dist/mdc.top-app-bar.css
  • @material/top-app-bar/dist/mdc.top-app-bar.min.css
  • @material/top-app-bar/dist/mdc.topAppBar
  • @material/top-app-bar/dist/mdc.topAppBar.js
  • @material/top-app-bar/foundation
  • @material/top-app-bar/index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@material/top-app-bar) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Top App Bar

MDC Top App Bar acts as a container for items such as application title, navigation icon, and action items. Top app bars scroll with content by default.

Design & API Documentation

Installation

npm install --save @material/top-app-bar

Usage

HTML Structure

<header class="mdc-top-app-bar">
  <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>
  </div>
</header>

Top app bars can accommodate multiple action items on the opposite side of the navigation icon:

<header class="mdc-top-app-bar">
  <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="toolbar">
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Download" alt="Download">file_download</a>
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Print this page" alt="Print this page">print</a>
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
    </section>
  </div>
</header>

Short top app bars should only be used with one action item:

<header class="mdc-top-app-bar mdc-top-app-bar--short">
  <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="toolbar">
      <a href="#" class="material-icons mdc-top-app-bar__action-item" aria-label="Bookmark this page" alt="Bookmark this page">bookmark</a>
    </section>
  </div>
</header>

Short top app bars can be configured to always appear collapsed by applying the mdc-top-app-bar--short-collapsed before instantiating the component :

<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

  // Instantiation
  var topAppBarElement = document.querySelector('#topAppBar');
  var topAppBar = mdc.topAppBar.MDCTopAppBar.attachTo(topAppBarElement);
  
  // Listen for navigation icon events 
  topAppBarElement.addEventListener('MDCTopAppBar:nav', function () {
    // do something
  });

CSS Classes

Class Description
mdc-top-app-bar Mandatory.
mdc-top-app-bar--short Class used to style the top app bar as a short top app bar.
mdc-top-app-bar--short-collapsed Class used to indicate the short top app bar is collapsed.

Sass Mixins

Mixin Description
mdc-top-app-bar-ink-color($color) Sets the ink color of the top app bar.
mdc-top-app-bar-icon-ink-color($color) Sets the ink color of the top app bar icons.
mdc-top-app-bar-fill-color($color) Sets the fill color of the top app bar.
mdc-top-app-bar-fill-color-accessible($color) Sets the fill color of the top app bar and automatically sets a high-contrast ink color.
mdc-top-app-bar-short-border-radius($border-radius) Sets the border-bottom-radius property on the action item side. Used only for the short top app bar when collapsed.

MDCTopAppBar

See Importing the JS component for more information on how to import JavaScript.

MDCTopAppBarAdapter

Method Signature Description
hasClass(className: string) => boolean Checks if the root element of the component has the given className.
addClass(className: string) => void Adds a class to the root element of the component.
removeClass(className: string) => void Removes a class from the root element of the component.
registerNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void Registers an event listener on the native navigation icon element for a given event.
deregisterNavigationIconInteractionHandler(evtType: string, handler: EventListener) => void Deregisters an event listener on the native navigation icon element for a given event.
notifyNavigationIconClicked() => void Emits a custom event MDCTopAppBar:nav when the navigation icon is clicked.
registerScrollHandler(handler) => void Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's scroll event.
deregisterScrollHandler(handler) => void Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's scroll event.
getViewportScrollY() => number Gets the number of pixels that the content of body is scrolled from the top of the page.
getTotalActionItems() => number Gets the number of action items in the top app bar.

Events

Event Name Event Data Structure Description
MDCTopAppBar:nav None Emits when the navigation icon is clicked.