88 Injector ,
99 Input ,
1010 Output ,
11- ViewChild
11+ ViewChild ,
12+ OnInit ,
13+ AfterViewInit
1214} from '@angular/core' ;
1315import { ControlValueAccessor , NG_VALUE_ACCESSOR } from "@angular/forms" ;
1416import { AbstractJigsawComponent , IJigsawFormControl } from "../../common/common" ;
@@ -28,15 +30,18 @@ import {RequireMarkForCheck} from "../../common/decorator/mark-for-check";
2830 '[style.height]' : 'height' ,
2931 '[class.jigsaw-textarea]' : 'true' ,
3032 '[class.jigsaw-textarea-error]' : '!valid' ,
31- '[class.jigsaw-textarea-disabled]' : 'disabled'
33+ '[class.jigsaw-textarea-disabled]' : 'disabled' ,
34+ '[class.jigsaw-textarea-resize-vertical]' :'resize === "vertical"' ,
35+ '[class.jigsaw-textarea-resize-horizontal]' :'resize === "horizontal"' ,
36+ '[class.jigsaw-textarea-resize-both]' :'resize === "both"' ,
3237 } ,
3338 providers : [
3439 { provide : NG_VALUE_ACCESSOR , useExisting : forwardRef ( ( ) => JigsawTextarea ) , multi : true } ,
3540 ] ,
3641 changeDetection : ChangeDetectionStrategy . OnPush
3742} )
3843
39- export class JigsawTextarea extends AbstractJigsawComponent implements IJigsawFormControl , ControlValueAccessor {
44+ export class JigsawTextarea extends AbstractJigsawComponent implements IJigsawFormControl , ControlValueAccessor , AfterViewInit {
4045 /**
4146 * 在文本框里的文本非空时,是否显示快速清除按钮,默认为显示。用户单击了清除按钮时,文本框里的文本立即被清空。
4247 *
@@ -55,6 +60,26 @@ export class JigsawTextarea extends AbstractJigsawComponent implements IJigsawFo
5560 @RequireMarkForCheck ( )
5661 public disabled : boolean = false ;
5762
63+
64+ private _resize : "both" | "horizontal" | "vertical" | "none" = "none" ;
65+ /**
66+ * 设置文本输入框是否可以拉伸
67+ *
68+ * @NoMarkForCheckRequired
69+ *
70+ * $demo = textarea/resize
71+ */
72+ @Input ( )
73+ public get resize ( ) : "both" | "horizontal" | "vertical" | "none" {
74+ return this . _resize ;
75+ }
76+
77+ public set resize ( value : "both" | "horizontal" | "vertical" | "none" ) {
78+ if ( CommonUtils . isDefined ( value ) ) {
79+ this . _resize = value ;
80+ }
81+ }
82+
5883 /**
5984 * 当用户输入非法时,组件给予样式上的提示,以提升易用性,常常和表单配合使用。
6085 *
@@ -304,4 +329,21 @@ export class JigsawTextarea extends AbstractJigsawComponent implements IJigsawFo
304329 this . _focused = false ;
305330 this . blur . emit ( event ) ;
306331 }
332+
333+ ngAfterViewInit ( ) {
334+ if ( this . resize === "vertical" || this . resize === "both" ) {
335+ if ( / .+ ( p x | v h ) \s * $ / i. test ( this . height ) ) {
336+ this . _textareaElement . nativeElement . style . height = this . height ;
337+ } else {
338+ console . warn ( "Resizeable JigsawTextarea only accepts height in 'px' and 'vh' format." )
339+ }
340+ }
341+ if ( this . resize === "horizontal" || this . resize === "both" ) {
342+ if ( / .+ ( p x | v w ) \s * $ / i. test ( this . width ) ) {
343+ this . _textareaElement . nativeElement . style . width = this . width ;
344+ } else {
345+ console . warn ( "Resizeable JigsawTextarea only accepts width in 'px' and 'vh' format." )
346+ }
347+ }
348+ }
307349}
0 commit comments