diff --git a/src/index.ts b/src/index.ts index 5c8c7fc6..98ecf871 100644 --- a/src/index.ts +++ b/src/index.ts @@ -473,16 +473,16 @@ export class EmojiButton { this.focusTrap.activate(); - const initialFocusElement = this.pickerEl.querySelector( - this.options.showSearch && this.options.autoFocusSearch - ? `.${CLASS_SEARCH_FIELD}` - : `.${CLASS_EMOJI}[tabindex="0"]` - ) as HTMLElement; - initialFocusElement.focus(); - setTimeout(() => { document.addEventListener('click', this.onDocumentClick); document.addEventListener('keydown', this.onDocumentKeydown); + + const initialFocusElement = this.pickerEl.querySelector( + this.options.showSearch && this.options.autoFocusSearch + ? `.${CLASS_SEARCH_FIELD}` + : `.${CLASS_EMOJI}[tabindex="0"]` + ) as HTMLElement; + initialFocusElement.focus(); }); this.emojiArea.reset();