Skip to content
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

HTMLElement as constructor argument #265

Closed
wiiiteek opened this issue Jun 30, 2017 · 3 comments
Closed

HTMLElement as constructor argument #265

wiiiteek opened this issue Jun 30, 2017 · 3 comments
Labels

Comments

@wiiiteek
Copy link

Hello,

I think it would be great if user could provide HTMLELement instance as a container in Typed constructor:

let p = document.querySelector('.some-container');
let t = new Typed(p, {
                strings: ["Some text"],
                typeSpeed: 15
});

What do you think?

@mattboldt
Copy link
Owner

As opposed to just passing in the query selector as a string? The library grabs the HTML element the exact same way as the code above. Do you just want to be able to declare a var for your element, do stuff with it, then pass it to Typed?

@wiiiteek
Copy link
Author

wiiiteek commented Jul 1, 2017

Yes, let me show you why I need this feature:

Let's take this code sample (TypeScript)

class SomeDialogBox {
    private node: HTMLElement
    public templateHTML = ''+
        '<div class="dialog-content"></div><div class="dialog-btn"></div>';

    constructor() {
        let n = this.node = document.createElement("div");
        n.innerHTML = this.templateHTML;

        // this operation will return exactly THIS dialog content
        let content = n.querySelector('.dialog-content'); 

        // I cant simply put '.dialog-content' into Typed because there can multiple DialogBoxes
        // so it would be great if I could put HTMLELement object instead
        let t = new Typed(content, {
            strings: ["Some text"],
            typeSpeed: 15
        });
    }
}

If I put '.dialog-content' as string into Typed, then I cant be sure which div container will be selected, because there will be multiple dialog boxes

@mattboldt
Copy link
Owner

Added to v2.0.2! As an Angular2 dev, I totally understand how this would come in handy. Thanks so much for your detailed feedback!

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

No branches or pull requests

2 participants