File tree Expand file tree Collapse file tree
src/components/blipTextarea Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const BLIP_TEXTAREA_PREFIX = 'blip-textarea-';
1717class BlipTextareaController extends ComponentController {
1818 elementId : string ;
1919 rows : string ;
20+ autoResize : boolean ;
2021 onChange : ( $val ) => { } ;
2122
2223 constructor ( private $element ) {
@@ -25,7 +26,11 @@ class BlipTextareaController extends ComponentController {
2526 }
2627
2728 $onInit ( ) {
28- this . rows = this . rows ? this . rows : '2' ;
29+ this . rows = this . rows ? this . rows : '1' ;
30+
31+ if ( this . autoResize ) {
32+ this . listenTextareaKeydown ( ) ;
33+ }
2934 }
3035
3136 focus ( ) {
@@ -34,6 +39,21 @@ class BlipTextareaController extends ComponentController {
3439 ) as HTMLTextAreaElement ;
3540 textarea . focus ( ) ;
3641 }
42+
43+ listenTextareaKeydown ( ) {
44+ let textarea = this . $element [ 0 ] . querySelector (
45+ 'textarea' ,
46+ ) as HTMLTextAreaElement ;
47+
48+ textarea . addEventListener ( 'keydown' , function ( ) {
49+ let element = this ;
50+
51+ setTimeout ( function ( ) {
52+ element . style . cssText = 'height:auto; padding:0' ;
53+ element . style . cssText = 'height:' + element . scrollHeight + 'px' ;
54+ } , 0 ) ;
55+ } ) ;
56+ }
3757}
3858
3959export const BlipTextareaComponent = angular
@@ -52,6 +72,7 @@ export const BlipTextareaComponent = angular
5272 maxlength : '@?' ,
5373 parentForm : '=?' ,
5474 onChange : '&?' ,
75+ autoResize : '<?'
5576 } ,
5677 require : {
5778 ngModel : 'ngModel' ,
Original file line number Diff line number Diff line change 1- < div class ="bp-textarea-wrapper " ng-class ="{
1+ < div class ="bp-textarea-wrapper bp2-textarea-wrapper " ng-class ="{
2+ 'bp2-textarea-wrapper--show': !$ctrl.disabled,
23 'bp-textarea-wrapper--focus': focused,
34 'bp-textarea-wrapper--disabled': $ctrl.disabled,
45 'bp-textarea-wrapper--invalid': !$ctrl.disabled && !$ctrl.parentForm[$ctrl.fieldName].$pristine && $ctrl.parentForm[$ctrl.fieldName].$invalid } "
56 ng-click ="$ctrl.focus() " id ="{{$ctrl.elementId}} ">
6- < label class ="bp-label tl " ng-class ="{
7+ < label class ="bp-label bp2-textarea__label tl " ng-class ="{
78 'bp-c-rooftop': !focused,
89 'bp-c-blip-dark': focused,
910 'bp-c-warning': !$ctrl.parentForm[$ctrl.fieldName].$pristine && $ctrl.parentForm[$ctrl.fieldName].$invalid } "> {{$ctrl.label}}</ label >
1011 < textarea class ="bp-textarea bp-c-city " ng-model ="$ctrl.model " name ="{{$ctrl.fieldName}} " placeholder ="{{$ctrl.placeholder}} "
1112 ng-required ="$ctrl.required " maxlength ="{{$ctrl.maxlength}} " ng-disabled ="$ctrl.disabled " ng-init ="focused=false "
12- ng-change ="$ctrl.onChange({ $val: $ctrl.model }) " ng-focus =" focused=true " ng-blur ="focused=false " rows ="{{$ctrl.rows}} "> </ textarea >
13+ ng-change ="$ctrl.onChange({ $val: $ctrl.model }) " ng-focus =" focused=true " ng-blur ="focused=false " rows ="{{$ctrl.rows}} "
14+ ng-class ="{
15+ 'bp-textarea-auto-resize': $ctrl.autoResize } "> </ textarea >
1316</ div >
You can’t perform that action at this time.
0 commit comments