当前位置:网站首页>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';
}
}
}
边栏推荐
- Azure file synchronization of altaro: the end of traditional file servers?
- 谷歌 | 蛋白序列的深度嵌入和比对
- ROS Compilation Principle
- Classification and discussion of plane grab detection methods based on learning
- Xaml gradient issue in uwp for some devices
- Go practice -- gorilla / websocket used by gorilla web Toolkit
- Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
- Installing altaro VM backup
- 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
- Why is go language particularly popular in China
猜你喜欢

College campus IP network broadcasting - manufacturer's design guide for college campus IP broadcasting scheme based on campus LAN

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

Intégration profonde et alignement des séquences de protéines Google

@Autowired 导致空指针报错 解决方式

"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()

Audio Focus Series: write a demo to understand audio focus and audiomananger

Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN

appium1.22.x 版本后的 appium inspector 需单独安装

3dslam with 16 line lidar and octomap

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
随机推荐
Classification and discussion of plane grab detection methods based on learning
Common methods of JS array
study hard and make progress every day
Go language interface learning notes
Interview question -- output the same characters in two character arrays
Installing altaro VM backup
AtCoder Beginner Contest 258(A-D)
【实战项目】自主web服务器
[practical project] autonomous web server
appium1.22.x 版本後的 appium inspector 需單獨安裝
XML配置文件
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
Botu uses peek and poke for IO mapping
(perfect solution) how to set the position of Matplotlib legend freely
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
获取并监控远程服务器日志
Pessimistic lock and optimistic lock of multithreading
Redis Introduction et explication des types de données
牛客网 JS 分隔符
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)