IgniteUI / igniteui-angular

Ignite UI for Angular is a complete library of Angular-native, Material-based Angular UI components with the fastest grids and charts, Pivot Grid, Dock Manager, Hierarchical Grid, and more.
https://www.infragistics.com/products/ignite-ui-angular
Other
572 stars 161 forks source link

Text Highlight Directive: TypeError: can't access property "classList", el is undefined #10002

Closed pmoleri closed 3 years ago

pmoleri commented 3 years ago

Description

I use text highlight directive inside an igxFor virtualized list and I have a filter on it. When I use the filter everything works fine, but when I clear the filter it crashes.

Steps to reproduce

I don't currently have isolated it.

Result

Exception: TypeError: can't access property "classList", el is undefined

Attachments

image image image image

pmoleri commented 3 years ago

I tried to isolate the issue, I couldn't get the exact same result but I got errors anyway. Use this stackblitz: https://stackblitz.com/edit/github-bwxvr8?

The highlight is inside a component that is rendered inside a virtualized igxFor.

image

DiyanDimitrov commented 3 years ago

@pmoleri. The text highlight expects that you will track an active highlight, but in your case I guess that you won't have an active highlight. I will make a change to skip the active highlight if the index is -1.

pmoleri commented 3 years ago

I will make a change to skip the active highlight if the index is -1.

That's how I monkey patched it yersterday :)

function highlightBugFix() {
    // Fix bug https://github.com/IgniteUI/igniteui-angular/issues/10002
    const highlight = IgxTextHighlightDirective.prototype as any;
    if (highlight && highlight.activate) {
        const activateOriginal: (index: number) => void = highlight.activate;

        highlight.activate = function(index: number) {
            if (index === -1) {
                // When activating nothing remove the highlight element, otherwise activate fails
                this.deactivate();
                this.clearHighlight(false);
            }

            activateOriginal.call(this, index);
        };
    }
}
pmoleri commented 3 years ago

I don't know exactly how IgxFor directive works, but it seems to me that at some point the component instances are still alive, but the DOM elements are not there and that's when the highlight fails. The highlight didn't fail with a regular ngFor.

DiyanDimitrov commented 3 years ago

I am also not sure why it works with regular ngFor, but this issue is definitely reproducible with a simple highlight if no active highlight is set.