History

Improve tab/focus navigation of doc picker

Thibaut Courouble committed 10 years ago

Commit a02dd3b1 parent aa6b9281 file · +11 −2Browse files

Unified · Split

assets/javascripts/views/sidebar/doc_picker.coffee+11−2
@@ -30,6 +30,7 @@ class app.views.DocPicker extends app.View · 29 unmodified lines
3030 @empty()
3131 app.appCache?.off 'progress', @onAppCacheProgress
3232 $.off @el, 'focus', @onDOMFocus, true
33+ @focusEl = null
3334 return
3435
3536 render: ->
@@ -101,8 +102,16 @@ class app.views.DocPicker extends app.View · 65 unmodified lines
101102 else if target.classList.contains(app.views.ListFold.targetClass)
102103 target.blur()
103104 unless @mouseDown and @mouseDown > Date.now() - 100
104− @listFold.open(target) unless target.classList.contains(app.views.ListFold.activeClass)
105− $('input', target.nextElementSibling).focus()
105+ if @focusEl is $('input', target.nextElementSibling)
106+ @listFold.close(target) if target.classList.contains(app.views.ListFold.activeClass)
107+ prev = target.previousElementSibling
108+ prev = prev.previousElementSibling until prev.tagName is 'LABEL' or prev.classList.contains(app.views.ListFold.targetClass)
109+ prev = $.makeArray($$('input', prev.nextElementSibling)).pop() if prev.classList.contains(app.views.ListFold.activeClass)
110+ @delay -> prev.focus()
111+ else
112+ @listFold.open(target) unless target.classList.contains(app.views.ListFold.activeClass)
113+ @delay -> $('input', target.nextElementSibling).focus()
114+ @focusEl = target
106115 return
107116
108117 onEnter: =>