Skip to content

Commit

Permalink
Event handlers with the on: directive are deprecated in svelte 5
Browse files Browse the repository at this point in the history
Also bubbling events from HTML elements to the components have to be
done with `onclick` callback props.
  • Loading branch information
sebastinez committed Sep 10, 2024
1 parent 6cfd87f commit ab248f4
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/components/Border.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
export let variant: "primary" | "secondary" | "ghost";
export let hoverable: boolean = false;
export let onclick: (() => void) | undefined = undefined;
export let stylePadding: string | undefined = undefined;
export let styleHeight: string | undefined = undefined;
Expand Down Expand Up @@ -150,7 +151,7 @@
<div
style:width={styleWidth}
class="container"
on:click
{onclick}
role="button"
tabindex="0"
{style}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
export let variant: "primary" | "secondary" | "ghost";
export let onclick: (() => void) | undefined = undefined;
$: style =
`--button-color-1: var(--color-fill-${variant});` +
Expand Down Expand Up @@ -222,7 +223,7 @@
</style>

<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="container" on:click role="button" tabindex="0" {style}>
<div class="container" {onclick} role="button" tabindex="0" {style}>
<div class="pixel p1-1"></div>
<div class="pixel p1-2"></div>
<div class="pixel p1-3"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Fill.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let stylePadding: string | undefined = undefined;
export let styleHeight: string | undefined = undefined;
export let styleWidth: string | undefined = undefined;
export let onclick: (() => void) | undefined = undefined;
$: style =
variant === "transparent"
Expand Down Expand Up @@ -82,9 +83,9 @@
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class="container"
on:click
role="button"
tabindex="0"
{onclick}
{style}
style:width={styleWidth}
style:height={styleHeight}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<div class="flex-item navigation" style:gap="0.5rem">
<Icon
name="arrow-left"
on:click={() => {
onclick={() => {
window.history.back();
}} />
<Icon
name="arrow-right"
on:click={() => {
onclick={() => {
window.history.forward();
}} />
</div>
Expand All @@ -67,7 +67,7 @@
<Border
slot="toggle"
let:toggle
on:click={toggle}
onclick={toggle}
variant="ghost"
stylePadding="0 0.25rem"
styleHeight="32px">
Expand Down
3 changes: 2 additions & 1 deletion src/components/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { unreachable } from "@app/lib/utils";
export let size: "16" | "32" = "16";
export let onclick: (() => void) | undefined = undefined;
export let name:
| "arrow-left"
Expand Down Expand Up @@ -39,7 +40,7 @@
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<svg
role="img"
on:click
{onclick}
width={size}
height={size}
fill="currentColor"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Link.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
}
</style>

<a on:click={navigateToRoute} href={routeToPath(route)}>
<a onclick={navigateToRoute} href={routeToPath(route)}>
<slot />
</a>
2 changes: 1 addition & 1 deletion src/components/Popover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
</style>

<svelte:window on:click={clickOutside} on:touchstart={clickOutside} />
<svelte:window onclick={clickOutside} on:touchstart={clickOutside} />

<div
bind:this={thisComponent}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ThemeSwitch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<Fill
stylePadding="0 0.5rem"
variant={$theme === "dark" ? "secondary" : "transparent"}
on:click={() => {
onclick={() => {
storeTheme("dark");
}}>
<Icon name="moon" />
Expand All @@ -49,7 +49,7 @@
<Fill
stylePadding="0 0.5rem"
variant={$theme === "light" ? "secondary" : "transparent"}
on:click={() => {
onclick={() => {
storeTheme("light");
}}>
<span
Expand Down

0 comments on commit ab248f4

Please sign in to comment.