UNPKG

app-walkthrough

Version:

An intuitive guided walkthrough library with UI highlighting and voice narration for web apps.

33 lines (32 loc) 1.08 kB
import { setValueNatively } from "./utils"; export function handleInputAction(element, step) { const validActionTypes = new Set([ "input", "select", "click", "dropdownClick", "dropdownSearchClick", "multiSelect", "uploadFile", "keyboard", ]); if (!validActionTypes.has(step.actionType) || !("input" in step)) return; const inputInside = findInsideInput(element); const inputElement = inputInside || element; console.log("Input element found:", inputElement); const rawValue = typeof step.input === "string" ? step.input : Array.isArray(step.input) && step.input.length > 0 ? step.input[0] : ""; const valueToSet = rawValue != null ? rawValue.toString() : ""; setValueNatively(inputElement, valueToSet); } export function findInsideInput(element) { if (element.tagName.toLowerCase() === "input") { return element; } const descendantInput = element.querySelector("input, textarea"); return descendantInput; }