UNPKG

@testing-library/user-event

Version:
30 lines (25 loc) 1.09 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var eventWrapper = require('../misc/eventWrapper.js'); var findClosest = require('../misc/findClosest.js'); var getActiveElement = require('./getActiveElement.js'); var isFocusable = require('./isFocusable.js'); var selection = require('./selection.js'); /** * Focus closest focusable element. */ function focus(element) { const target = findClosest.findClosest(element, isFocusable.isFocusable); const activeElement = getActiveElement.getActiveElement(element.ownerDocument); if ((target !== null && target !== void 0 ? target : element.ownerDocument.body) === activeElement) { return; } else if (target) { eventWrapper.eventWrapper(()=>target.focus()); } else { eventWrapper.eventWrapper(()=>{ var ref; return (ref = activeElement) === null || ref === void 0 ? void 0 : ref.blur(); }); } selection.updateSelectionOnFocus(target !== null && target !== void 0 ? target : element.ownerDocument.body); } exports.focus = focus;