Skip to main content

onchange

Description

Fires on change of the value in textarea

Usage

onchange?: (ev: { value: string; input?: boolean }) => void;

Parameters

  • value - (required) the value of the input
  • input - (optional) - (optional) true, if a value is being typed by a user (check details below)

Example

Tracking user input:

<script>
import { Textarea } from "@svar-ui/svelte-textarea";

const onchange = ({ value, input }) => {
console.log("Textarea value:", value, "Changed by user:", !!input);
};
</script>

<Textarea onchange={onchange} />

Details

The handler function receives the new value of the counter typed in the input. The received object may also contain input:true, depending on the fired HTML input event:

  • if the input event of the HTML input is caught (a number is being typed), the change event of the control will have input:true
  • if the change event of the HTML input is caught (a user has applied changes), the change event of the control won't have the input property

Related article: Catching the change of the value