Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Swap order of bindings and event listeners#473

Open
shaun-wild wants to merge 1 commit intobestguy:masterfrom
shaun-wild:master
Open

Swap order of bindings and event listeners#473
shaun-wild wants to merge 1 commit intobestguy:masterfrom
shaun-wild:master

Conversation

@shaun-wild
Copy link

@shaun-wild shaun-wild commented Apr 1, 2022

Summary

This PR swaps the attributes for binds and events in the Input and FormCheck components.

The Problem

As it turns out, the order of these attributes actually matters in the input, select etc components. If the event listener is listed before the bind, the bound value will not be up to date when the event listener is called.

E.g.

<input on:change={xxx} bind:value={yyy} />

and

<input bind:value={yyy} on:change={xxx} />

function differently, in the first example, yyy will not be the correct value in the event listener.

The Solution

Considering there is currently no way to specify the order of attributes on sub-components, I think it makes more sense to use a sensible default.


Wasn't really sure how to test this without creating a test component. Please someone let me know if there is a better way to test this.

@shaun-wild
Copy link
Author

This fixes #461 and is a replacement for #468.

@clemens-tolboom
Copy link

Allowing different ordering is a feature of svelte but a bug for sveltestrap.

See comment #461 (comment)

This is a know 'bug' sveltejs/svelte#4616 but it seems to be a feature and has a merged PR sveltejs/svelte#6887 documenting it.

See just above https://svelte.dev/docs#template-syntax-element-directives-bind-property-binding-select-value

@shaun-wild
Copy link
Author

shaun-wild commented Apr 2, 2022

I have created an issue on the official svelte repo, see sveltejs/svelte#7415.

Hopefully there will be a nicer fix in future.

@clemens-tolboom
Copy link

I have created an issue on the official svelte repo, see sveltejs/svelte#7415.

(huh) that's why I said

Allowing different ordering is a feature of svelte

as it is not a bug in Svelte.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants