Using shoelace in svelte #320
Replies: 3 comments 8 replies
-
I'm not familiar with Svelte directly, but I'm guessing the code you need to run would need to be wrapped in a That way you're guaranteed not to be interacting with a generic/unknown HTML element. |
Beta Was this translation helpful? Give feedback.
-
This may help. It's not [currently] documented, but every component exposes a const input = document.querySelector('sl-input');
input.componentOnReady().then(() => {
// component has rendered
}); |
Beta Was this translation helpful? Give feedback.
-
Is this still a problem with the latest LitElement-powered release? |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I've been using shoelace components in a svelte app, and it's mostly been going well, but I've run into a few problems, and I'm trying to determine if it's on my end, svelte's end, or shoelace's.
It seems the shoelace components get out of sync with the svelte render process, causing some "undefined is not a function" errors. Here's an example: https://svelte.dev/repl/ba22f88b580e44b9a794005af6c4cb1f?version=3.32.1. And here's the code:
For those of you not familiar with svelte, use:focus is a directive which calls the focus method once the node it is on has been mounted. Only trouble is, it is called before the
sl-input
component has fully initialized, resulting in an error written to the console:TypeError: Cannot read property 'focus' of undefined at HTMLElement.setFocus
.Wrapping the call to
el.setFocus
in asetTimeout
works, but it's hacky and I'm trying to see if there's a better way.On a related note, can anyone explain why methods like
setFocus
are async? I don't quite understand that.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions