Use the connectedCallback function to set button styles instead of the constructor #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Building a header button in memory with a custom heading ("level") causes a unexpected behaviour. Consider the following example:
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 thelevel
attribute when the component is initialised. Changing the constructor to aconnectedCallback
function ensures that the button styles aren't set until the button is connected to the DOM.Since
constructor
can be error-prone for custom elements and keep all the components similar, I've also changed all the constructors toconnectedCallback
functions.Finally, even though we don't expect header buttons to change levels dynamically during an application lifetime, we should ensure that it works as expected. So I've added an
attributeChangedCallback
to the header button element. The callback changes the level style based on thelevel
attribute.Fixes #40 and possibly #45