Commit a414178
committed
Convert
Building a header button in memory with a custom heading ("level")
causes a unexpected behaviour. Consider the following example:
```js
const headerButton = document.createElement('md-header') // The constructor is executed at this point.
headerButton.setAttribute('level', '1') // Has no effect since the style has already been set.
headerButton.textContent = 'h1'
document.body.appendChild(headerButton)
```
While we expect to have a header button that outputs a single hash
(`#`), we have a button that outputs three (`###`). The constructor sets
the styles based on the `level` attribute when the component is
initialised.
Changing the constructor to a `connectedCallback` function
ensures that the button styles aren't set until the button is connected
to the DOM.constructor to a connectedCallback function1 parent 2fe2941 commit a414178
1 file changed
+1
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
117 | 115 | | |
118 | 116 | | |
119 | 117 | | |
| |||
0 commit comments