当前位置:网站首页>NG Textarea-auto-resize
NG Textarea-auto-resize
2022-07-03 05:29:00 【SeriousLose】
<textarea (ngModelChange)="onChange()" [(ngModel)]="val" (focus)="onChange()" (blur)="onChange()" #text class="autosize" maxlength={
{maxlength}} rows="1" placeholder={
{placeholder}}></textarea>
<!--text1为影子textarea 用于获取scrollHeight,并将值付给主textarea的height 实现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; // 最大高度 默认 100
@Input('maxlength') maxlength = 500; // 最大字数 默认500
@Input('placeholder') placeholder: any; // placeholder 提示语
@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: 改变textarea的高度
* @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';
}
}
}
边栏推荐
- 獲取並監控遠程服務器日志
- Audio Focus Series: write a demo to understand audio focus and audiomananger
- How to install and configure altaro VM backup for VMware vSphere
- Make your own dataset
- Get and monitor remote server logs
- Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
- study hard and make progress every day
- ninja: build stopped: subcommand failed.
- Classification and discussion of plane grab detection methods based on learning
- Based on RFC 3986 (unified resource descriptor (URI): general syntax)
猜你喜欢

appium1.22.x 版本後的 appium inspector 需單獨安裝

Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)

How to connect the network: Chapter 1 CSDN creation punch in

Burp suite plug-in based on actual combat uses tips
![[set theory] relational closure (relational closure related theorem)](/img/6a/b6dca7abf592f8d8ab1d6aecc43381.jpg)
[set theory] relational closure (relational closure related theorem)

Map的扩容机制

Simpleitk learning notes

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn

(完美解决)matplotlib图例(legend)如何自由设置其位置

求质数的方法
随机推荐
Altaro set grandfather parent child (GFS) archiving
Detailed explanation of yolov5 training own data set
How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
ES 2022 正式发布!有哪些新特性?
Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
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
Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
Web APIs exclusivity
XML Configuration File
[basic grammar] C language uses for loop to print Pentagram
Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
Classification and discussion of plane grab detection methods based on learning
Pan details of deep learning
酒店公共广播背景音乐-基于互联网+的酒店IP网络广播系统设计
2022.6.30DAY591
(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
Overview of basic knowledge of C language
Installing altaro VM backup
Learn libcef together -- set cookies for your browser
Common methods of JS array