github.com/Theta-Dev/Talon@v0.0.0-20211018130634-ff179e19fa9a/ui/menu/src/util/inputDirectives.ts (about)

     1  /** Selects the text inside a text node when the node is focused */
     2  import type {SvelteActionRes} from "./types"
     3  
     4  export function selectTextOnFocus(node: HTMLInputElement): SvelteActionRes {
     5  	const handleFocus = () => {
     6  		node && typeof node.select === "function" && node.select()
     7  	}
     8  
     9  	node.addEventListener("focus", handleFocus)
    10  
    11  	return {
    12  		destroy() {
    13  			node.removeEventListener("focus", handleFocus)
    14  		},
    15  	}
    16  }