UNPKG

tav-ui

Version:
26 lines (23 loc) 869 B
import { nextTick } from 'vue'; import '../../utils/index2.mjs'; import { isNullOrUnDef } from '../../utils/is2.mjs'; const getInput = (el) => el instanceof HTMLInputElement ? el : el.querySelector("input") || el.querySelector("textarea"); const AutoFocusDirective = { mounted: async (el, { arg }) => { await nextTick(); const relEle = arg ? el : getInput(el); if (!isNullOrUnDef(relEle)) { relEle.focus(); const className = relEle.getAttribute("class"); const value = relEle.value; if (!Number.isNaN(value) && className && className.indexOf("number-input") > -1) { relEle?.setSelectionRange(0, 1e3); } } } }; function setupAutoFocusDirective(app) { app.directive("autoFocus", AutoFocusDirective); } export { AutoFocusDirective as default, setupAutoFocusDirective }; //# sourceMappingURL=autoFocus2.mjs.map