当前位置:网站首页>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';
}
}
}
边栏推荐
- Get and monitor remote server logs
- Interview question -- output the same characters in two character arrays
- [set theory] relational closure (relational closure related theorem)
- 期末复习(day3)
- Source insight automatic installation and licensing
- How to use source insight
- Talk about how to use p6spy for SQL monitoring
- Disassembly and installation of Lenovo r7000 graphics card
- 求质数的方法
- 期末复习(DAY7)
猜你喜欢
中职网络子网划分例题解析
XML Configuration File
Yolov5 model construction source code details | CSDN creation punch in
Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
Audio Focus Series: write a demo to understand audio focus and audiomananger
Progressive multi grasp detection using grasp path for rgbd images
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Introduction to deep learning (II) -- univariate linear regression
随机推荐
Get and monitor remote server logs
ES 2022 正式发布!有哪些新特性?
Pytorch through load_ state_ Dict load weight
XML Configuration File
Source insight operation manual installation trial
Redis 过期淘汰机制
请求数据库报错:“could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGram
Web APIs exclusivity
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
酒店公共广播背景音乐-基于互联网+的酒店IP网络广播系统设计
Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
Botu uses peek and poke for IO mapping
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
Audio Focus Series: write a demo to understand audio focus and audiomananger
期末复习(DAY7)
Transferring images using flask
JS function algorithm interview case
"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()
[basic grammar] Snake game written in C language