14.0.0 • Published 5 months ago

@material/button v14.0.0

Weekly downloads
61,876
License
MIT
Repository
github
Last release
5 months ago

Buttons

The MDC Button component is a spec-aligned button component adhering to the Material Design button requirements. It works without JavaScript with basic functionality for all states. You can enhance the button to have ripple effects by instantiating MDCRipple on the button element. See MDC Ripple and Demo for details.

Design & API Documentation

Installation

npm install @material/button

Usage

HTML Structure

<button class="mdc-button">
  Button
</button>

Note: Examples and documents use generic <button>, but users can also apply mdc-button to <a class="mdc-button">Link Button</a> in cases where it is semantically correct.

Adding Icon

Users can nest mdc-button__icon inside the button element to add an icon. The icon in button is set to 18px to meet legibility requirements. This element should also include aria-hidden="true".

We recommend you load Material Icons from Google Fonts:

<head>
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>

<button class="mdc-button">
  <i class="material-icons mdc-button__icon" aria-hidden="true">favorite</i>
  Button
</button>

It's also possible to use an SVG icon:

<button class="mdc-button">
  <svg class="mdc-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" viewBox="...">
  ...
  </svg>
  SVG Icon
</button>

CSS Classes

CSS ClassDescription
mdc-buttonMandatory, defaults to a text button that is flush with the surface
mdc-button__iconOptional, for the icon element
mdc-button--raisedOptional, a contained button that is elevated upon the surface
mdc-button--unelevatedOptional, a contained button that is flush with the surface
mdc-button--outlinedOptional, a contained button that is flush with the surface and has a visible border
mdc-button--denseOptional, compresses the button text to make it slightly smaller

Disabled Button

Users can add disabled directly to the button element or set the fieldset containing the button to disabled to disable a button. Disabled buttons cannot be interacted with and have no visual interaction effect.

<button class="mdc-button mdc-button--raised" disabled>
  Raised disabled button
</button>

Adding MDC Ripple

To add the ink ripple effect to a button, attach a ripple instance to the button element.

mdc.ripple.MDCRipple.attachTo(document.querySelector('.mdc-button'));

You can also do this declaratively when using the material-components-web package.

<button class="mdc-button" data-mdc-auto-init="MDCRipple">
  Flat button
</button>

Buttons are fully aware of ripple styles, so no DOM or CSS changes are required to use them.

Sass Mixins

By default an MDC Button will inherit its color from the theme and align with Material Design button requirements. To customize a Button's color and properties, you can use the following mixins.

mdc-button-filled-accessible($container-fill-color)

This mixin is provided for customizing a raised or unelevated button's color. It changes the Button's container color to the given color, and updates the Button's ink and ripple color to meet accessibility standards.

Advanced Sass Mixins

A note about advanced mixins, The following mixins are intended for advanced users. These mixins will override the color of the container, ink, outline or ripple. You can use all of them if you want to completely customize a Button. Or you can use only one of them, e.g. if you only need to override the ripple color. It is up to you to pick container, ink, outline and ripple colors that work together, and meet accessibility standards.

MixinDescription
mdc-button-container-fill-color($color)Sets the container color to the given color.
mdc-button-icon-color($color)Sets the icon color to the given color.
mdc-button-ink-color($color)Sets the ink color to the given color. This affects both text and icon, unless mdc-button-icon-color is also used.
mdc-button-corner-radius($corner-radius)Sets the corner radius to the given number (defaults to 2px).
mdc-button-horizontal-padding($padding)Sets horizontal padding to the given number.
mdc-button-outline-color($color)Sets the outline color to the given color.
mdc-button-outline-width($width, $padding)Sets the outline width to the given number (defaults to 2px) and adjusts padding accordingly. $padding is only required in cases where mdc-button-horizontal-padding is also included with a custom value.

The ripple effect for the Button component is styled using MDC Ripple mixins.

Note: If you want to customize both horizontal padding and the outline width, simply include the mdc-button-outline-width mixin with both arguments. It will include mdc-button-horizontal-padding for you.

Caveat: Edge and CSS Variables

In browsers that fully support CSS variables, the above mixins will hook up styles using CSS variables if a theme property is passed. However, due to Edge's buggy CSS variable support, mdc-button-container-fill-color will not honor CSS variables in Edge. This means you will need to override button container styles manually for Edge if you are altering the affected CSS variables for theme properties (raised and unelevated buttons use primary by default for the container fill color).

@hazou/material@material/dialog@material/banner@material/tooltip@material/snackbarbw-material-button@zentek/buttonpwa-test-hpwa-test1pwa-test2sot-incubatormdwrapper@beezydev/buttonmrcwmaterial-components-web@everything-registry/sub-chunk-584flicktrip-webcomponentsember-material-componentsexample-elementexplicaboquia@gmvdev/materialshyperapp-mdcimage-posting.webidm-reservation-search-results-details-libirma-components@hieunv/react-mdc@emuanalytics/flow-rdfgspreadlibgta-web-components@flayvor/top-app-bar@finastra/chiphail-mary-projectgesdisc-componentsgit-commit-validate@fran_guevara/bs-first-componenthollaex-web-lib@ikechukwu_boniface/vmddaterangepickerjn-stencil@ied/button@ied/image-posting.web@jrg-material/buttonjsonresume-theme-material-design@smui/dialog@shortcm/react-button@shortcm/react-snackbar@smui/button@rfoxlabs/rfox-nft-webcomponentsnuxt3-mui@rmwc/button@robertkern/vue-material@organtik/material-button@openremote/or-input@squirtle/common@preact-material-components/buttonnextime-delivery-datenexus-portal-components@react-mdc/button@react-universal-dialogs/android@react.material/buttonmarko-mdc@material-design/sveltematerial-imba@mirana/materializematerial-vue-date-pickermaterial-toolboxmaterial-components-sveltematerial-components-web-infernomaterial-components-markomcr-buttonmcu-mern-project@lcap-ui/button@leanup/material-core@lucasecdb/rmdc@listo-paye/sdk-uilogik-config-componentmaple-material-vue@mhamrah/svelte-material-ui@material/react-button@materialr/button@materials-elements/core@materials-elements/site@materials-ui/site@materials-ui/core@mcwv/button@mdc-react/button@mdc-stencil/button@morioh/materialmdc-101-webmdc-stencilmdc-react-gumball@niftykit/components@niftykit/widgets@o-rango/orango-material-design@onecomponent/buttonmollitiaanimi@pitaya-components/accordion@pitaya-components/button@pitaya-components/card@pitaya-components/dialog@pmwcs/button
14.0.0

2 years ago

13.0.0

3 years ago

12.0.0

3 years ago

11.0.0

3 years ago

10.0.0

3 years ago

9.0.0

3 years ago

8.0.0

3 years ago

7.0.0

4 years ago

6.0.0

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.0.0

4 years ago

3.2.0

5 years ago

4.0.0-canary.1

5 years ago

4.0.0-canary.0

5 years ago

4.0.0-alpha.0

5 years ago

3.1.0

5 years ago

3.1.0-alpha.0

5 years ago

3.0.0

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.0

5 years ago

2.3.0

5 years ago

2.1.1

5 years ago

2.0.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-1

5 years ago

1.0.0-0

5 years ago

0.44.1

5 years ago

0.44.0

5 years ago

0.43.0

5 years ago

0.42.0

5 years ago

0.41.0

5 years ago

0.40.1

6 years ago

0.40.0

6 years ago

0.39.3

6 years ago

0.39.2

6 years ago

0.39.1

6 years ago

0.39.0

6 years ago

0.39.0-0

6 years ago

0.38.1

6 years ago

0.38.0

6 years ago

0.37.1

6 years ago

0.37.0

6 years ago

0.36.1

6 years ago

0.36.0

6 years ago

0.36.0-0

6 years ago

0.35.0

6 years ago

0.34.1

6 years ago

0.34.0

6 years ago

0.33.0

6 years ago

0.32.0

6 years ago

0.31.0

6 years ago

0.30.0

6 years ago

0.29.0

6 years ago

0.28.0

6 years ago

0.27.0

6 years ago

0.26.0

6 years ago

0.25.0

6 years ago

0.24.0

6 years ago

0.23.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

2.0.0-alpha.6-2

8 years ago