Handle TextEditorElement::focus() while parent is being attached

Fixes atom/autocomplete#61
This commit is contained in:
Max Brunsfeld
2015-01-09 15:00:29 -08:00
parent 19bf64f3cd
commit f9bde050b4
2 changed files with 19 additions and 5 deletions

View File

@@ -98,6 +98,22 @@ describe "TextEditorElement", ->
document.body.focus()
expect(blurCalled).toBe true
describe "when focused while a parent node is being attached to the DOM", ->
class ElementThatFocusesChild extends HTMLDivElement
attachedCallback: ->
@firstChild.focus()
document.registerElement("element-that-focuses-child",
prototype: ElementThatFocusesChild.prototype
)
it "proxies the focus event to the hidden input", ->
element = new TextEditorElement
parentElement = document.createElement("element-that-focuses-child")
parentElement.appendChild(element)
jasmineContent.appendChild(parentElement)
expect(element.shadowRoot.activeElement).toBe element.shadowRoot.querySelector('input')
describe "when the themes finish loading", ->
[themeReloadCallback, initialThemeLoadComplete, element] = []

View File

@@ -63,7 +63,8 @@ class TextEditorElement extends HTMLElement
@buildModel() unless @getModel()?
@mountComponent() unless @component?.isMounted()
@component.checkForVisibilityChange()
@focus() if @focusOnAttach
if this is document.activeElement
@focused()
@emitter.emit("did-attach")
detachedCallback: ->
@@ -128,10 +129,7 @@ class TextEditorElement extends HTMLElement
@component = null
focused: ->
if @component?
@component.focused()
else
@focusOnAttach = true
@component?.focused()
blurred: (event) ->
unless @useShadowDOM