当前位置:网站首页>NG Textarea-auto-resize
NG Textarea-auto-resize
2022-07-03 05:33:00 【SeriousLose】
<textarea (ngModelChange)="onChange()" [(ngModel)]="val" (focus)="onChange()" (blur)="onChange()" #text class="autosize" maxlength={
{maxlength}} rows="1" placeholder={
{placeholder}}></textarea>
<!--text1 For the shadow textarea Used to get scrollHeight, And pay the value to the owner textarea Of height Realization auto resize -->
<textarea class="autosize hidden" rows="1" [value]="val" #text1 ></textarea>
:host {
display: flex;
justify-content: flex-start;
.autosize {
vertical-align: top;
padding: 7px 8px;
font-size: 12px;
width: 200px;
border-radius: 3px;
line-height: 14px;
position: relative;
outline: none;
resize: none;
box-sizing: border-box;
height: 32px;
transition: height 0.2s;
}
.hidden {
position: absolute;
left: -100px;
visibility: hidden;
overflow: hidden;
}
}
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, OnInit, Output, Renderer2, ViewChild } from '@angular/core';
@Component({
selector: 'textarea-auto-resize',
templateUrl: './textarea-auto-resize.component.html',
styleUrls: ['./textarea-auto-resize.component.less'],
})
export class TextareaAutoResizeComponent implements OnInit, AfterViewInit {
@Input('max-height') maxHeight = 100; // Maximum height Default 100
@Input('maxlength') maxlength = 500; // The maximum number of words Default 500
@Input('placeholder') placeholder: any; // placeholder Hint
@Input('g') g: any;
@Input('el') el: any;
@Output('valChange') valChange = new EventEmitter();
@ViewChild('text') text: ElementRef;
@ViewChild('text1') text1: ElementRef;
@Input('value') val = '';
constructor(private rd2: Renderer2) {}
ngOnInit() {}
ngAfterViewInit() {
this.reset();
}
onChange() {
this.reset();
setTimeout(() => {
this.valChange.emit({
value: this.val,
g: this.g,
el: this.el,
});
this.reset();
}, 0);
}
/**
* @description: change textarea Height
* @param {type}
* @return:
*/
reset() {
this.text1.nativeElement.style.width = this.text.nativeElement.scrollWidth + 2 + 'px';
if (this.text1.nativeElement.scrollHeight < this.maxHeight) {
this.text1.nativeElement.style.width = this.text.nativeElement.scrollWidth + 19 + 'px';
this.text.nativeElement.style.height = this.text1.nativeElement.scrollHeight + 2 + 'px';
} else {
this.text.nativeElement.style.height = this.maxHeight - 0 + 2 + 'px';
}
}
}
边栏推荐
- Win10 install pytullet and test
- Altaro set grandfather parent child (GFS) archiving
- 求质数的方法
- How do I migrate my altaro VM backup configuration to another machine?
- Yolov5 model construction source code details | CSDN creation punch in
- Common methods of JS array
- Overview of basic knowledge of C language
- Redis 入门和数据类型讲解
- ES7 easy mistakes in index creation
- Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
猜你喜欢

Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +

Detailed explanation of yolov5 training own data set

How do I migrate my altaro VM backup configuration to another machine?

XML Configuration File

Principles of BTC cryptography

Go practice - gorilla / handlers used by gorilla web Toolkit

XML配置文件

Map的扩容机制

乾元通多卡聚合路由器的技术解析

ES7 easy mistakes in index creation
随机推荐
大二困局(复盘)
Introduction to webrtc protocol -- an article to understand dtls, SRTP, srtcp
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
Obtenir et surveiller les journaux du serveur distant
@Autowired 导致空指针报错 解决方式
[practical project] autonomous web server
appium1.22.x 版本后的 appium inspector 需单独安装
redis 遇到 NOAUTH Authentication required
Yolov5 network structure + code + application details | CSDN creation punch in
appium1.22.x 版本後的 appium inspector 需單獨安裝
SimpleITK学习笔记
Altaro set grandfather parent child (GFS) archiving
[basic grammar] Snake game written in C language
Making coco datasets
Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
期末复习(DAY7)
JS scope
Botu uses peek and poke for IO mapping