Skip to content

Commit fae6387

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/integration/ng15/serialize-javascript-6.0.2
2 parents da8d04a + 2e34121 commit fae6387

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

integration/ng14/angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{
4545
"type": "initial",
4646
"maximumWarning": "500kb",
47-
"maximumError": "1mb"
47+
"maximumError": "1.5mb"
4848
},
4949
{
5050
"type": "anyComponentStyle",

src/modal/base-modal.service.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
ComponentRef,
33
Injector,
4-
Injectable
4+
Injectable,
5+
inject,
6+
EnvironmentInjector
57
} from "@angular/core";
68
import { PlaceholderService } from "carbon-components-angular/placeholder";
79
import { tap, delay } from "rxjs/operators";
@@ -16,6 +18,23 @@ export class BaseModalService {
1618
// track all our open modals
1719
protected static modalList: Array<ComponentRef<any>> = [];
1820

21+
/**
22+
* Current module/component injection enviornment
23+
* Allows modules to use providers from calling component
24+
*
25+
* Root Module/
26+
* └── Lazy loaded Feature Module/
27+
* ├── Provides Service & imports modules
28+
* ├── Modal component (component that extends base component)
29+
* └── Modal component launcher (dynamically creates modal component)
30+
*
31+
* Passing EnvironmentInjector in `createComponent` will look for provider declaration in feature
32+
* module instead of root module. This is required to pass correct context in a lazy-loaded applications.
33+
* Services injected in root, will also be available as feature module enviornment will also hierarchically inherit
34+
* the root services.
35+
*/
36+
protected environment: EnvironmentInjector = inject(EnvironmentInjector);
37+
1938
/**
2039
* Creates an instance of `ModalService`.
2140
*/
@@ -34,7 +53,12 @@ export class BaseModalService {
3453
useValue: data.inputs[inputName]
3554
}));
3655
const injector = Injector.create({ providers: inputProviders });
37-
const component = this.placeholderService.createComponent(data.component, injector);
56+
const component = this.placeholderService.createComponent(
57+
data.component,
58+
injector,
59+
undefined,
60+
this.environment
61+
);
3862
let focusedElement = document.activeElement as HTMLElement;
3963
setTimeout(() => {
4064
component.instance.open = true;

src/placeholder/placeholder.service.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
ComponentRef,
33
ViewContainerRef,
4-
Injector
4+
Injector,
5+
EnvironmentInjector,
6+
inject
57
} from "@angular/core";
68
import { Injectable } from "@angular/core";
79

@@ -33,7 +35,12 @@ export class PlaceholderService {
3335
/**
3436
* Creates and returns component in the view.
3537
*/
36-
createComponent(component: ComponentRef<any>, injector: Injector, id?: any): ComponentRef<any> {
38+
createComponent(
39+
component: ComponentRef<any>,
40+
injector: Injector,
41+
id?: any,
42+
environment: EnvironmentInjector = undefined
43+
): ComponentRef<any> {
3744
if (id) {
3845
if (!this.viewContainerMap.has(id)) {
3946
console.error(`No view container with id ${id} found`);
@@ -45,7 +52,13 @@ export class PlaceholderService {
4552
console.error("No view container defined! Likely due to a missing `cds-placeholder`");
4653
return;
4754
}
48-
return this.viewContainerRef.createComponent(component as any, { index: this.viewContainerRef.length, injector });
55+
return this.viewContainerRef.createComponent(component as any,
56+
{
57+
index: this.viewContainerRef.length,
58+
injector,
59+
environmentInjector: environment
60+
}
61+
);
4962
}
5063

5164
destroyComponent(component: ComponentRef<any>) {

src/tooltip/tooltip.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ export class Tooltip extends PopoverContainer implements OnChanges, AfterContent
144144
this.handleChange(false);
145145

146146
// Ignore first change since content is not initialized
147-
if ((changes.autoAlign && !changes.autoAlign.firstChange)
148-
|| (changes.disabled && !changes.disabled.firstChange && !changes.disabled.currentValue)) {
147+
if (
148+
(changes.autoAlign && !changes.autoAlign.firstChange)
149+
|| (changes.disabled && !changes.disabled.firstChange && !changes.disabled.currentValue)
150+
// If description is set to empty string when open & autoAlign is true then set to a new value
151+
// positioning of popover is broken because popover content ref/caret no longer exists
152+
|| changes.description
153+
) {
149154
/**
150155
* When `disabled` is `true`, popover content node is removed. So when re-enabling `disabled`,
151156
* we manually update view so querySelector can detect the popover content node.
@@ -155,7 +160,7 @@ export class Tooltip extends PopoverContainer implements OnChanges, AfterContent
155160

156161
// Reset the inline styles
157162
this.popoverContentRef = this.elementRef.nativeElement.querySelector(".cds--popover-content");
158-
this.popoverContentRef.setAttribute("style", "");
163+
this.popoverContentRef?.setAttribute("style", "");
159164
this.caretRef = this.elementRef.nativeElement.querySelector("span.cds--popover-caret");
160165
}
161166

0 commit comments

Comments
 (0)