Skip to content

Commit 73fe3df

Browse files
committed
fix: ensure element is defined when calling addTabindexIfNoItemsSelected by passing it
This fix should be even much more better than the last one, cause this one will (hopefully) work.
1 parent c9a3f9c commit 73fe3df

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/list/src/Item.svelte

+6-12
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
<script lang="ts">
6868
import type { SvelteComponent } from 'svelte';
69-
import { onMount, onDestroy, getContext, setContext, tick } from 'svelte';
69+
import { onMount, onDestroy, getContext, setContext } from 'svelte';
7070
import { get_current_component } from 'svelte/internal';
7171
import type {
7272
SMUICheckboxInputAccessor,
@@ -179,13 +179,13 @@
179179
// Reset separator context, because we aren't directly under a list anymore.
180180
setContext('SMUI:separator:context', undefined);
181181
182-
onMount(async () => {
182+
onMount(() => {
183183
// Tabindex needs to be '0' if this is the first non-disabled list item, and
184184
// no other item is selected.
185185
186186
if (!selected && !nonInteractive) {
187187
let first = true;
188-
let el = element;
188+
let el = element.getElement();
189189
while (el.previousSibling) {
190190
el = el.previousSibling;
191191
if (
@@ -200,9 +200,8 @@
200200
if (first) {
201201
// This is first, so now set up a check that no other items are
202202
// selected.
203-
await tick();
204-
addTabindexIfNoItemsSelectedRaf = window.requestAnimationFrame(
205-
addTabindexIfNoItemsSelected
203+
addTabindexIfNoItemsSelectedRaf = window.requestAnimationFrame(() =>
204+
addTabindexIfNoItemsSelected(el)
206205
);
207206
}
208207
}
@@ -336,14 +335,9 @@
336335
}
337336
}
338337
339-
function addTabindexIfNoItemsSelected() {
340-
if (!element) {
341-
return;
342-
}
343-
338+
function addTabindexIfNoItemsSelected(el: HTMLElement) {
344339
// Look through next siblings to see if none of them are selected.
345340
let noneSelected = true;
346-
let el = element.getElement();
347341
while (el.nextElementSibling) {
348342
el = el.nextElementSibling as HTMLElement;
349343
if (

0 commit comments

Comments
 (0)