UNPKG

@wordpress/components

Version:
59 lines (49 loc) 1.58 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = FocusableIframe; var _element = require("@wordpress/element"); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _compose = require("@wordpress/compose"); /** * WordPress dependencies */ function FocusableIframe({ iframeRef, ...props }) { const fallbackRef = (0, _element.useRef)(); const ref = (0, _compose.useMergeRefs)([iframeRef, fallbackRef]); (0, _element.useEffect)(() => { const iframe = fallbackRef.current; const { ownerDocument } = iframe; const { defaultView } = ownerDocument; /** * Checks whether the iframe is the activeElement, inferring that it has * then received focus, and calls the `onFocus` prop callback. */ function checkFocus() { if (ownerDocument.activeElement !== iframe) { return; } iframe.focus(); } defaultView.addEventListener('blur', checkFocus); return () => { defaultView.removeEventListener('blur', checkFocus); }; }, []); // Disable reason: The rendered iframe is a pass-through component, // assigning props inherited from the rendering parent. It's the // responsibility of the parent to assign a title. // eslint-disable-next-line jsx-a11y/iframe-has-title return (0, _element.createElement)("iframe", (0, _extends2.default)({ ref: ref }, props)); } //# sourceMappingURL=index.js.map