This repository has been archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): defer getComputedStyle() calls until ngOnInit phase
Previously, the Show/Hide directives would query the `display` style during directive instantiation. For elements instantiated during `*ngFor`, constructor calls to getComputedStyle() will incorrectly return “” due to failures in queries for styles in CSS stylesheets or inline styles. Deferring these types of queries to the ngOnInit() lifecycle event, enables valid response to queries for both inline styles and stylesheets. Fixes #310.
- Loading branch information
1 parent
695bf37
commit 430069e
Showing
15 changed files
with
271 additions
and
75 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
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 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,75 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {Component} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {TestBed} from '@angular/core/testing'; | ||
|
||
import {customMatchers} from './testing/custom-matchers'; | ||
import {makeExpectDOMFrom} from './testing/helpers'; | ||
|
||
describe('style-utils directive', () => { | ||
let expectDOMFrom = makeExpectDOMFrom(() => TestLayoutComponent); | ||
|
||
beforeEach(() => { | ||
jasmine.addMatchers(customMatchers); | ||
|
||
// Configure testbed to prepare services | ||
TestBed.configureTestingModule({ | ||
imports: [CommonModule], | ||
declarations: [TestLayoutComponent] | ||
}); | ||
}); | ||
|
||
describe('testing display styles', () => { | ||
|
||
it('should default to "display:block" for <div></div>', () => { | ||
expectDOMFrom(` | ||
<div></div> | ||
`).toHaveStyle({'display': 'block'}); | ||
}); | ||
|
||
it('should find to "display" for inline style <div></div>', () => { | ||
expectDOMFrom(` | ||
<div style="display: flex;"></div> | ||
`).toHaveStyle({'display': 'flex'}); | ||
}); | ||
|
||
it('should find `display` from html style element', () => { | ||
expectDOMFrom(` | ||
<style> | ||
div.special { display: inline-block; } | ||
</style> | ||
<div class="special"></div> | ||
`).toHaveStyle({'display': 'inline-block'}); | ||
}); | ||
|
||
it('should find `display` from component styles', () => { | ||
let expectStyledDOM = makeExpectDOMFrom(() => TestLayoutComponent, [ | ||
'div.extra { display:table; }' | ||
]); | ||
expectStyledDOM(` | ||
<div class="extra"></div> | ||
`).toHaveStyle({'display': 'table'}); | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
// ***************************************************************** | ||
// Template Component | ||
// ***************************************************************** | ||
|
||
@Component({ | ||
selector: 'test-style-utils', | ||
template: `<span>PlaceHolder Template HTML</span>` | ||
}) | ||
export class TestLayoutComponent { | ||
} |
Oops, something went wrong.