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

Setting the active attribute of a paper-button inserted into a slot using setAttribute requires calling it twice before it is updated. #169

Open
1 of 8 tasks
eriklumme opened this issue Aug 24, 2017 · 2 comments

Comments

@eriklumme
Copy link

Description

Imperatively setting the active attribute of a paper-button inserted into a slot requires setting it twice before it is updated.

Expected outcome

The attribute is updated the first time.

Actual outcome

The attribute is not updated until the second time.

Live Demo

https://jsbin.com/lalarivoli/1/edit?html,console,output

Steps to reproduce

  1. Create a Polymer element with a slot.
  2. On ready(), set the active attribute of the <paper-button> in the slot to true.
  3. Create a parent element that holds the child element and inserts a <paper-button> into the slot.

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9
  • Safari 8
  • Safari 7
  • Edge
  • IE 11
  • IE 10
@eriklumme eriklumme changed the title Setting the active attribute of a paper-button inserted into a slot using setAttribute requires calling it twice before it is updated. Setting the active attribute of a paper-button inserted into a slot using setAttribute requires calling it twice before it is updated. Aug 24, 2017
@eriklumme
Copy link
Author

eriklumme commented Aug 24, 2017

This seems to be the case with other properties such as raised too, but not properties not defined in the paper-button such as my-attribute.

Instead of setting active twice, one can set raised once and then active, at which point raised will be false and active will be true. I.e. the first time any property defined in paper-button is set, it is not updated. After that, all properties are immediately updated.

@valdrinkoshi
Copy link
Member

That happens because these properties do reflectToAttribute and have a default value, e.g. see active property.
I'd suggest to set the property instead of the attribute, e.g.

ready() {
  super.ready();
  const paperButton = this.querySelector('paper-button');
  paperButton.active = true;
  console.log(paperButton.hasAttribute('active')); // true \o/
}

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

No branches or pull requests

2 participants