Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@material/top-app-bar
Advanced tools
The Material Components for the web top app bar component
The top app bar provides content and actions related to the current screen. It’s used for branding, screen titles, navigation, and actions.
There are two types of top app bar:
A regular top app bar can transform into a contextual action bar.
npm install @material/top-app-bar
@use "@material/icon-button";
@use "@material/top-app-bar/mdc-top-app-bar";
@include icon-button.core-styles;
import {MDCTopAppBar} from '@material/top-app-bar';
// Instantiation
const topAppBarElement = document.querySelector('.mdc-top-app-bar');
const topAppBar = new MDCTopAppBar(topAppBarElement);
Note: See Importing the JS component for more information on how to import JavaScript.
The top app bar provides content and actions related to the current screen. It’s used for branding, screen titles, navigation, and actions.
<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">
<button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button" aria-label="Open navigation menu">menu</button>
<span class="mdc-top-app-bar__title">Page title</span>
</section>
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Favorite">favorite</button>
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Search">search</button>
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Options">more_vert</button>
</section>
</div>
</header>
<main class="mdc-top-app-bar--fixed-adjust">
App content
</main>
Top app bars can contain action items which are placed on the side opposite the navigation icon. You must also attach the mdc-icon-button
class to both the mdc-top-app-bar__navigation-icon
and the mdc-top-app-bar__action-item
elements in order to get the correct styles applied.
For further documentation on icons, please see the mdc-icon-button docs.
A top app bar can transform into a contextual action bar to provide contextual actions to selected items. For example, upon user selection of photos from a gallery, the top app bar transforms to a contextual app bar with actions related to the selected photos.
When a top app bar transforms into a contextual action bar, the following changes occur:
The following example shows a contextual action bar with a contextual title, a close icon, two contextual action icons, and an overflow menu:
<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">
<button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button" aria-label="Close">close</button>
<span class="mdc-top-app-bar__title">Contextual title</span>
</section>
<section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" role="toolbar">
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Share">share</button>
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Delete">delete</button>
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Open menu">more_vert</button>
</section>
</div>
</header>
<main class="mdc-top-app-bar--fixed-adjust">
App content
</main>
Short top app bars are top app bars that can collapse to the navigation icon side when scrolled.
<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">
<button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button">menu</button>
<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">
<button class="material-icons mdc-top-app-bar__action-item mdc-icon-button" aria-label="Bookmark this page">bookmark</button>
</section>
</div>
</header>
<main class="mdc-top-app-bar--short-fixed-adjust">
App content
</main>
Note: Short top app bars should be used with no more than 1 action item.
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">
...
</header>
<main class="mdc-top-app-bar--short-fixed-adjust">
App content
</main>
Fixed top app bars stay at the top of the page and elevate above the content when scrolled.
<header class="mdc-top-app-bar mdc-top-app-bar--fixed">
...
</header>
<main class="mdc-top-app-bar--fixed-adjust">
App content
</main>
The prominent top app bar is taller.
<header class="mdc-top-app-bar mdc-top-app-bar--prominent">
...
</header>
<main class="mdc-top-app-bar--prominent-fixed-adjust">
App content
</main>
The dense top app bar is shorter.
<header class="mdc-top-app-bar mdc-top-app-bar--dense">
...
</header>
<main class="mdc-top-app-bar--dense-fixed-adjust">
App content
</main>
Class | Description |
---|---|
mdc-top-app-bar | Mandatory. |
mdc-top-app-bar--fixed | Class used to style the top app bar as a fixed top app bar. |
mdc-top-app-bar--fixed-adjust | Class used to style the content below the top app bar to prevent the top app bar from covering it. |
mdc-top-app-bar--prominent | Class used to style the top app bar as a prominent top app bar. |
mdc-top-app-bar--prominent-fixed-adjust | Class used to style the content below the prominent top app bar to prevent the top app bar from covering it. |
mdc-top-app-bar--dense | Class used to style the top app bar as a dense top app bar. |
mdc-top-app-bar--dense-fixed-adjust | Class used to style the content below the dense top app bar to prevent the top app bar from covering it. |
mdc-top-app-bar--dense-prominent-fixed-adjust | Class used to style the content below the top app bar when styled as both dense and prominent, to prevent the top app bar from covering it. |
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. |
mdc-top-app-bar--short-fixed-adjust | Class used to style the content below the short top app bar to prevent the top app bar from covering it. |
Mixin | Description |
---|---|
ink-color($color) | Sets the ink color of the top app bar. |
icon-ink-color($color) | Sets the ink color of the top app bar icons. |
fill-color($color) | Sets the fill color of the top app bar. |
fill-color-accessible($color) | Sets the fill color of the top app bar and automatically sets a high-contrast ink color. |
short-shape-radius($radius, $rtl-reflexive) | Sets the rounded shape to short top app bar variant (when it is collapsed) with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to true. |
MDCTopAppBar
properties and methodsMethod Signature | Description |
---|---|
setScrollTarget(target: element) => void | Sets scroll target to different DOM node (default is window). |
Event Name | Event Data Structure | Description |
---|---|---|
MDCTopAppBar:nav | None | Emits when the navigation icon is clicked. |
If you are using a JavaScript framework, such as React or Angular, you can create a Top App Bar for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.
MDCTopAppBarAdapter
Method Signature | Description |
---|---|
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. |
hasClass(className: string) => boolean | Checks if the root element of the component has the given className. |
setStyle(property: string, value: string) => void | Sets the specified CSS property to the given value on the root element. |
getTopAppBarHeight() => number | Gets the height in px of the top app bar. |
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. |
notifyNavigationIconClicked() => void | Emits a custom event MDCTopAppBar:nav when the navigation icon is clicked. |
MDCTopAppBarBaseFoundation
, MDCTopAppBarFoundation
, MDCFixedTopAppBarFoundation
and MDCShortTopAppBarFoundation
All foundations provide the following methods:
Method Signature | Description |
---|---|
handleTargetScroll() => void | Handles scroll event on specified scrollTarget (defaults to window ). |
handleWindowResize() => void | Handles resize event on window. |
handleNavigationClick() => void | Handles click event on navigation icon. |
MDCShortTopAppBarFoundation
In addition to the methods above, the short variant provides the following public methods and properties:
Method Signature | Description |
---|---|
setAlwaysCollapsed(value: boolean) => void | When value is true , sets the short top app bar to always be collapsed. |
getAlwaysCollapsed() => boolean | Gets if the short top app bar is in the "always collapsed" state. |
Property | Value Type | Description |
---|---|---|
isCollapsed | boolean (read-only) | Indicates whether the short top app bar is in the collapsed state. |
FAQs
The Material Components for the web top app bar component
The npm package @material/top-app-bar receives a total of 545,302 weekly downloads. As such, @material/top-app-bar popularity was classified as popular.
We found that @material/top-app-bar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.