Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can pass my event handler as $$restProps to child component

I have an input component like this:

<script lang="ts"></script>

<div class="wrap-input">
  <input
    class='input'
    type="text"
    {...$$restProps}
  />
</div>

<style lang="scss">
  // some styles
</style>

I used input component on the parent:

<script lang="ts">

  // function event handler
  const onKeyUp = (event) => {
    console.log(event)
  }
</script>

<main>
  <Input
    on:keyup={onKeyUp} // How I can send this event to input component as $$restProps
    className="input-todo"
    placeholder="What needs to be done ?"
  />
</main>

<style lang="scss">
  // some styles
</style>

like image 852
aldenn Avatar asked Oct 13 '25 10:10

aldenn


1 Answers

Based on the event-forwarding tutorial,
on:keyup event directive without a value means 'forward all keyup events', so you can change your Input component to:

<div class="wrap-input">
  <input
    class='input'
    type="text"
    on:keyup
    {...$$restProps}
  />
</div>

Example

like image 129
CD.. Avatar answered Oct 15 '25 09:10

CD..



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!