mirror of
https://github.com/maunium/stickerpicker.git
synced 2025-02-06 23:35:33 +01:00
handle focus for iframe
This commit is contained in:
parent
26ab8e2821
commit
9b87f7436f
@ -32,16 +32,34 @@ export class SearchBox extends Component {
|
||||
this.value = props.value
|
||||
this.onSearch = props.onSearch
|
||||
this.onReset = props.onReset
|
||||
this.hasBeenFocused = false
|
||||
|
||||
this.focusInput = this.focusInput.bind(this)
|
||||
this.search = this.search.bind(this)
|
||||
this.clearSearch = this.clearSearch.bind(this)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// hack required for firefox
|
||||
focusInput() {
|
||||
const inputInWebView = document.querySelector('.search-box input')
|
||||
if (inputInWebView && this.autofocus) {
|
||||
inputInWebView.focus()
|
||||
this.hasBeenFocused = true
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.focusInput()
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
// check if we're in an iframe (Element desktop)
|
||||
if (window.self !== window.top) {
|
||||
// check if the iframe is not closed
|
||||
if (document.querySelector('.search-box').offsetParent === null) {
|
||||
this.focusInput()
|
||||
} else {
|
||||
this.hasBeenFocused = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user