简体   繁体   English

如何使输入区域适合角度文字?

[英]How to fit input area to text in angular?

I'd like to have an input area to fit text that is inside of it. 我想要一个输入区域以适合其中的文本。

My code: 我的代码:

<mat-card>
  <fieldset>
    <legend>qwerty</legend>
    <div>
      <div>
        <label>Qwerty Asdf</label>
        <mat-form-field>
          <input matInput disabled="true" name="type" value="qwerty" />
        </mat-form-field>
      </div>
      <div>
        <label>Foo Bar</label>
        <mat-form-field>
          <input matInput disabled="false" name="type" value="baz" />
        </mat-form-field>
      </div>
      <div>
        <label>E Makarena</label>
        <mat-form-field>
          <input matInput disabled="false" name="type" value="asdsadsadsadsadsaadsad" />
        </mat-form-field>
      </div>
    </div>
  </fieldset>
</mat-card>

The result of above code is: 以上代码的结果是:

I tried setting width of input to auto or 100% or fit-content but that doesn't change a thing. 我尝试将输入宽度设置为auto100%fit-content但这并没有改变。

Try directive matTextareaAutosize mentioned in https://material.angular.io/components/input/api 尝试在https://material.angular.io/components/input/api中提到的指令matTextareaAutosize

That should be exaxtly what you are looking for. 那应该是您要找的东西。

It can not be done using CSS alone, because CSS is not aware of user typing. 不能仅使用CSS来完成此操作,因为CSS无法识别用户的输入。 It has to be done via Javascript. 必须通过Javascript完成。

If you are only interested in "increasing the width" of input field by pure CSS, then you can do it like this: 如果您只对纯CSS的“增加输入字段的宽度”感兴趣,则可以这样做:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM