Comments (6)
use chidren and props
from svelte.
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}>
from svelte.
^ 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.
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.
from svelte.
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.
Ah, this seems to be an issue with the internal init_select
logic. Digging into it now.
from svelte.
Related Issues (20)
- Addition assignment operator (+=) broken
- "node is null" when manipulating an array state in a Snippet HOT 4
- Styles are not removed after transition slide end HOT 1
- Svelte 5 migration: statements should be reordered
- Svelte 5: leaking private implementation details ($$events, $$slots) HOT 3
- Svelte 5: Snippets aren't deconflicted HOT 5
- Svelte5: snippets components invoked multiple times HOT 4
- The exported names of the reactive Map, Set, and others conflict with platform globals HOT 6
- Svelte 5: non-keyed each blocks do not retain text direction in elements with `dir="auto"` HOT 2
- Svelte 5: <select>s don't properly set their initial value if the option value is an object HOT 4
- Svelte 5: Changing of the items in #each block breaks order of the element HOT 1
- Using a generic type as an argument to a Snippet breaks types generation of a component HOT 4
- Svelte 5: Optimize reads to getters HOT 2
- Svelte 5: Unexpected character '@' when using *.svelte.ts with Decorators and $state and importing in client HOT 5
- Improve message for error "Nesting selectors can only be used inside a rule"
- Svelte 5: Regression since 5.0.0-next.162 with #each or render HOT 1
- Svelte v4 components under Svelte v5: Internals leaked through slot variables when defined in component HOT 7
- Svelte 5 - Relax Variable Naming Restrictions on $-Prefixed Variables HOT 7
- Svelte 5: Components in #if blocks don't trigger their $effect rune HOT 9
- False positive error: rune outside svelte HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.