-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
bug(tabs): fix arrows not showing on reszize #6303 #6304
Conversation
src/lib/tabs/tab-header.ts
Outdated
@@ -387,6 +388,7 @@ export class MdTabHeader extends _MdTabHeaderMixinBase | |||
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and | |||
* should be called sparingly. | |||
*/ | |||
@HostListener('window:resize') |
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.
We don't really use the @HostListener
anywhere. Can you switch to using the host
property on the component definition instead?
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.
Done.
Adds the `HostBinding` and `HostListener` decorators to the banned symbols list for consistency's sake. Refactors the handful of places that were using them. Relates to angular#6304.
src/lib/tabs/tab-header.ts
Outdated
@@ -79,6 +80,7 @@ export const _MdTabHeaderMixinBase = mixinDisableRipple(MdTabHeaderBase); | |||
'class': 'mat-tab-header', | |||
'[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls', | |||
'[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'", | |||
'(window:resize)': "_checkPaginationEnabled()" |
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.
At the very least this call should be debounced. The comment for the handler even says "This is an expensive call that forces a layout reflow to compute box and scroll metrics and should be called sparingly."
src/lib/tabs/tab-header.ts
Outdated
@@ -79,6 +80,7 @@ export const _MdTabHeaderMixinBase = mixinDisableRipple(MdTabHeaderBase); | |||
'class': 'mat-tab-header', | |||
'[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls', | |||
'[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'", | |||
'(window:resize)': "_checkPaginationEnabled()" |
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.
We should really just have one library-wide resize handler instead of each component adding their own. Add a TODO?
src/lib/tabs/tab-header.ts
Outdated
@@ -79,6 +80,7 @@ export const _MdTabHeaderMixinBase = mixinDisableRipple(MdTabHeaderBase); | |||
'class': 'mat-tab-header', | |||
'[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls', | |||
'[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'", | |||
'(window:resize)': "_checkPaginationEnabled()" |
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.
Any way to add a unit test for this?
Adds the `HostBinding` and `HostListener` decorators to the banned symbols list for consistency's sake. Refactors the handful of places that were using them. Relates to #6304.
Adds the `HostBinding` and `HostListener` decorators to the banned symbols list for consistency's sake. Refactors the handful of places that were using them. Relates to #6304.
@jelbourn - Ready for another review. |
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.
LGTM, just a couple minor things. Add the "merge-ready" label when ready
tick(10); | ||
fixture.detectChanges(); | ||
|
||
expect(header._checkPaginationEnabled).toHaveBeenCalled(); |
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.
FYI, I generally prefer tests that assert on the outcome of calling the function rather than using a spy. In this case, though, it would end up being a brittle geometric value so the spy is okay.
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.
Ya, thats what I was thinking too.
src/lib/tabs/tab-header.ts
Outdated
@@ -143,6 +146,11 @@ export class MdTabHeader extends _MdTabHeaderMixinBase | |||
private _changeDetectorRef: ChangeDetectorRef, | |||
@Optional() private _dir: Directionality) { | |||
super(); | |||
|
|||
// TODO: Add library level window listener https://goo.gl/FJWhZM |
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.
I think you got the wrong comment in your shortlink
(probably meant #6304 (comment))
src/lib/tabs/tab-header.ts
Outdated
@@ -78,7 +78,7 @@ export const _MdTabHeaderMixinBase = mixinDisableRipple(MdTabHeaderBase); | |||
host: { | |||
'class': 'mat-tab-header', | |||
'[class.mat-tab-header-pagination-controls-enabled]': '_showPaginationControls', | |||
'[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'", | |||
'[class.mat-tab-header-rtl]': "_getLayoutDirection() == 'rtl'" |
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.
TrailingCommas4Life
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.
Are you serial?!
Actually I just noticed that this breaks the prerender task. The resize event should only be setup when on the browser platform |
@jelbourn - ready for another review. |
In angular#6304, an extra window resize handler was added in order to call `_checkPaginationEnabled`. This handler is unnecessary, because we have another resize handler a little bit below that calls `_updatePagination`, which will call `_checkPaginationEnabled` internally. The original issue that angular#6304 was fixing was due to the fact that the current listener wasn't being run in the Angular zone. These changes remove the extra listener, increase the debounce interval and move the handler outside back into the zone. There may be a slight overhead from moving the listener into the zone, however it should be offset by not having another listener and not calling `_checkPaginationEnabled` twice.
In #6304, an extra window resize handler was added in order to call `_checkPaginationEnabled`. This handler is unnecessary, because we have another resize handler a little bit below that calls `_updatePagination`, which will call `_checkPaginationEnabled` internally. The original issue that #6304 was fixing was due to the fact that the current listener wasn't being run in the Angular zone. These changes remove the extra listener, increase the debounce interval and move the handler outside back into the zone. There may be a slight overhead from moving the listener into the zone, however it should be offset by not having another listener and not calling `_checkPaginationEnabled` twice.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Addresses #6303