From 4d61d0357f861b8bcc5c4a462640943a19c6db66 Mon Sep 17 00:00:00 2001 From: Max Prilutskiy Date: Mon, 3 Aug 2020 16:45:27 +0300 Subject: [PATCH] fix: Focus inconsistency fixed --- src/core/views/widget.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/views/widget.js b/src/core/views/widget.js index 7ee53c96..2bd1c771 100644 --- a/src/core/views/widget.js +++ b/src/core/views/widget.js @@ -127,6 +127,7 @@ class Widget extends Component { this.reloadIframe = this.reloadIframe.bind(this) this.debouncedScroll = debounce(this.focusIframe, DEBOUNCE_WAIT, this) this.setIframeRef = this.setIframeRef.bind(this) + this.sendFocusMessageToIframe = this.sendFocusMessageToIframe.bind(this) } componentDidMount () { @@ -214,11 +215,9 @@ class Widget extends Component { if (this.props.enabledFullscreen) return const { iframeRef } = this.iframe - if (!iframeRef || !iframeRef.contentWindow) { return } - const isIframeInViewport = isElementInViewport(iframeRef) const canPostMessage = this.state.isFormReady && @@ -227,13 +226,20 @@ class Widget extends Component { iframeRef.contentWindow != null if (canPostMessage) { - iframeRef.contentWindow.postMessage('embed-focus', '*') - this.setState({ - isIframeFocused: true - }) + this.setState({ isIframeFocused: true }, this.sendFocusMessageToIframe) } } + sendFocusMessageToIframe () { + const { iframeRef } = this.iframe + if (!iframeRef) { return } + + setTimeout( + () => iframeRef.contentWindow.postMessage('embed-focus', '*'), + 100 + ) + } + render () { const { isFullscreen,