-
-
Notifications
You must be signed in to change notification settings - Fork 265
Open
Description
Let's add a way to pass actions to components, especially Form and FluidForm.
Rejected Proposal 1: `use` prop
This is flawed since you cannot specify <form action={something} />
Proposed prop name is use
. Example component:
<script>
export let use
</script>
<div use:use>
Hello
</div>
Example usage:
<script>
import Component from './Component2.svelte'
const action = () => console.log('action')
</script>
<Component use={action} />
Example: https://svelte.dev/repl/e24d07853ebe4773b1ab818ad60536a2?version=3.55.0
Proposal 2: formAttributes
Specify a formAttributes
prop. If present, will render an outer <form>
element.
- Typed as
HTMLFormAttributes | { useAction: () => {} }
- If defined, renders a
<form>
element, wrapping the target component - If
useAction
is defined, it will be desconstructed fromformAttributes
and applied to the form element withuse:useAction
- For components with multiple interaction points, a more descriptive name can be used. For example, with
Pagination
we can haveitemsPerPageFormAttributes
for the 'items per page' dropdown (though an 'update' button may need to be rendered alongside<select>
elements) - Supplementary documentation should be added explaining why these features exist and how to best use them
<Button formAttributes={{ action: '?/update', useAction: enhance }}>Update</Button>
Demo: https://svelte.dev/repl/a1f1eec629f141a9a3373dafa075dd8a?version=3.55.0
Related #1622
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request