DevCloudFE / ng-devui

Angular UI Component Library based on DevUI Design
https://devui.design
MIT License
1.75k stars 210 forks source link

关于d-select #313

Closed 75910456 closed 1 year ago

75910456 commented 1 year ago

Version

^12.0.0-beta.1

Angular Version

~12.2.0

Link to minimal reproduction

<d-select #select="select" [options]="dataSources" [isSearch]="true" [readonly]="true" [(ngModel)]="currentValue" [allowClear]="true" [placeholder]="placeholder" (toggleChange)="toggleChange($event)" [customViewTemplate]="selectBottomTemplate" [appendToBody]="true">

<ng-template #selectBottomTemplate let-selectComponent>

d-pagination中页按钮点击后,会导致select下拉框隐藏,通过如下代码可以避免隐藏下拉框: @HostListener("click", ["$event"]) inClick(e: MouseEvent) { e.stopPropagation(); }

但如果d-select中使用了[appendToBody]="true",上述代码无效了,修改成 @HostListener("document:click", ["$event"])也不行,

我应该如何实现在select下拉框中点击某个区域,但不要隐藏下拉区域?

Step to reproduce

1

What is expected

No response

What is actually happening

No response

Any additional comments (optional)

No response

75910456 commented 1 year ago

已经实现了,谢谢

@Directive({ selector: '[appSelectDropdownIgnoreClick]' }) export class SelectDropdownIgnoreClickDirective implements AfterViewInit {

constructor(private el: ElementRef) { } ngAfterViewInit(): void { this.el.nativeElement.addEventListener('click', function (e) { e.stopPropagation(); }); } }