Skip to content

Commit

Permalink
chore: Making it more Svelte 5 compatible (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 authored May 1, 2024
1 parent e1c85eb commit 98d5bd0
Show file tree
Hide file tree
Showing 28 changed files with 58 additions and 52 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-pens-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

chore: Updated a11y warnings for better Svelte 5 compatibility
8 changes: 7 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ import config, { DEFAULT_IGNORES } from "@huntabyte/eslint-config";

const ignores = ["**/extended-types"];

export default config({ svelte: true, ignores: [...DEFAULT_IGNORES, ...ignores] });
export default config({
svelte: true,
ignores: [...DEFAULT_IGNORES, ...ignores],
}).override("huntabyte:svelte:rules", {
// we ignore as it complains about the changed warning names in Svelte 5
rules: { "svelte/no-unused-svelte-ignore": "off" },
});
4 changes: 2 additions & 2 deletions packages/bits-ui/src/lib/bits/button/components/button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</script>

{#if builders && builders.length}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<svelte:element
this={href ? "a" : "button"}
bind:this={el}
Expand All @@ -35,7 +35,7 @@
<slot />
</svelte:element>
{:else}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<svelte:element
this={href ? "a" : "button"}
bind:this={el}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
});
</script>

<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
{#if asChild && $open}
<slot {builder} />
{:else if transition && $open}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
$: isSelected = $isSelectedStore(value);
</script>

<!-- svelte-ignore a11y-no-static-element-interactions-->

<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
{#if asChild}
<slot {builder} {isSelected} />
{:else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{#if asChild && $open}
<slot {builder} />
{:else if transition && $open}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<div
on:mouseup
bind:this={el}
Expand All @@ -43,7 +43,7 @@
{...$$restProps}
></div>
{:else if inTransition && outTransition && $open}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<div
bind:this={el}
in:inTransition={inTransitionConfig}
Expand All @@ -53,7 +53,7 @@
{...$$restProps}
></div>
{:else if inTransition && $open}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<div
bind:this={el}
in:inTransition={inTransitionConfig}
Expand All @@ -62,7 +62,7 @@
{...$$restProps}
></div>
{:else if outTransition && $open}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<div
bind:this={el}
out:outTransition={outTransitionConfig}
Expand All @@ -71,6 +71,6 @@
{...$$restProps}
></div>
{:else if $open}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<div bind:this={el} use:melt={builder} on:mouseup {...$$restProps}></div>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
{#if asChild}
<slot {builder} />
{:else}
<svelte:element
this={"a"}
<!-- svelte-ignore a11y-missing-attribute a11y_missing_attribute -->
<a
bind:this={el}
use:melt={builder}
{...$$restProps}
Expand All @@ -42,5 +42,5 @@
on:m-pointerleave={dispatch}
>
<slot {builder} />
</svelte:element>
</a>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
}
</script>

<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
{#if asChild && $open}
<slot {builder} />
{:else if transition && $open}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$: isSelected = $isSelectedStore(value);
</script>

<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
{#if asChild}
<slot {builder} {isSelected} />
{:else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@
{#if asChild}
<slot {builder} />
{:else}
<!-- svelte-ignore a11y-no-static-element-interactions -->
<svelte:element
this={"a"}
bind:this={el}
use:melt={builder}
{...$$restProps}
on:click
on:m-keydown={dispatch}
>
<!-- svelte-ignore a11y-no-static-element-interactions a11y_no_static_element_interactions -->
<!-- svelte-ignore a11y-missing-attribute a11y_missing_attribute -->
<a bind:this={el} use:melt={builder} {...$$restProps} on:click on:m-keydown={dispatch}>
<slot {builder} />
</svelte:element>
</a>
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
<p data-testid="binding">{open}</p>
<button data-testid="toggle" on:click={() => (open = !open)}> toggle </button>

<div id="portalTarget" data-testid="portalTarget" />
<div id="portalTarget" data-testid="portalTarget"></div>
</main>
2 changes: 1 addition & 1 deletion packages/bits-ui/src/tests/combobox/ComboboxTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</Combobox.Content>
<Combobox.HiddenInput data-testid="hidden-input" />
</Combobox.Root>
<div data-testid="outside" />
<div data-testid="outside"></div>
<button data-testid="input-binding" on:click={() => (inputValue = "")}>
{#if inputValue === ""}
empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@
<button aria-label="radio-sub" data-testid="sub-radio-binding" on:click={() => (subRadio = "")}
>{subRadio}</button
>
<div id="portal-target" data-testid="portal-target" />
<div id="portal-target" data-testid="portal-target"></div>
</main>
2 changes: 1 addition & 1 deletion packages/bits-ui/src/tests/dialog/DialogTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
</Dialog.Root>
<p data-testid="binding">{open}</p>
<button data-testid="toggle" on:click={() => (open = !open)}>toggle</button>
<div id="portalTarget" data-testid="portalTarget" />
<div id="portalTarget" data-testid="portalTarget"></div>
</main>
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@
<button aria-label="radio-sub" data-testid="sub-radio-binding" on:click={() => (subRadio = "")}
>{subRadio}</button
>
<div id="portal-target" data-testid="portal-target" />
<div id="portal-target" data-testid="portal-target"></div>
</main>
2 changes: 1 addition & 1 deletion packages/bits-ui/src/tests/select/SelectTest.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</Select.Content>
<Select.Input data-testid="input" />
</Select.Root>
<div data-testid="outside" />
<div data-testid="outside"></div>
<button data-testid="open-binding" on:click={() => (open = !open)}>
{open}
</button>
Expand Down
8 changes: 4 additions & 4 deletions sites/docs/src/lib/components/api-ref/props-table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { parseMarkdown } from "$lib/utils/index.js";
export let props: PropObj<Record<string, unknown>>;
export let slot = false;
export let slotted = false;
$: propData = Object.entries(props).map(([name, prop]) => {
const { type, description, default: defaultVal, required } = prop as PropSchema;
Expand All @@ -18,7 +18,7 @@
<Table.Header>
<Table.Row class="w-1/4">
<Table.Head class="w-[38%] whitespace-nowrap pr-1"
>{slot ? "Slot" : ""} Property</Table.Head
>{slotted ? "Slot" : ""} Property</Table.Head
>
<Table.Head class="w-[22%] whitespace-nowrap pr-1">Type</Table.Head>
<Table.Head class="w-[40%] whitespace-nowrap">Description</Table.Head>
Expand All @@ -42,14 +42,14 @@
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html parseMarkdown(description)}
</p>
{#if !slot}
{#if !slotted}
<div class="mt-2">
<Code class="h-auto bg-background px-0">
Default:
{#if defaultVal}
{` ${defaultVal}`}
{:else}
<span aria-hidden> &nbsp;—— </span>
<span aria-hidden="true"> &nbsp;—— </span>
<span class="sr-only"> undefined </span>
{/if}
</Code>
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/api-section.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PropsTable props={schema.props} />
{/if}
{#if schema.slotProps}
<PropsTable slot props={schema.slotProps} />
<PropsTable slotted props={schema.slotProps} />
{/if}
{#if schema.dataAttributes && schema.dataAttributes.length}
<DataAttrsTable dataAttrs={schema.dataAttributes} />
Expand Down
4 changes: 2 additions & 2 deletions sites/docs/src/lib/components/component-preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class="absolute left-0 top-0 h-8 w-full rounded-[7px] bg-background dark:bg-muted"
in:send={{ key: "active" }}
out:receive={{ key: "active" }}
/>
></div>
{/if}
</Tabs.Trigger>
<Tabs.Trigger
Expand All @@ -66,7 +66,7 @@
class="absolute left-0 top-0 h-8 w-full rounded-[7px] bg-background dark:bg-muted"
in:send={{ key: "active" }}
out:receive={{ key: "active" }}
/>
></div>
{/if}
</Tabs.Trigger>
</Tabs.List>
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/demos/calendar-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
>
<div
class="absolute top-[5px] hidden size-1 rounded-full bg-foreground group-data-[today]:block group-data-[selected]:bg-background"
/>
></div>
{date.day}
</Calendar.Day>
</Calendar.Cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
>
<div
class="absolute top-[5px] hidden size-1 rounded-full bg-foreground transition-all group-data-[today]:block group-data-[selected]:bg-background"
/>
></div>
{date.day}
</DatePicker.Day>
</DatePicker.Cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{/if}
</div>
{/each}
<div aria-hidden class="px-1 text-muted-foreground">–⁠⁠⁠⁠⁠</div>
<div aria-hidden="true" class="px-1 text-muted-foreground">–⁠⁠⁠⁠⁠</div>
{#each segments.end as { part, value }}
<div class="inline-block select-none">
{#if part === "literal"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{/if}
</div>
{/each}
<div aria-hidden class="px-1 text-muted-foreground">–</div>
<div aria-hidden="true" class="px-1 text-muted-foreground">–</div>
{#each segments.end as { part, value }}
<div class="inline-block select-none">
{#if part === "literal"}
Expand Down Expand Up @@ -114,7 +114,7 @@
>
<div
class="absolute top-[5px] hidden size-1 rounded-full bg-foreground transition-all group-data-[today]:block group-data-[selected]:bg-background"
/>
></div>
{date.day}
</DateRangePicker.Day>
</DateRangePicker.Cell>
Expand Down
10 changes: 6 additions & 4 deletions sites/docs/src/lib/components/demos/popover-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
<div class="mr-2 flex items-center">
<div class="relative mr-2">
<span class="sr-only">Width</span>
<span aria-hidden class="absolute left-5 top-4 text-xxs text-muted-foreground"
>W</span
<span
aria-hidden="true"
class="absolute left-5 top-4 text-xxs text-muted-foreground">W</span
>
<input
type="number"
Expand All @@ -44,8 +45,9 @@
</div>
<div class="relative">
<span class="sr-only">Height</span>
<span aria-hidden class="absolute left-5 top-4 text-xxs text-muted-foreground"
>H</span
<span
aria-hidden="true"
class="absolute left-5 top-4 text-xxs text-muted-foreground">H</span
>
<input
type="number"
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/demos/progress-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<div
class="h-full w-full flex-1 rounded-full bg-foreground shadow-mini-inset transition-all duration-1000 ease-in-out"
style={`transform: translateX(-${100 - (100 * (value ?? 0)) / (100 ?? 1)}%)`}
/>
></div>
</Progress.Root>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
>
<div
class="absolute top-[5px] hidden size-1 rounded-full bg-foreground group-data-[today]:block group-data-[selected]:bg-background"
/>
></div>
{date.day}
</RangeCalendar.Day>
</RangeCalendar.Cell>
Expand Down
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/icons/switch-off.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
>
<span
class="pointer-events-none block size-[13px] shrink-0 translate-x-0 rounded-full bg-background shadow-mini transition-transform dark:border dark:border-border-input dark:shadow-mini"
/>
></span>
</div>
2 changes: 1 addition & 1 deletion sites/docs/src/lib/components/icons/switch-on.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
>
<span
class="pointer-events-none block size-[13px] shrink-0 translate-x-[10px] rounded-full bg-background dark:border-border-input dark:shadow-mini"
/>
></span>
</div>

0 comments on commit 98d5bd0

Please sign in to comment.