Skip to content

Commit bc11417

Browse files
author
Arthur Soares
authored
Merge pull request #33 from takenet/feature/152307_text-area-component
Ajusts for new text area component
2 parents b33a244 + c364969 commit bc11417

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/components/blipTextarea/blipTextarea.component.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const BLIP_TEXTAREA_PREFIX = 'blip-textarea-';
1717
class 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

3959
export 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',
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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>

0 commit comments

Comments
 (0)