HealthCatalyst / Fabric.Cashmere

Health Catalyst’s comprehensive design system.
http://cashmere.healthcatalyst.net
Apache License 2.0
66 stars 76 forks source link

ScrollNav throws error when HcScrollNavComponent is updated and [hasDynamicContent]="true" #2224

Open amaury14 opened 1 year ago

amaury14 commented 1 year ago

Summary

Reproduction

Steps to reproduce:

  1. In Vitalware VitalKnowledge we are using the ScrollNav component inside dynamic tabs. The issues presents when you change from one tab to another with the ScrollNav as a content. This happen when [hasDynamicContent]="true".

The error is thrown by this function in the else statement. We have in place the hcScrollLink links to be use inside the scroll nav.

_setActiveSectionById(id) {
        const link = this.linkList.find(e => e.hcScrollLink === id);
        if (!link) {
            if (!this.tryRefresh) {
                this.tryRefresh = true;
                this.refreshScrollNavLinks();
                this._setActiveSectionById(id);
            }
            else {
                this.tryRefresh = false;
                throw new Error(`Failed to mark active section. Could not find the element with the data target for id: ${id}.`);
            }
        }
        else {
            this.setActiveSection(link.nativeElement);
        }
    }

image

I found out that if I set the [hasDynamicContent]="false" the issue is solved:

With this last config and using this.scrollNavContent.setActiveSection(sectionInViewId); the active section in never updated. The component doesn't update.

corykon commented 1 year ago

Thanks for reporting @amaury14! I appreciate the thorough explanation. Any chance you could throw together a stackbltiz that repro's the issue? No worries if you don't have time, but it would help us find a fix more quickly.