Skip to content

Commit eb63fee

Browse files
committed
fix(dropdown): doesn't render nested dropdowns (#UIM-773) (#700)
* fix(dropdown): doesn't render nested dropdowns (#UIM-773) * fixed linter error * fixed tests
1 parent 885790e commit eb63fee

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

packages/mosaic-dev/dropdown/module.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* tslint:disable:no-console */
12
import { Component, NgModule, ViewEncapsulation } from '@angular/core';
23
import { FormsModule } from '@angular/forms';
34
import { BrowserModule } from '@angular/platform-browser';
@@ -15,6 +16,33 @@ import { McLinkModule } from '@ptsecurity/mosaic/link';
1516
encapsulation: ViewEncapsulation.None
1617
})
1718
export class DemoComponent {
19+
pools = [
20+
{
21+
id: 1,
22+
name: 'x',
23+
domains: [
24+
{ id: 10, name: 'ax' },
25+
{ id: 11, name: 'bx' }
26+
]
27+
},
28+
{
29+
id: 2,
30+
name: 'y',
31+
domains: [
32+
{ id: 20, name: 'ay' },
33+
{ id: 21, name: 'by' }
34+
]
35+
},
36+
{
37+
id: 3,
38+
name: 'z',
39+
domains: [
40+
{ id: 30, name: 'az' },
41+
{ id: 31, name: 'bz' }
42+
]
43+
}
44+
];
45+
1846
someValue = 'Lazy Value';
1947

2048
isDropdownOpen: boolean = false;
@@ -26,6 +54,10 @@ export class DemoComponent {
2654
dropdownClosed() {
2755
this.isDropdownOpen = false;
2856
}
57+
58+
selectDomain(id: string): void {
59+
console.log('selected domain id', id);
60+
}
2961
}
3062

3163
@NgModule({

packages/mosaic-dev/dropdown/template.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
11
<div>
2+
<br><br><br>
3+
4+
<span mc-link
5+
pseudo
6+
[mcDropdownTriggerFor]="dropdown">
7+
Выбрать
8+
</span>
9+
10+
<mc-dropdown #dropdown>
11+
<ng-template mcDropdownContent>
12+
<button
13+
*ngFor="let pool of pools"
14+
mc-dropdown-item
15+
[mcDropdownTriggerFor]="domainsDropdown"
16+
[mcDropdownTriggerData]="{domains: pool.domains}"
17+
>
18+
{{pool.name}}
19+
</button>
20+
</ng-template>
21+
</mc-dropdown>
22+
23+
<mc-dropdown #domainsDropdown>
24+
<ng-template mcDropdownContent let-domains="domains">
25+
<button
26+
*ngFor="let domain of domains"
27+
mc-dropdown-item
28+
(click)="selectDomain(domain.id)"
29+
>
30+
{{domain.name}}
31+
</button>
32+
</ng-template>
33+
</mc-dropdown>
34+
35+
<br><br><br>
36+
237
<span class="mc-group">
338
<button mc-button class="mc-group-item mc-active"
439
[ngClass]="{ 'mc-active': isDropdownOpen}"

packages/mosaic/dropdown/dropdown-content.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class McDropdownContent implements OnDestroy {
6969
* @docs-private
7070
*/
7171
detach() {
72-
if (this.portal.isAttached) {
72+
if (this.portal?.isAttached) {
7373
this.portal.detach();
7474
}
7575
}

packages/mosaic/dropdown/dropdown-trigger.directive.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ export class McDropdownTrigger implements AfterContentInit, OnDestroy {
214214
overlayRef.attach(this.getPortal());
215215

216216
if (this.dropdown.lazyContent) {
217+
this.dropdown.lazyContent.detach();
218+
217219
this.dropdown.lazyContent.attach(this.data);
218220
}
219221

@@ -328,14 +330,7 @@ export class McDropdownTrigger implements AfterContentInit, OnDestroy {
328330
}
329331

330332
dropdownAnimationDoneSubscription
331-
.subscribe({
332-
// If lazy content has attached we're need to detach it.
333-
next: this.dropdown.lazyContent ? () => this.dropdown.lazyContent?.detach() : undefined,
334-
error: undefined,
335-
complete: () => {
336-
this.reset();
337-
}
338-
});
333+
.subscribe(() => this.reset());
339334
} else {
340335
this.reset();
341336

packages/mosaic/dropdown/dropdown.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,14 @@ describe('McDropdown', () => {
631631
fixture.detectChanges();
632632
tick(500);
633633

634-
expect(fixture.componentInstance.items.length).toBeGreaterThan(0);
634+
expect(overlayContainerElement.querySelectorAll('.mc-dropdown__panel').length).toBeGreaterThan(0);
635635

636636
fixture.componentInstance.trigger.close();
637637
fixture.detectChanges();
638638
tick(500);
639639
fixture.detectChanges();
640640

641-
expect(fixture.componentInstance.items.length).toBe(0);
641+
expect(overlayContainerElement.querySelectorAll('.mc-dropdown__panel').length).toBe(0);
642642
}));
643643

644644
it('should wait for the close animation to finish before considering the panel as closed', fakeAsync(() => {

0 commit comments

Comments
 (0)