Skip to content

Commit 62296f2

Browse files
author
Max Prilutskiy
authored
fix(DIST-353): Focus inconsistency fixed (#66)
1 parent c351c33 commit 62296f2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/core/views/widget.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class Widget extends Component {
127127
this.reloadIframe = this.reloadIframe.bind(this)
128128
this.debouncedScroll = debounce(this.focusIframe, DEBOUNCE_WAIT, this)
129129
this.setIframeRef = this.setIframeRef.bind(this)
130+
this.sendFocusMessageToIframe = this.sendFocusMessageToIframe.bind(this)
130131
}
131132

132133
componentDidMount () {
@@ -214,11 +215,9 @@ class Widget extends Component {
214215
if (this.props.enabledFullscreen) return
215216

216217
const { iframeRef } = this.iframe
217-
218218
if (!iframeRef || !iframeRef.contentWindow) {
219219
return
220220
}
221-
222221
const isIframeInViewport = isElementInViewport(iframeRef)
223222
const canPostMessage =
224223
this.state.isFormReady &&
@@ -227,13 +226,20 @@ class Widget extends Component {
227226
iframeRef.contentWindow != null
228227

229228
if (canPostMessage) {
230-
iframeRef.contentWindow.postMessage('embed-focus', '*')
231-
this.setState({
232-
isIframeFocused: true
233-
})
229+
this.setState({ isIframeFocused: true }, this.sendFocusMessageToIframe)
234230
}
235231
}
236232

233+
sendFocusMessageToIframe () {
234+
const { iframeRef } = this.iframe
235+
if (!iframeRef) { return }
236+
237+
setTimeout(
238+
() => iframeRef.contentWindow.postMessage('embed-focus', '*'),
239+
100
240+
)
241+
}
242+
237243
render () {
238244
const {
239245
isFullscreen,

0 commit comments

Comments
 (0)