Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@material/top-app-bar
Advanced tools
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. |
14.0.0 (2022-04-27)
unset
is unsupported in IE. (f460e23)validateTooltipWithCaretDistances
method. (3e30054)theme-styles
mixin... the value being retreived from the $theme
map and css property name was swapped. The mixin would request font-size
/font-weight
/letter-spacing
from the $theme
map (which expects size
/weight
/tracking
)... so these values would always be null
. (32b3913)attachTo
. (05db65e)showTimeout
is not set (indicating that this tooltip is about to be re-shown). (6ca8b8f)minRange
param to range sliders to request a minimum gap between the two thumbs. (8fffcb5)valueToAriaValueTextFn
and valueToValueIndicatorTextFn
functions are called for. (b6510c8)PiperOrigin-RevId: 444830518
PiperOrigin-RevId: 419837612
FAQs
The Material Components for the web top app bar component
The npm package @material/top-app-bar receives a total of 440,469 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.