UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

27 lines (26 loc) 772 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeSetSelection = safeSetSelection; var _helpers = require("../../../shared/helpers.js"); const defer = typeof requestAnimationFrame !== 'undefined' ? cb => { requestAnimationFrame(cb); } : cb => { setTimeout(cb, 0); }; function safeSetSelection(element, selectionPosition) { if (document.activeElement === element || process.env.NODE_ENV !== 'production' && typeof jest !== 'undefined') { const select = () => { try { element.setSelectionRange(selectionPosition, selectionPosition); } catch (error) {} }; if ((0, _helpers.isAndroid)()) { defer(select); } else { select(); } } } //# sourceMappingURL=safeSetSelection.js.map