Skip to content

Using html elements inside Shoelace components #1964

Answered by claviska
teemu-linecut asked this question in Help
Discussion options

You must be logged in to vote

Can I use html elements inside Shoelace components?

Yes, absolutely!

But I get TypeError: Cannot read properties of null on openButton.addEventListener.

This tells me that openButton is being assigned by a querySelector() that doesn't match. In this example, we assigned a drawer with the "drawer-overview" class and the open button is the next element adjacent to the drawer.

const drawer = document.querySelector('.drawer-overview');
const openButton = drawer.nextElementSibling;

We do this in the docs for convenience so we don't litter it up with ids, but it's not a portable way to obtain element references. For example, adding anything — even a <br> tag — between the drawer and the but…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@teemu-linecut
Comment options

Answer selected by teemu-linecut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants