10

enter image description hereExample

<form clrForm>
    <clr-input-container>
        <label>Field 1 label</label>
        <input clrInput type="text" [(ngModel)]="model" name="example" style="width:100%" />
    </clr-input-container>
    <clr-input-container>
        <label>Field 2 label</label>
        <input clrInput type="text" [(ngModel)]="model" name="example" style="width:100%" />
    </clr-input-container>
</form>

above is the code sample from clarity form, where I am using angular component for the form, the thing is when I Use form without angular component the input width takes 100% when I give style="100%" but same thing if i use with angular component the input field is not taking to 100% though I give style="100%". Please let me know the reason how can I make width to 100% when using angular component for the clarity form.

vinay k hegde
  • 243
  • 4
  • 18
  • The `max-widths` on form inputs was a design decision, leaving input widths to be 100% will make for very wide inputs in desktop forms. The inputs are designed to default to the defined size of the browser while still keeping room for the error icon. – hippeelee Aug 28 '18 at 23:40
  • Also, fyi - the reason it does not work with the *angular component* is because the styles are encapsulated into the components view and do not affect the rest of the application. There is a deprecated technique you can use to override a componants style. Read more here: https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep – hippeelee Aug 28 '18 at 23:49
  • But it seems its not looking good. Is there any way I can – vinay k hegde Aug 29 '18 at 11:54
  • Sorry, I don’t understand that last comment. What’s your question again? – hippeelee Aug 29 '18 at 13:23
  • I mean the entire form layout doesn't look good if its not 100% width, the whole page looks empty. example the image above currently this is how it looks.. – vinay k hegde Aug 30 '18 at 04:56
  • 1
    `Looks good to you or me` is subjective. IMO 100% width seems like it would take up to much space. As I said earlier the max-width was a design decision based on the UX research that went into the new forms design. I understand that you don’t like the decision that was made - there is nothing stopping you from overriding the css as you see fit for your app. – hippeelee Aug 30 '18 at 05:04

6 Answers6

4

We patched around it with a size attribute for input fields like this:

<input clrInput type="text" [(ngModel)]="..." name="title" required size="40" />

But this can't be done for other controls.

Nightmare
  • 41
  • 4
2

Something like this gave me 100% width for the <input> in a form.

SCSS:

.clr-form-control {
   align-items: unset;
}
.clr-input{
   width: 100%;
}

HTML:

<form class="clr-form">
  <clr-input-container>
    <input clrInput [(ngModel)]="field"/>
  </clr-input-container>
</form>
PhatBuck
  • 326
  • 5
  • 15
2

This is what I did with my forms to make the input controls fill up the 100% width:

Horizontal Layout:

enter image description here

Vertical Layout:

enter image description here

<form clrForm class="form-flex">...</form>
.form-flex {
  width: 100%;

  .clr-control-container {
    display: block;
    width: 100%;

    // Override to make select full width
    .clr-select-wrapper,
    .clr-select {
      width: 100%;
    }

    // Override to make search full width
    .hf-search-wrapper > .hf-search,
    .hf-search-select-input,
    .hf-search-input-text-container {
      width: 100%;
    }

    // Override to make input full width
    .clr-input-wrapper > .clr-input {
      width: 100%;
    }

    // Override to make password full width
    .clr-input-wrapper {
      width: 100%;

      & > .clr-input-group {
        max-width: 100%;
        width: 100%;
        padding-right: 0.4rem;

        & > input {
          width: calc(100% - 1rem);
        }
      }
    }
  }
}

In forms,

<clr-input-container>
                        <label class="clr-col-xs-12 clr-col-md-4 clr-col-lg-4"
                            >Employee Code/ID</label
                        >
                        <input
                            hfFocusInput="true"
                            class="clr-col-xs-12 clr-col-md-8 clr-col-lg-8"
                            clrInput
                            type="text"
                            formControlName="code"
                            name="code"
                        />
                        <clr-control-helper>Enter a unique Code.</clr-control-helper>
                        <clr-control-error *clrIfError="'required'"
                            >You must provide a Code!</clr-control-error
                        >
                    </clr-input-container>
Wendell
  • 170
  • 1
  • 8
0

Something like this should cover most inputs types? Select might need some fine tuning

.clr-form.is-fullwidth {
    width: 100%;

    .clr-control-container, .clr-input {
        width: 100%;
    }
}
0

This work for me ;-)

<div class="form-outer">

  <form clrForm
    clrLayout="horizontal"
    [formGroup]="exampleForm"
    class="clr-form-compact"
    *ngIf="exampleForm">

      <clr-input-container>
          <label>Field 1 label</label>
          <input clrInput type="text" formControlName="sample" />
          <clr-control-helper>Helper text that shows while it is pristine and valid</clr-control-helper>
          <clr-control-error>Error message that appears after focus is lost and control is invalid</clr-control-error>
      </clr-input-container>

  </form>

</div>

Ad my .scss

.form-outer {
    input.clr-input {
        width: 100% ;
    }
}
jspassov
  • 791
  • 7
  • 11
-1

100% on a full width form is ugly, I'll grant you that. However, let's take the login component / form and convert it to using the angular form

<div class="login-wrapper">
    <form class="login" clrForm>

        <section class="title">
            <h3 class="welcome">Welcome to</h3>
            MyApp
        </section>

        <div class="login-group">

            <clr-input-container>
                <input clrInput class="username" type="text" id="username" name="username" placeholder="Username" [(ngModel)]="username">
            </clr-input-container>
            <clr-password-container>
                <input clrPassword id="password" name="password" [(ngModel)]="password" />
            </clr-password-container>

            <div class="checkbox">
                <input type="checkbox" id="rememberme">
                <label for="rememberme">
                    Remember me
                </label>
            </div>

            <button type="submit" class="btn btn-primary">SIGN IN</button>

        </div>
    </form>
</div>

this gives this ugly form

enter image description here

So how would you style this ? I have tried adding

.clr-control-container {
    width: 100% !important;
}

to the login component scss, but it doesn't work

jmls
  • 2,879
  • 4
  • 34
  • 58