Components: form-field: remove extra bottom space

Created on 23 Oct 2017  路  15Comments  路  Source: angular/components

Bug, feature request, or proposal:

Add a way to remove the extra bottom space when there's no hint or error possible.

What is the current behavior?

https://stackblitz.com/edit/angular-material2-issue-pq4ikd

Which version of Material is affected?

2.0.0-beta.12

P5 feature needs discussion

Most helpful comment

10px is not enough considering size of padding.

<mat-form-field style=" margin-bottom: -1.25em">

I agree that spacings should be consistent in a form context, but on other contexts (like a search on a toolbar or in the header of a page) this spacing breaks layout gap consistency.

The user should be allowed to configure the mat-form-field component to never need this bottom spacing and remove it.

This could interfere with https://github.com/angular/material2/issues/3984

All 15 comments

This is working by design.

We want to create a consistent space whether padding or not for alignment reasons.

Okay, now with this example : https://stackblitz.com/edit/angular-material2-issue-hyhhxo
Basically: an search input with result in a list. There's way too much space between the list and the input.

It's easy to remove the padding-top of the md-list, but it's not enough, and removing the extra bottom space of form-field is not a simple padding-bottom: 0px;. It should be easier to remove this extra space when it doesn't make sense.

Or this use case should be handled with a new custom search component (https://material.io/guidelines/patterns/search.html) ?
(But I can find more use case when the extra space doesn't make sense)

Try removing mat-form-field wrapper.. It's seems to do the job

Yeah... https://stackblitz.com/edit/angular-material2-issue-xrdzn6
It just kill matInput and render a regular input which doesn't have the extra bottom space of course..

I think that there is a decent case for implementing a component or directive to render an input in line with the search pattern guidelines as mentioned by @Wykks

Closing this since this is intentional and we have no plans to change it

Workaround when e.g. adding a search field to a toolbar and you don't want the space below is to set a negative margin:

<mat-form-field style=" margin-bottom: -10px">

10px is not enough considering size of padding.

<mat-form-field style=" margin-bottom: -1.25em">

I agree that spacings should be consistent in a form context, but on other contexts (like a search on a toolbar or in the header of a page) this spacing breaks layout gap consistency.

The user should be allowed to configure the mat-form-field component to never need this bottom spacing and remove it.

This could interfere with https://github.com/angular/material2/issues/3984

So I want consistent spacing. That is precisely why I am here.

That is probably why everybody is here too. This is all I want to achieve, but for a mat-select to get an underline it needs to be inside a form field which adds extra spacing:

  • Checkbox 1
  • Checkbox 2 __mat-select__
  • Checkbox 3

If anyone can suggest a way to achieve the above layout 'legally' I'd love to hear it. In the meantime this is how I managed it. Same idea as @sambaptista but had to tweak the top margin too to get the select to align with the checkbox text.

(I'm using angular-flex layout too):

<div fxLayout="column" fxLayoutGap=".5em">

    <mat-checkbox >First option</mat-checkbox>

    <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="1em">

        <mat-checkbox (checked)="false">Second option</mat-checkbox>    

        <mat-form-field [style.marginBottom]="'-1.25em'" 
                                   [style.marginTop]="'-1em'">
            <mat-select [(value)]="subOption">
                <mat-option *ngFor="let option of subOptions" [value]="option.value">{{ option.desc }}</mat-option>
            </mat-select>
        </mat-form-field>   

    </div>

    <mat-checkbox>Third option</mat-checkbox>

</div>

But the reason this won't be supported natively is 'because we want consistent spacing'. My head is spinning.

Ran into same issue, we are using mat-select inside mat-table inside modal window. When table is as big as modal it should become scrollable, but because of the spacing in mat-form-field it makes table always scrollable. Although workaround suggest by @simeyla works in our case too.

This would be great to have a _built-in_ solution for more flexibility over the automatically generated <div class="mat-form-field-wrapper">, like an @Input() noPadding: boolean on <mat-form-field> for example, to specify whether or not we want that extra space.

Yes there are workarounds but we'll always have to handle it on our side ...

My current workaround consists of a CSS utility class that I created to apply on <mat-form-field> that negates the bottom padding on .mat-form-field-wrapper :

css

.mat-form-field.no-padding > .mat-form-field-wrapper {
  margin-bottom: -1.25em;
}

html

<mat-form-field class="no-padding">

The problem with that workaround is that @angular/material2 team could change the padding-bottom value and breaks the layout without you noticing.

So if you're using Angular-Flex and define a nice gap in a column for consistence spacing you're lost...
The mentioned workaround with negative margin (thats quite ugly imho) doesn't work with fxLayoutGap because this directive defines a margin right on the element.

I use the below workaround to handle this till there is a better in-built solution:

.mat-form-field { .mat-form-field-wrapper { padding-bottom: 0; } .mat-form-field-underline { bottom: 0; } }
This way I don't need to worry about @angular/material2 team changing the padding-bottom value.

If you just to hide the underline, then you can use below CSS:
.mat-form-field { .mat-form-field-wrapper { padding-bottom: 0; } .mat-form-field-underline { display: none; } }

That kind of thing makes me think of leaving angular material behind. So much struggle for something that should be so simple.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3mp3ri0r picture 3mp3ri0r  路  3Comments

dzrust picture dzrust  路  3Comments

LoganDupont picture LoganDupont  路  3Comments

vitaly-t picture vitaly-t  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments