Code Monkey home page Code Monkey logo

Comments (6)

Neptunium1129 avatar Neptunium1129 commented on July 17, 2024 1

use chidren and props

REPL

from svelte.

brunnerh avatar brunnerh commented on July 17, 2024

Apparently something in the {...$$restProps} logic causes the issue, i.e. without it the option will be selected.

No rest props to rest props diff
 import * as $ from "svelte/internal/client";

-var root = $.template(`<select name="pets" id="pet-select1"><!></select>`);
+var root = $.template(`<select><!></select>`);

 export default function Select($$anchor, $$props) {
+       const $$sanitized_props = $.legacy_rest_props($$props, [
+               "children",
+               "$$slots",
+               "$$events",
+               "$$legacy"
+       ]);
+
+       const $$restProps = $.legacy_rest_props($$sanitized_props, []);
        var select = root();
+       let attributes;
+
+       $.init_select(select, () => attributes.value);
+
        var node = $.child(select);

        $.slot(node, $.default_slot($$props), {}, null);
+
+       $.template_effect(() => {
+               attributes = $.set_attributes(
+                       select,
+                       attributes,
+                       {
+                               name: "pets",
+                               id: "pet-select1",
+                               ...$$restProps
+                       },
+                       true,
+                       ""
+               );
+
+               if ("value" in attributes) {
+                       $.select_option(select, attributes.value);
+               }
+       });
+
        $.append($$anchor, select);
 }

Migrating the code to the runes equivalent does not affect the result.


Explicit declaration and setting of value to '' by default would be a workaround:

<script>
	export let value = '';
</script>
<select name="pets" id="pet-select1" {value} {...$$restProps}>

REPL

from svelte.

jrmoynihan avatar jrmoynihan commented on July 17, 2024

^ correct solution above. Svelte 5 == children snippets instead of slots.

They're also not placeholders. Those are actual options in the <select> with a value of an empty string and can set the value of the select element (or component, in your case), unlike the placeholder attribute on input elements, which never get bound to the value of the input.

from svelte.

brunnerh avatar brunnerh commented on July 17, 2024

Whether it's legacy or runes does not matter, it's broken either way.
The code given in @Neptunium1129 REPL is wrong, it sets a non-existent property called rest instead of spreading it.

REPL with spread

from svelte.

shinokada avatar shinokada commented on July 17, 2024

For a legacy project, I can't use children and $props().
As you can see in my demo, it is not a runes project.

from svelte.

trueadm avatar trueadm commented on July 17, 2024

Ah, this seems to be an issue with the internal init_select logic. Digging into it now.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.