Kendo-angular: [PopupSettings] extend type of anchor property

Created on 25 Apr 2020  路  8Comments  路  Source: telerik/kendo-angular

In PopupSettings the type of anchor property is ElementRef, but HTMLElement type is a working case too. I had some investigation on it and found that Kendo uses the following unwrap method in dom.service:

public nativeElement(el: ElementRef): HTMLElement {
  if (!el) { return null; }

  return el.nativeElement || el;
}

https://stackblitz.com/edit/angular-gwiipe?file=app/app.component.ts
In the given link you can observe the described above behavior.

Enhancement Team1 possible popup low

Most helpful comment

Good point. Seems we'll have to prioritize this issue after all. In the meantime the [anchor]="$any(anchor)" workaround will have to be used.

Edit:
Duck-typing should also work:

[anchor]="{ nativeElement: anchor }"

All 8 comments

Thanks for pointing this out, @destus90, we'll update the type and docs as suggested.

While we are here, I would like to note some oversight in the docs. In your example, the type of anchor argument in the togglePopup method is set to ElementRef which is wrong. It should have been HTMLButtonElement. It would be nice if you updated this typo.

Actually, if you enable strictTemplates check you are going to have an error based on HtmlElement used as popup anchor.

Property 'nativeElement' is missing in type 'HTMLButtonElement' but required in type 'ElementRef<any>'

The only workaround found is to add $any <kendo-popup [anchor]="$any(anchor)" on template side: https://angular.io/guide/template-typecheck#disabling-type-checking-using-any

Still present on the latest milestone of kendo components!

Same problem for me.

Why is this only sev1:low!?

The reason why we want use TypeScript ist safety. It should be possible to enable all strict options that are available. In TypeScript and in Angular too!

Turned out this was more than just a docs update task, as changing the type requires more changes in other places of the popup code and possibly in other kendo components using the popup internally as well. The reason it is marked as a low severity issue is that the configuration works as expected when the correct type is provided (ElementRef instaed of HTMLElement) - it is different than #3158, as the summary tag directive is supposed to work without arguments as well.

So, the popup anchor ElementRef can be correctly provided by querying a reference to its ElementRef instance from code and using that value instead of the template variable value. Here's an example.

It does look pretty redundant though and unpleasant to use like so, therefore it is marked as a valid enhancement. As it may take more time to implement and test across other repos where the popup is used, while a viable solution currently exists, it's not yet been planned and I cannot commit to a specific ETA.

Your solution doesn't work in all of my cases.

E.g it doesn't work in *ngFor or in Kendo controls itself (e.g. kendo-grid):

                <kendo-grid
                    ...
                >               
                    <kendo-grid-column field="name" title="Name" [width]="300">
                        <ng-template kendoGridEditTemplate let-column="column" let-formGroup="formGroup">
                            <input #anchor class="k-textbox" [formControl]="formGroup.get(column.field)" />

                            <kendo-popup [anchor]="anchorElementRef">
                                <span class="k-icon k-i-warning mr-2"></span> Name is required
                            </kendo-popup>

                        </ng-template>
                    </kendo-grid-column>
...

Here 'anchorElementRef' is always undefined!

https://angular.io/guide/template-reference-variables#accessing-in-a-nested-template

Good point. Seems we'll have to prioritize this issue after all. In the meantime the [anchor]="$any(anchor)" workaround will have to be used.

Edit:
Duck-typing should also work:

[anchor]="{ nativeElement: anchor }"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jiangen1016 picture jiangen1016  路  16Comments

0-gravity picture 0-gravity  路  28Comments

simon11196 picture simon11196  路  17Comments

tsvetomir picture tsvetomir  路  20Comments

alexeykostevich picture alexeykostevich  路  16Comments