fleetio_spark 0.2.28 → 0.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ae67716c57e2a7d14b83575192dbb948f5aee51a653a3ec07a79fa54ec1bd54
4
- data.tar.gz: b995d27caef6905dc0b8030d16097438ac1883118097f222d57f7a033d715c85
3
+ metadata.gz: 3640eeaf1e8c576f9ba70590de9dd65808b37b9222915ef949d3681cfc2df49b
4
+ data.tar.gz: b3845797d1b2a9dea6bebc9392a96e820cdb9d97473e49f428fa00c689f866ca
5
5
  SHA512:
6
- metadata.gz: b593cd1e85c41b3ee0f4fa67154036c93419cc5e2c4d59fcdbbef22da2220c68738e665c94dd1b261b713b0186e6cd792d5f2970b5c57f3376464c356488cc2d
7
- data.tar.gz: 655489cb5b0716f7fb5debc574cb6a0efb816972dbc7e5a3b0b76621d08611c2284a9289fb505594b6200194ecb5d5b7657f1ce02ef3c5520ddc26130e6a1b6a
6
+ metadata.gz: 0dd3669666d16c9c9fd90c60c7ccd486ac6793645107d29d83ca8594aee1e8d687951fcf3b38348ea78ced5fd33b30d54fb8398c79cd49b68bc044f36f28ab6f
7
+ data.tar.gz: 1047c7d294fbe1b0e9c234cdef2bf6f6f3ef86111102eac9ef463de2cd1d00250578a9600374e5eb2d5beab22cd12316703c70a488b00de00df47b66deeecebe
@@ -246,6 +246,7 @@ function navClick(event) {
246
246
  }
247
247
 
248
248
  function navKey(event) {
249
+ // Find the active panel in the stack where the navigation event should be triggered.
249
250
  var panel = event.currentTarget.closest('[data-stack="root"]').querySelector('[data-stack-index][aria-hidden="false"]')
250
251
  if (!panel) { return }
251
252
 
@@ -1,6 +1,6 @@
1
1
  // Purpose: Toggles expansion of tree nav and stores cookies to retain state
2
2
  //
3
- // Usage:
3
+ // For Cookies to be set:
4
4
  // - Trees must have a [data-tree='tree-key']
5
5
  // - Nodes are named by [data-node='node-name']
6
6
  //
@@ -12,7 +12,7 @@ var toolbox = require('@spark-engine/toolbox'),
12
12
  cookie = require('../../_cookie'),
13
13
  Event = require('@spark-engine/event')
14
14
 
15
- function setCookie (node) {
15
+ function setCookie(node) {
16
16
  if (node.dataset.node) {
17
17
  var tree = node.closest('[data-tree]')
18
18
  if (tree) {
@@ -23,30 +23,31 @@ function setCookie (node) {
23
23
  }
24
24
  }
25
25
 
26
- function click (event) {
26
+ function click(event) {
27
27
  toggleNode(event.currentTarget)
28
28
  }
29
29
 
30
+ // Expand or collapse the current tree node
30
31
  function toggleNode(target) {
31
- parent = target.parentElement,
32
- expanded = parent.getAttribute('aria-expanded')
32
+ var parent = target.closest('[aria-expanded]'),
33
+ expanded = parent.getAttribute('aria-expanded') == 'true'
33
34
 
34
35
  // Add a classname to indicate that it was manually triggered
35
36
  // This allows for animating interactions, but not other attribute changes
36
37
  parent.classList.add('triggered')
37
- toggleExpansion(parent, expanded != 'true')
38
- select(target)
38
+ toggleExpansion(parent, !expanded)
39
39
 
40
40
  setCookie(parent)
41
41
  }
42
42
 
43
+ // Set aria-expanded and toggle tabindex values based on expansion
43
44
  function toggleExpansion(el, expanded) {
44
45
  el.setAttribute('aria-expanded', expanded)
45
46
  setupItemTabIndex(el)
46
47
  }
47
48
 
48
49
  // Sets tree nav state based off of cookies
49
- function restoreNav () {
50
+ function restoreNav() {
50
51
  toolbox.each(document.querySelectorAll('[data-tree]'), function(tree) {
51
52
  var key = tree.dataset.tree
52
53
  if (key) {
@@ -65,90 +66,115 @@ function restoreNav () {
65
66
  })
66
67
  }
67
68
 
69
+ // Enables keyboard navigation of a nav tree
70
+ //
71
+ // `space` - toggles tree node triggers
72
+ // `right arrow` - opens nodes and navigates inward
73
+ // `left arrow` - closes nodes and navigates outward
74
+ // `up arrow` - moves to previous visible element
75
+ // `down arrow` - moves to next visible element
76
+ //
68
77
  function navigateTree(event) {
69
78
  var item = document.activeElement
70
79
  if (!item) return
71
80
 
81
+ // Find the parent tree item
72
82
  var tree = item.closest('[role="tree"]')
73
83
  if (!tree) return
74
84
 
75
- var trigger = item.matches('.tree-trigger')
76
-
77
- if (trigger) {
85
+ // Is the item a trigger which opens nodes?
86
+ if (item.matches('.tree-trigger')) {
78
87
  var expanded = item.parentElement.getAttribute('aria-expanded') != 'false'
79
88
 
89
+ // Space toggles node which trigger points to
80
90
  if (Event.key.isPressed('space')) {
81
- toggleNode(item)
82
91
  event.preventDefault()
92
+ return toggleNode(item)
83
93
  }
84
94
 
95
+ // Expand or move to the first item in the node
85
96
  if (Event.key.isPressed('right')) {
86
97
  event.preventDefault()
87
- if (expanded) return select(getNextItem(tree, item))
98
+ if (expanded) return focus(getNextItem(tree, item))
88
99
  else return toggleNode(item)
89
100
  }
90
101
 
102
+ // Collapse or move up the parent node
91
103
  if (Event.key.isPressed('left')) {
92
104
  event.preventDefault()
93
105
  if (expanded) return toggleNode(item)
94
- else return select(getUpwardItem(tree, item))
106
+ else return focus(getUpwardItem(tree, item))
95
107
  }
96
108
  }
97
109
 
110
+ // Move to next visible item in the tree
98
111
  if (Event.key.isPressed('down')) {
99
112
  event.preventDefault()
100
- select(getNextItem(tree, item))
113
+ focus(getNextItem(tree, item))
101
114
  }
102
115
 
103
- if (Event.key.isPressed('left')) {
116
+ // Move to previous visible item in the tree
117
+ else if (Event.key.isPressed('up')) {
104
118
  event.preventDefault()
105
- select(getUpwardItem(tree, item))
119
+ focus(getPreviousItem(tree, item))
106
120
  }
107
121
 
108
- else if (Event.key.isPressed('up')) {
122
+ // Move outward in tree
123
+ else if (Event.key.isPressed('left')) {
109
124
  event.preventDefault()
110
- select(getPreviousItem(tree, item))
125
+ focus(getUpwardItem(tree, item))
111
126
  }
112
127
  }
113
128
 
114
- function select(el) {
115
- if (!el) return
116
- el.focus()
129
+ // Focus on element (if able)
130
+ function focus(el) {
131
+ if (el) el.focus()
117
132
  }
118
133
 
134
+ // Find next focusable item
119
135
  function getNextItem(tree, item) {
120
- items = getSelectableItems(tree)
136
+ items = getFocusableItems(tree)
121
137
  return items[ items.indexOf(item) + 1]
122
138
  }
123
139
 
140
+ // Find previous focusable item
124
141
  function getPreviousItem(tree, item) {
125
- items = getSelectableItems(tree)
142
+ items = getFocusableItems(tree)
126
143
  return items[ items.indexOf(item) - 1]
127
144
  }
128
145
 
146
+ // Walk up the tree to the tree trigger
129
147
  function getUpwardItem(tree, item) {
130
148
  var upward = item.parentElement.closest('[aria-expanded]')
131
149
  if (upward) return upward.querySelector('.tree-trigger')
132
150
  }
133
151
 
134
- function getSelectableItems(tree) {
135
- return Array.prototype.filter.call(tree.querySelectorAll('[tabindex]'), function(el) {
152
+ // Find all focusable items in a nav tree
153
+ function getFocusableItems(tree) {
154
+ // Filter out items in collapsed nodes
155
+ return Array.prototype.filter.call(tree.querySelectorAll('a, [tabindex]'), function(el) {
136
156
  return !el.closest('[aria-expanded="false"] [role="group"]')
137
157
  })
138
158
  }
139
159
 
140
- // Remove hidden items from the tabindex
160
+ // Ensure hidden items are not focasable
141
161
  function setupItemTabIndex(tree) {
142
- toolbox.each(tree.querySelectorAll('a'), function(el) {
162
+ toolbox.each(tree.querySelectorAll('a, [tabindex]'), function(el) {
143
163
  if (el.closest('[aria-expanded="false"] [role="group"]')) {
144
164
  el.setAttribute('tabindex', -1)
145
165
  } else {
146
- el.setAttribute('tabindex', 0)
166
+ // Don't set a tabindex for anchor elements
167
+ // They already participate in tabindex and tabindex=0
168
+ // will change their click behavior
169
+ if (el.matches('a')) {
170
+ el.removeAttribute('tabindex')
171
+ } else {
172
+ el.setAttribute('tabindex', 0)
173
+ }
147
174
  }
148
175
  })
149
176
  }
150
177
 
151
-
152
178
  function setup() {
153
179
  Event.ready(function() {
154
180
 
@@ -1,6 +1,6 @@
1
1
  [role=tree] {
2
- [role=group] {
3
- overflow: hidden;
2
+ [aria-expanded=false][role=group] {
3
+ overflow: hidden;
4
4
  }
5
5
 
6
6
  [role=treeitem][aria-expanded=false] > [role=group] {
@@ -40,7 +40,6 @@ module Spark
40
40
  options = add_class( options, config[:base_class] + "-item" )
41
41
 
42
42
  options['role'] ||= 'menuitem'
43
- options['tabindex'] ||= 0
44
43
 
45
44
  link_to( url, options, &content )
46
45
  end
@@ -65,7 +65,7 @@ module Spark
65
65
  options = add_class( options, classes )
66
66
 
67
67
  content_tag( config[:item_tag], options ) do
68
- concat link_to( "#", class: config[:base_class] + '-item', tabindex: 0 ){
68
+ concat link_to("#", class: config[:base_class] + '-item'){
69
69
  concat name.call
70
70
  concat use_svg( 'chevron-down', class: 'expand-icon' )
71
71
  }
@@ -1,3 +1,3 @@
1
1
  module FleetioSpark
2
- VERSION = "0.2.28"
2
+ VERSION = "0.2.29"
3
3
  end