Padax / w-components

JavaScript library based on Web Components.
MIT License
22 stars 2 forks source link

Attributes of w-button does not work if creating by DOM.create() #138

Closed cwpeng closed 2 years ago

cwpeng commented 2 years ago

If we use code below to create w-button, type and size attributes do not work.

    DOM.create("w-button", {
      attrs:{type:"outline", size:"sm"},
      props:{className:"secondary", textContent:"Cancel"}
    }, footerRight);
nizniz187 commented 2 years ago

This problem is caused by the component key set timing. We set the key on connectedCallback, i.e. when the component was added to DOM. Then for some reason (probably for reducing the times update event being triggered,) we skipped attribute update by checking if the key is not valid (unset.) That's why in this case of creating component programically -- create and set attributes/properties first, and add to DOM later -- the properties are well set, but the attributes take no effect. By changing the key set timing from connectedCallback to right after init function being called, this issue is solved. But we shall still take a look if it makes any further side effect.

@cwpeng Please take a review.

cwpeng commented 2 years ago

Done.