0

Is there any way to pass parameters to the custom web component ? I need parameters for my component . Class is extended html collection.

class CustomDropdown extends HTMLElement{

    constructor(){

        super();

        this.shadow = this.attachShadow({ mode : 'open' });

        this.setAttribute('expanded', there should be some parameter );

    }
}

1 Answer 1

1

Normally, when you use your custom component you pass the parameters as attributes:

<custom-dropw-down expanded="true"></custom-drop-down>

Then, in the connectedCallback hook you can retrieve them:

connectedCallback() {
    const isExpanded = this.getAttribute('expanded');
}

If you want to set an attribute to the rendered DOM, you should also do that once the component has been rendered (for example, in the connectedCallback hook):

connectedCallback() {
    this.setAttribute('expanded', 'true');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.