Start Typing

Create a typing listener for the given element.

Usage

<script>
    import {startTyping} from "@sveu/actions"

    function fn(element, event){
         if(element !== document.activeElement) element.focus()
    }
</script>

<input use:startTyping="{fn}" />
<script>
    import {startTyping} from "@sveu/actions"

    function fn(element, event){
         if(element !== document.activeElement) element.focus()
    }
</script>

<input use:startTyping="{fn}" />
svelte

Example

<script>
    import {startTyping} from "@sveu/actions" 

    function fn(element, event){
         if(element !== document.activeElement) element.focus() 
    }
</script>

<input placeholder="Search....." use:startTyping="{fn}" />  <!--   -->

<input placeholder="Enter your name"  />
<script>
    import {startTyping} from "@sveu/actions" 

    function fn(element, event){
         if(element !== document.activeElement) element.focus() 
    }
</script>

<input placeholder="Search....." use:startTyping="{fn}" />  <!--   -->

<input placeholder="Enter your name"  />
svelte
1
2
3
4
5
6
7
8
9
10
11
Click fold/expand code

API

Arguments

Name Description Type Required
fn A function to be called when the user types a character. (element: T, event: KeyboardEvent) => void Yes


TIP

If you use typescript, you need to add ./node_modules/@sveu/actions/events.d.ts to your tsconfig.json file.

{
    ...

    "include": [
        ...
        "./node_modules/@sveu/actions/events.d.ts"
    ]
    ...
}
{
    ...

    "include": [
        ...
        "./node_modules/@sveu/actions/events.d.ts"
    ]
    ...
}
json