bestguy / sveltestrap

Bootstrap 4 & 5 components for Svelte
https://sveltestrap.js.org
MIT License
1.3k stars 183 forks source link

Actions can only be applied to DOM elements, not components #451

Open diontron opened 2 years ago

diontron commented 2 years ago

I am using Inertia and Sveltestrap.

I am trying to add use:inertia to a NavLink component but I get the following error:

Actions can only be applied to DOM elements, not components

Here is the code:

<script>
    import {inertia} from '@inertiajs/inertia-svelte'
    import {NavLink} from 'sveltestrap'
</script>

<NavLink href="/login" use:inertia>Login</NavLink>

Is there any way I can use:inertia on a non-DOM element (e.g. a component)?

demetrius-mp commented 2 years ago

as far as i know, you cannot pass actions to components in a natural way.

the author would have to accept an use property in every component and forward it.

but what you can try to do is wrap the component inside a dom element (maybe a div, or a span), and apply the action to the wrapping element. i did this when i had to do things like handling click events on components that didnt forward an on:click event.

another thing you can try is actually just using plain HTML with the required bootstrap css classes for the single element you want to use the action.