-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed height calculations when using padding #24
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,16 @@ import { Observable, Subscription } from 'rxjs/Rx'; | |
export class ElasticDirective implements OnInit, OnDestroy, AfterViewInit { | ||
private modelSub: Subscription; | ||
private textareaEl: HTMLTextAreaElement; | ||
private totalVerticalPadding = 0; | ||
|
||
constructor( | ||
private element: ElementRef, | ||
private ngZone: NgZone, | ||
@Optional() private model: NgModel | ||
) {} | ||
) { } | ||
|
||
ngOnInit() { | ||
if(!this.model) { | ||
if (!this.model) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
return; | ||
} | ||
|
||
|
@@ -30,7 +31,7 @@ export class ElasticDirective implements OnInit, OnDestroy, AfterViewInit { | |
} | ||
|
||
ngOnDestroy() { | ||
if(this.modelSub) { | ||
if (this.modelSub) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above |
||
this.modelSub.unsubscribe(); | ||
} | ||
} | ||
|
@@ -64,6 +65,10 @@ export class ElasticDirective implements OnInit, OnDestroy, AfterViewInit { | |
private setupTextarea(textareaEl: HTMLTextAreaElement) { | ||
this.textareaEl = textareaEl; | ||
|
||
const paddingTop = window.getComputedStyle(this.textareaEl).getPropertyValue('padding-top').replace('px', ''); | ||
const paddingBottom = window.getComputedStyle(this.textareaEl).getPropertyValue('padding-bottom').replace('px', ''); | ||
this.totalVerticalPadding = +paddingTop + +paddingBottom; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to make a few changes here.
|
||
// Set some necessary styles | ||
const style = this.textareaEl.style; | ||
style.overflow = 'hidden'; | ||
|
@@ -87,6 +92,6 @@ export class ElasticDirective implements OnInit, OnDestroy, AfterViewInit { | |
} | ||
|
||
this.textareaEl.style.height = 'auto'; | ||
this.textareaEl.style.height = this.textareaEl.scrollHeight + "px"; | ||
this.textareaEl.style.height = this.textareaEl.scrollHeight - this.totalVerticalPadding + "px"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The most recent commit uses a backtick string so let's do the same here. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you recommit without the extra whitespace?