Skip to content

Commit

Permalink
fix(SelectField): Properly handle option selection with option slot d…
Browse files Browse the repository at this point in the history
…efined using `<svelte:fragment slot="option">` or `<div slot="option">` (#512)
  • Loading branch information
techniq authored Nov 4, 2024
1 parent df4e367 commit e47763d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-dingos-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

fix(SelectField): Properly handle option selection with option slot defined using `<svelte:fragment slot="option">` or `<div slot="option">`
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

if (e.target instanceof HTMLElement) {
// Find slot parent of click target option, fallback to `e.target` if slot is not overridden
// Use `.options > ` in case slot is nested (ex. GraphQLSelect with slot)
const slotEl = e.target.closest('.options > [slot=option]') ?? e.target;
// Use `.options > *` in case slot is nested (ex. `<svelte:fragment slot="option">` vs `<div slot="option">`)
const slotEl = e.target.closest('.options > *') ?? e.target;
// Find the index of the clicked on element (ignoring group headers)
const optionIndex = slotEl
? [...menuOptionsEl.children]
Expand Down

0 comments on commit e47763d

Please sign in to comment.