Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap order of bindings and event listeners #473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 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.

2 participants