Skip to content

fix(tabs): server-side rendering error when aligning ink bar #5455

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

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions src/lib/tabs/ink-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ export class MdInkBar {
alignToElement(element: HTMLElement) {
this.show();

this._ngZone.runOutsideAngular(() => {
requestAnimationFrame(() => {
this._renderer.setStyle(this._elementRef.nativeElement, 'left',
this._getLeftPosition(element));
this._renderer.setStyle(this._elementRef.nativeElement, 'width',
this._getElementWidth(element));
if (typeof requestAnimationFrame !== 'undefined') {
this._ngZone.runOutsideAngular(() => {
requestAnimationFrame(() => this._setStyles(element));
});
});
} else {
this._setStyles(element);
}
}

/** Shows the ink bar. */
Expand All @@ -54,18 +53,14 @@ export class MdInkBar {
}

/**
* Generates the pixel distance from the left based on the provided element in string format.
* Sets the proper styles to the ink bar element.
* @param element
*/
private _getLeftPosition(element: HTMLElement): string {
return element ? element.offsetLeft + 'px' : '0';
}
private _setStyles(element: HTMLElement) {
const left = element ? (element.offsetLeft || 0) + 'px' : '0';
const width = element ? (element.offsetWidth || 0) + 'px' : '0';

/**
* Generates the pixel width from the provided element in string format.
* @param element
*/
private _getElementWidth(element: HTMLElement): string {
return element ? element.offsetWidth + 'px' : '0';
this._renderer.setStyle(this._elementRef.nativeElement, 'left', left);
this._renderer.setStyle(this._elementRef.nativeElement, 'width', width);
}
}
38 changes: 18 additions & 20 deletions src/universal-app/kitchen-sink/kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ <h2>Button</h2>
<a md-fab href="https://google.com">Google</a>
<a md-mini-fab href="https://google.com">Google</a>

<!-- Button toggle doesn't work due to https://github.com/angular/angular/issues/17050 -->
<!--<h2>Button toggle</h2>-->

<!--<h3>Single selection</h3>-->
<!--<md-button-toggle-group>-->
<!--<md-button-toggle>Ketchup</md-button-toggle>-->
<!--<md-button-toggle>Mustard</md-button-toggle>-->
<!--<md-button-toggle>Mayo</md-button-toggle>-->
<!--</md-button-toggle-group>-->

<!--<h3>Multi selection</h3>-->
<!--<md-button-toggle-group multiple>-->
<!--<md-button-toggle>Ketchup</md-button-toggle>-->
<!--<md-button-toggle>Mustard</md-button-toggle>-->
<!--<md-button-toggle>Mayo</md-button-toggle>-->
<!--</md-button-toggle-group>-->
<h2>Button toggle</h2>

<h3>Single selection</h3>
<md-button-toggle-group>
<md-button-toggle>Ketchup</md-button-toggle>
<md-button-toggle>Mustard</md-button-toggle>
<md-button-toggle>Mayo</md-button-toggle>
</md-button-toggle-group>

<h3>Multi selection</h3>
<md-button-toggle-group multiple>
<md-button-toggle>Ketchup</md-button-toggle>
<md-button-toggle>Mustard</md-button-toggle>
<md-button-toggle>Mayo</md-button-toggle>
</md-button-toggle-group>

<h3>Standalone</h3>
<md-button-toggle>Hyperspinner enabled</md-button-toggle>
Expand All @@ -63,11 +62,10 @@ <h3>Card</h3>
</md-card-footer>
</md-card>

<!-- Checkbox doesn't work due to https://github.com/angular/angular/issues/17050 -->
<!--<h2>Checkbox</h2>-->
<h2>Checkbox</h2>

<!--<md-checkbox>With a label</md-checkbox>-->
<!--<md-checkbox></md-checkbox>Without a label-->
<md-checkbox>With a label</md-checkbox>
<md-checkbox></md-checkbox>Without a label

<h2>Chips</h2>

Expand Down