MOBILE-3952 context-menu: Fix menu displayed when no items
This commit is contained in:
		
							parent
							
								
									11d219ddce
								
							
						
					
					
						commit
						bb97b0e48a
					
				| @ -12,7 +12,7 @@ | |||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
| import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; | import { Component, Input, OnInit, OnDestroy, ElementRef, ChangeDetectorRef } from '@angular/core'; | ||||||
| import { Subject } from 'rxjs'; | import { Subject } from 'rxjs'; | ||||||
| import { auditTime } from 'rxjs/operators'; | import { auditTime } from 'rxjs/operators'; | ||||||
| import { CoreDomUtils } from '@services/utils/dom'; | import { CoreDomUtils } from '@services/utils/dom'; | ||||||
| @ -43,16 +43,17 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy { | |||||||
|     protected parentContextMenu?: CoreContextMenuComponent; |     protected parentContextMenu?: CoreContextMenuComponent; | ||||||
|     protected expanded = false; |     protected expanded = false; | ||||||
| 
 | 
 | ||||||
|     constructor(elementRef: ElementRef) { |     constructor(elementRef: ElementRef, changeDetector: ChangeDetectorRef) { | ||||||
|         // Create the stream and subscribe to it. We ignore successive changes during 250ms.
 |         // Create the stream and subscribe to it. We ignore successive changes during 250ms.
 | ||||||
|         this.itemsChangedStream = new Subject<void>(); |         this.itemsChangedStream = new Subject<void>(); | ||||||
|         this.itemsChangedStream.pipe(auditTime(250)); |         this.itemsChangedStream.pipe(auditTime(250)).subscribe(() => { | ||||||
|         this.itemsChangedStream.subscribe(() => { |  | ||||||
|             // Hide the menu if all items are hidden.
 |             // Hide the menu if all items are hidden.
 | ||||||
|             this.hideMenu = !this.items.some((item) => !item.hidden); |             this.hideMenu = !this.items.some((item) => !item.hidden); | ||||||
| 
 | 
 | ||||||
|             // Sort the items by priority.
 |             // Sort the items by priority.
 | ||||||
|             this.items.sort((a, b) => (a.priority || 0) <= (b.priority || 0) ? 1 : -1); |             this.items.sort((a, b) => (a.priority || 0) <= (b.priority || 0) ? 1 : -1); | ||||||
|  | 
 | ||||||
|  |             changeDetector.detectChanges(); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         // Calculate the unique ID.
 |         // Calculate the unique ID.
 | ||||||
| @ -118,7 +119,7 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy { | |||||||
| 
 | 
 | ||||||
|         // Remove all items from the current menu.
 |         // Remove all items from the current menu.
 | ||||||
|         this.items = []; |         this.items = []; | ||||||
|         this.itemsChanged(); |         this.itemsChangedStream.next(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user