Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form-field): remove 200px width since it messes up flex layouts #7083

Merged
merged 2 commits into from
Oct 12, 2017

Conversation

mmalerba
Copy link
Contributor

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 14, 2017
@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Sep 14, 2017
@ChenReuven
Copy link

i think that this issue prevent upgrading to new angular material version cause the global look of the input in the application is break(high bug) and the WA for that is too high.

@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 1, 2017

@ChenReuven you can use a CSS override to put this back how it used to be until this PR makes it in:

/* class repeated for increased specificity */
.mat-form-field.mat-form-field {
  width: auto;
}

@ChenReuven
Copy link

@mmalerba Thanks Bro! i will try it :)

@mmalerba mmalerba added pr: needs cleanup / tests and removed action: merge The PR is ready for merge by the caretaker labels Oct 1, 2017
@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 1, 2017

seems to have some broken select tests, will investigate

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker and removed pr: needs cleanup / tests labels Oct 2, 2017
@kara kara added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged labels Oct 4, 2017
@kara
Copy link
Contributor

kara commented Oct 4, 2017

Note: need to update screenshot tests

@Upimage
Copy link

Upimage commented Oct 6, 2017

@mmalerba Thanks for the hint.
Using 'auto' results in longer rending calculations in FF & IE. Therefore, I prefer to use small values like .mat-form-field.mat-form-field { width: auto; } and 'fxFlex' in my HTML

@benb7760
Copy link

@mmalerba the temporary workaround you suggested affects the paginator. conflicts with 56px width in .mat-paginator-page-size-select. I've solved this temporarily with

mat-paginator .mat-form-field.mat-form-field {
  width: 56px;
}

@mmalerba mmalerba added the P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful label Oct 11, 2017
@andrewseguin andrewseguin merged commit 160a511 into angular:master Oct 12, 2017
@kamok
Copy link

kamok commented Oct 17, 2017

How do I get the changes made in this PR? I'm a bit confused about what it means by " andrewseguin merged commit 160a511 into angular:master". I checked npm for angular 2 material https://www.npmjs.com/package/@angular2-material/input, and the last update was 6 months ago.

Edit: I already made the CSS change of

mat-form-field {
  width: 100%;
}

on my project, but it's more of a GitHub question.

@skovalyov
Copy link

After this change horizontal forms with fxFlex are not looking as they supposed to. They do not shrink beyond their minimum width. For example, this snippet:

<div fxLayout="row" fxLayoutGap="10px">
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
  <mat-form-field fxFlex>
    <input matInput>
  </mat-form-field>
</div>

All form fields remain 180px in width due to mat-form-field-infix style.

@AppField
Copy link

AppField commented Dec 8, 2017

Sorry for taking out this thread.
I have some trouble with the 180px fixed width due to mat-form-field-infix
Is there a way to remove/override this width style?

@vadim82
Copy link

vadim82 commented Dec 8, 2017

We are also experiencing a problem with a fixed width of the mat-form-field-infix class. It is not letting us shrink the mat-select component.

@AppField
Copy link

AppField commented Dec 9, 2017

@vadim82
You mentioned the mat-select component.
So, did you get the normal mat-form-field with an input element shrinking?

@vadim82
Copy link

vadim82 commented Dec 9, 2017

The only thing I was able to do was to override that selector and set the min width to something smaller. It is a terrible solution, but I can't think of any other workaround.

        .flex-form-field { 
            .mat-form-field-infix { 
                width: auto !important;
                min-width: 74px !important;
            }
        }

@sophistyx
Copy link

Is there a fix for this yet? Without wrapping mat-select components in mat-form-field elements I lose placeholder functionality but wrapping them breaks my bootstrap/flex column widths as described above?

@mmalerba
Copy link
Contributor Author

I don't think there's a way to set these properties that's going to make it work perfectly for everyone out of the box. If you need to change the width just add some CSS:

.mat-form-field .mat-form-field-infix {
  width: auto;
}

You should not need to use !important, just use a rule with greater specificity than a single class

@AppField
Copy link

Maybe I am missing something, but I can't get it to set the width to auto.

I have created a Stackblitz for this:
Stackblitz mat-form-field-infix

@mmalerba
Copy link
Contributor Author

@Webfield that is because view encapsulation is enabled in the component you added the style to. There are a couple ways to fix it:

  1. Add the style to a global stylesheet rather than the component's styles
  2. Add encapsulation: ViewEncapsulation.None to your component's decorator to turn off view encapsulation.
  3. Use ::ng-deep .mat-form-fiel .mat-form-field-infix to pierce the encapsulation

Here's a fixed version of your stackblitz using option number 3: https://stackblitz.com/edit/angular-material-whdy24?file=app%2Fapp.component.css

@AppField
Copy link

AppField commented Dec 12, 2017

Thanks you so much!

Since the shadow piercings >>> have been deprecating, I've totally forgotten about the ViewEncapsulation

@philmday
Copy link

philmday commented Mar 16, 2018

Adding this to the global styles made the fxFlex attribute work for me

mat-form-field {
  min-width:auto !important;
  .mat-form-field-infix {
    width: auto;
  }
}

@mmalerba mmalerba deleted the input-width branch July 31, 2018 21:19
@Akitha
Copy link

Akitha commented Jan 8, 2019

Just Add this , it works for me
::ng-deep .mat-form-fiel .mat-form-field-infix

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.