Skip to content

Conversation

@Uzair-Ahmed-Shah
Copy link

Closes #17280

This PR fixes an issue where the selected property of options in a <select> element would not update correctly when the multiple attribute was toggled dynamically (e.g., <select {multiple}>).

The Problem

Previously, the runtime MutationObserver in select.js only watched for changes to the value attribute. It ignored changes to the multiple attribute. Consequently, when multiple changed from false to true (or vice versa), the selection logic was not re-evaluated, leading to inconsistent DOM states where options had selected attributes but selected properties set to false.

Additionally, the compiler explicitly forbade using a dynamic multiple attribute with bind:value, throwing an attribute_invalid_multiple error.

The Solution

  1. Runtime: Updated the MutationObserver in packages/svelte/src/internal/client/dom/elements/bindings/select.js to include 'multiple' in its attributeFilter. This ensures the selection logic runs whenever the multiple attribute changes.
  2. Compiler: Removed the attribute_invalid_multiple validation in BindDirective.js and its definition in errors.js, allowing dynamic multiple attributes to be used with bind:value.

Tests

  • Added a new regression test case: packages/svelte/tests/runtime-runes/samples/select-multiple-dynamic-attribute.
    • This test toggles the multiple attribute and asserts that select.multiple and option.selected properties update correctly.
  • Removed the obsolete validator test binding-select-multiple-dynamic which asserted the now-removed error.
  • Verified that all select-related tests in packages/svelte/tests/runtime-runes pass.

Checklist

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).
  • Run the tests with pnpm test and lint the project with pnpm lint.

@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: 94fe55c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Playground

pnpm add https://pkg.pr.new/svelte@17306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Options of <select multiple={true}> have incorrect selected property value

1 participant