-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed as not planned
Description
Describe the problem
Spreadable actions would be great for ergonomics in particular with components.
Describe the proposed solution
Removing the use:* directive in favor of a use* attribute in a move similar to the on:* directive -> on* attribute would allow spreadable actions.
- It could be added to the
HTMLAttributeinterface something like
export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, DOMAttributes<T> {
[actions: `use${string}`]: Action<T>
}- This way we can grab actions in a component
restattribute without having to manage actions in a particular way. Which makes our components future proof as we can later add more actions without reopening the component file + adding ause:directive
// Button.svelte
<script lang="ts">
// Action-ability is already in the type, nothing to do here
export let {children, ...rest}: HTMLButtonAttributes = $props();
</script>
<button {...rest}>{@render children()}</button>// +page.svelte
<Button useclickoutside={(node /* typed as HTMLButton */) => {...}}>click me</Button>- If the action takes params they can be passed in the
use*paramsattribute
// +page.svelte
<Button useclickoutside={(node, options = {message: "nope"}) => {...}} useclickoutsideparams={{message: "clicked outside"}}>click me</Button>- No dash (unlike
data-attributes) to avoid double quotes everywhere
Importance
would make my life easier
Azarattum
Metadata
Metadata
Assignees
Labels
No labels