forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input): incorrect height with autosize (angular#4084)
Currently when using the `mdTextareaAutosize` directive the textarea height might be incorrect on component initialization. This happens because the textarea `scrollHeight` property is not ready in the `ngOnInit` lifecycle hook yet. Other libraries like `angular-elastic` have timeouts for that. But using the `ngAfterViewInit` lifecycle hook is more elegant and also ensures that the `scrollHeight` property is ready. Also switches `offsetHeight` to `clientHeight` since we don't want to include the border in our line-height calculations. Also by default `textarea` elements have a padding of `2px` and the `padding` needs to be explicitly set to `0px` when resolving the line-height. Fixes angular#4070.
- Loading branch information
1 parent
21f8899
commit 5c640d0
Showing
27 changed files
with
183 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
Directive, | ||
HostBinding, | ||
Output, | ||
Input, | ||
EventEmitter | ||
} from '@angular/core'; | ||
|
||
import {Direction, Directionality} from './directionality'; | ||
|
||
/** | ||
* Directive to listen for changes of direction of part of the DOM. | ||
* | ||
* Would provide itself in case a component looks for the Directionality service | ||
*/ | ||
@Directive({ | ||
selector: '[dir]', | ||
// TODO(hansl): maybe `$implicit` isn't the best option here, but for now that's the best we got. | ||
exportAs: '$implicit', | ||
providers: [ | ||
{provide: Directionality, useExisting: Dir} | ||
] | ||
}) | ||
export class Dir implements Directionality { | ||
/** Layout direction of the element. */ | ||
@Input('dir') _dir: Direction = 'ltr'; | ||
|
||
/** Event emitted when the direction changes. */ | ||
@Output() change = new EventEmitter<void>(); | ||
|
||
/** @docs-private */ | ||
@HostBinding('attr.dir') | ||
get dir(): Direction { | ||
return this._dir; | ||
} | ||
|
||
set dir(v: Direction) { | ||
let old = this._dir; | ||
this._dir = v; | ||
if (old != this._dir) { | ||
this.change.emit(); | ||
} | ||
} | ||
|
||
/** Current layout direction of the element. */ | ||
get value(): Direction { return this.dir; } | ||
set value(v: Direction) { this.dir = v; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
EventEmitter, | ||
Injectable, | ||
Optional, | ||
SkipSelf | ||
} from '@angular/core'; | ||
|
||
export type Direction = 'ltr' | 'rtl'; | ||
|
||
/** | ||
* The directionality (LTR / RTL) context for the application (or a subtree of it). | ||
* Exposes the current direction and a stream of direction changes. | ||
*/ | ||
@Injectable() | ||
export class Directionality { | ||
value: Direction = 'ltr'; | ||
change: EventEmitter<void> = new EventEmitter<void>(); | ||
|
||
constructor() { | ||
if (document) { | ||
// TODO: handle auto value - | ||
// We still need to account for dir="auto". | ||
// It looks like HTMLElemenet.dir is also "auto" when that's set to the attribute, | ||
// but getComputedStyle return either "ltr" or "rtl". avoiding getComputedStyle for now | ||
// though, we're already calling it for the theming check. | ||
this.value = | ||
(document.body.getAttribute('dir') || | ||
document.documentElement.getAttribute('dir') || | ||
'ltr') as Direction; | ||
} | ||
} | ||
} | ||
|
||
export const DIRECTIONALITY_PROVIDER = { | ||
// If there is already a Directionality available, use that. Otherwise, provide a new one. | ||
provide: Directionality, | ||
deps: [[new Optional(), new SkipSelf(), Directionality]], | ||
useFactory: function (parentDirectionality) { | ||
return parentDirectionality || new Directionality(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {ModuleWithProviders, NgModule} from '@angular/core'; | ||
import {Dir} from './dir'; | ||
import {Directionality, DIRECTIONALITY_PROVIDER} from './directionality'; | ||
|
||
export { | ||
Directionality, | ||
DIRECTIONALITY_PROVIDER, | ||
Direction | ||
} from './directionality'; | ||
export {Dir} from './dir'; | ||
|
||
|
||
@NgModule({ | ||
exports: [Dir], | ||
declarations: [Dir], | ||
providers: [Directionality] | ||
}) | ||
export class BidiModule { | ||
/** @deprecated */ | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: BidiModule, | ||
providers: [DIRECTIONALITY_PROVIDER] | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.