当前位置:网站首页>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';
}
}
}
边栏推荐
- Introduction to rust Foundation (basic type)
- EMD distance - example of use
- How to use source insight
- (subplots用法)matplotlib如何绘制多个子图(轴域)
- Robot capture experiment demonstration video
- appium1.22.x 版本后的 appium inspector 需单独安装
- Training method of grasping angle in grasping detection
- Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +
- About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
- 在PyCharm中配置使用Anaconda环境
猜你喜欢

Overview of basic knowledge of C language

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

Map的扩容机制

Technical analysis of qianyuantong multi card aggregation router

Redis使用Lua脚本简介

Principles of BTC cryptography

JS scope

2022.DAY592

Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)

XML配置文件
随机推荐
Redis 入門和數據類型講解
Altaro set grandfather parent child (GFS) archiving
Redis使用Lua脚本简介
Common methods of JS array
XML Configuration File
Go practice -- use redis in golang (redis and go redis / redis)
XML配置文件
SimpleITK学习笔记
JS string and array methods
Yolov5 input (II) | CSDN creative punch in
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Webapidom get page elements
Talk about how to use p6spy for SQL monitoring
Redis expiration elimination mechanism
Pan details of deep learning
Export the altaro event log to a text file
Disassembly and installation of Lenovo r7000 graphics card
Configure and use Anaconda environment in pycharm
【无标题】
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit