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

mwc-button height is always fixed

Open ainvaltin opened this issue 7 years ago • 10 comments

mwc-button doesn't adjust it's height when it's content's height is bigger than the default, ie when using code like

<mwc-button><img src="image.png"/></mwc-button>

the width of the button will grow according to the width of the image but height stays fixed so that the bottom part of the image is cut off.

The paper-button of the Polymer 2 adjusted it's size so that the whole image is visible.

ainvaltin avatar Jul 24 '18 07:07 ainvaltin

We'll need to figure out if the material-components-web MDCButton is supposed to adjust its height with children.

dfreedm avatar Aug 06 '18 21:08 dfreedm

This was incredibly straightforward with paper-button - just add content.

https://material.io/design/components/buttons.html#anatomy shows an example of a button flowing to adjust to inline content.

A use case for adjusting height is for image buttons

bennypowers avatar Nov 05 '18 16:11 bennypowers

https://material.io/design/components/buttons.html#usage has only 4 types of buttons, non of them an image button.

elf-pavlik avatar Feb 26 '19 15:02 elf-pavlik

I tried this in the latest material-components-web, results below.

Image with mdc-button__icon class

Images inside buttons will be resized to fit (left side). Trying to force the height of the image with explicit styling (right side) causes undefined behavior.

image in button

Just an image tag as button content

Images inside buttons will expand the width of the button, but not the height (left). Forcing the height causes the same behavior (right).

images in button 2

straversi avatar Apr 01 '19 18:04 straversi

Image buttons are far from the only use case here

consider this grid:

Screen Shot 2019-12-18 at 12 52 00

in which the button is misaligned and shorter than the inputs.

The button has height controls in SASS. It should have in the browser as well.

bennypowers avatar Jan 02 '20 07:01 bennypowers

Note that the Shrine theme calls for customizing the button size. From the images, it looks like they're using 360px x 48px for contained buttons. We can't currently do this with MWC.

See "Contained buttons" in the Components section:

https://material.io/design/material-studies/shrine.html#components

arthurevans avatar Feb 11 '20 17:02 arthurevans

Even if the size isn't updated automatically, could there be a custom property exposed that controls the height? I just wrote the line this.shadowRoot.querySelector('.some-button').shadowRoot.querySelector('button').style.height = '60px'; and it didn't feel great :)

I can open this as a separate issue if it doesn't fit here.

notwaldorf avatar May 21 '20 01:05 notwaldorf

There will eventually be a way to change the height that is part of the density system that we're working on.

asyncliz avatar May 21 '20 02:05 asyncliz

I would also need this.

MarcSkovMadsen avatar Jul 31 '20 04:07 MarcSkovMadsen

I don't believe this is resolved yet, and this point wasn't raised: it would be nice to have control over both height and min-height. In the following screenshot I've done similar styling as @notwaldorf to fix the issue, and it didn't feel great for me as well:)

Screen Shot 2021-11-04 at 4 56 22 PM

andyvanee avatar Nov 04 '21 23:11 andyvanee

Height is now configurable in M3

asyncliz avatar Apr 24 '23 21:04 asyncliz