Skip to content

this.getAttribute() returns undefined when used with async components #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alsoicode opened this issue May 17, 2021 · 3 comments · Fixed by #55
Closed

this.getAttribute() returns undefined when used with async components #40

alsoicode opened this issue May 17, 2021 · 3 comments · Fixed by #55
Assignees

Comments

@alsoicode
Copy link

alsoicode commented May 17, 2021

Hello,

When incorporating markdown-toolbar-element into an Angular (11.2.12) component that is added to the DOM dynamically, this.getAttribute() returns undefined. A concrete example of this would be the level attribute of MarkdownHeaderButtonElement

If I force the event loop to tick one time:

class MarkdownHeaderButtonElement extends MarkdownButtonElement {
    constructor() {
        super();

        setTimeout(() => {
            const level = parseInt(this.getAttribute('level') || '3', 10);
            if (level < 1 || level > 6) {
                return;
            }
            const prefix = `${'#'.repeat(level)} `;
            styles.set(this, {
                prefix
            });
        }, 0);
    }
}

it works as expected. Do you have a default strategy for this scenario? Unfortunately, adding setTimeout() breaks the test cases for title.

@alsoicode alsoicode changed the title getAttribute returns undefined when used with async components this.getAttribute() returns undefined when used with async components May 17, 2021
@koddsson
Copy link
Contributor

koddsson commented Jun 9, 2021

When incorporating markdown-toolbar-element into an Angular (11.2.12) component that is added to the DOM dynamically, this.getAttribute() returns undefined.

Could you attach a minimum reproduction case so we can dig into the issue?

@alsoicode
Copy link
Author

Sorry for the delay getting back to you. I'll try to make some time to get a StackBlitz together.

@mjsprengers
Copy link

Hi @koddsson @alsoicode,

Running into the same issue, here's a repro in Stackblitz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants