@energie360/ui-library 0.1.9 → 0.1.10

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.
Files changed (29) hide show
  1. package/base/abstracts/_variables.scss +1 -0
  2. package/components/context-menu/context-menu.scss +28 -0
  3. package/components/context-menu/u-context-menu.vue +113 -0
  4. package/components/context-menu-divider/context-menu-divider.scss +6 -0
  5. package/components/context-menu-divider/u-context-menu-divider.vue +5 -0
  6. package/components/context-menu-link/context-menu-link.scss +26 -0
  7. package/components/context-menu-link/u-context-menu-link.vue +27 -0
  8. package/components/index.js +5 -0
  9. package/components/navigation-toolbar-link/navigation-toolbar-link.scss +177 -0
  10. package/components/navigation-toolbar-link/u-navigation-toolbar-link.vue +108 -0
  11. package/components/text-block/text-block.scss +58 -0
  12. package/components/text-block/u-text-block.vue +26 -0
  13. package/components/tooltip/popover.ts +74 -12
  14. package/dist/base-style.css +1 -0
  15. package/dist/base-style.css.map +1 -1
  16. package/dist/elements/text-link.css +1 -0
  17. package/dist/elements/text-link.css.map +1 -1
  18. package/dist/layout/split.css +1 -0
  19. package/dist/layout/split.css.map +1 -1
  20. package/elements/button-chip/button-chip.scss +2 -2
  21. package/elements/text-field/u-text-field.vue +9 -1
  22. package/i18n/i18n.ts +8 -0
  23. package/modules/index.js +2 -0
  24. package/modules/navigation-toolbar-side/navigation-toolbar-side.scss +89 -0
  25. package/modules/navigation-toolbar-side/u-navigation-toolbar-side.vue +93 -0
  26. package/modules/navigation-toolbar-top/navigation-toolbar-top.scss +89 -0
  27. package/modules/navigation-toolbar-top/u-navigation-toolbar-top.vue +130 -0
  28. package/package.json +2 -2
  29. package/utils/a11y/focus-trap.js +128 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@energie360/ui-library",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "./wizard": "./wizard/index.js",
15
15
  "./utility/elements/*": "./dist/elements/*",
16
16
  "./utility/layout/*": "./dist/layout/*",
17
- "./abstracts": "./base/abstracts/index.scss"
17
+ "./base/abstracts": "./base/abstracts/index.scss"
18
18
  },
19
19
  "keywords": [],
20
20
  "author": "",
@@ -0,0 +1,128 @@
1
+ export const getFocusableElements = (parent) => {
2
+ const focusableElements = [
3
+ 'button:not([disabled]):not([tabindex="-1"])',
4
+ '[href]',
5
+ 'input:not([disabled]):not([type="hidden"])',
6
+ 'select:not([disabled])',
7
+ 'textarea:not([disabled])',
8
+ '[tabindex]:not([tabindex="-1"])',
9
+ 'iframe',
10
+ 'details',
11
+ ]
12
+
13
+ return Array.from(parent.querySelectorAll(focusableElements.join(', ')))
14
+ }
15
+
16
+ /**
17
+ *
18
+ * @param parent
19
+ * @param {Object} options
20
+ * @param {Boolean} options.focusFirstElement
21
+ * @param {Boolean} options.allowArrowUpDown
22
+ * @param {Boolean} options.allowArrowLeftRight
23
+ * @returns {{release: release}}
24
+ */
25
+ export const focusTrap = (parent, options = {}) => {
26
+ const TAB = 'Tab'
27
+ const ARROW_DOWN = 'ArrowDown'
28
+ const ARROW_UP = 'ArrowUp'
29
+ const ARROW_LEFT = 'ArrowLeft'
30
+ const ARROW_RIGHT = 'ArrowRight'
31
+
32
+ const allFocusable = getFocusableElements(parent)
33
+ const firstFocusable = allFocusable[0]
34
+ const lastFocusable = allFocusable[allFocusable.length - 1]
35
+
36
+ const focusNext = () => {
37
+ let currentIdx = allFocusable.findIndex((el) => el === document.activeElement)
38
+
39
+ if (currentIdx === allFocusable.length - 1) {
40
+ currentIdx = 0
41
+ } else {
42
+ currentIdx++
43
+ }
44
+
45
+ allFocusable[currentIdx].focus()
46
+ }
47
+
48
+ const focusPrevious = () => {
49
+ let currentIdx = allFocusable.findIndex((el) => el === document.activeElement)
50
+
51
+ if (currentIdx === 0) {
52
+ currentIdx = allFocusable.length - 1
53
+ } else {
54
+ currentIdx--
55
+ }
56
+
57
+ allFocusable[currentIdx].focus()
58
+ }
59
+
60
+ const onKeydown = (e) => {
61
+ // Tab
62
+ if (e.code === TAB && !e.shiftKey) {
63
+ if (document.activeElement === lastFocusable) {
64
+ firstFocusable.focus()
65
+ e.preventDefault()
66
+ }
67
+
68
+ return
69
+ }
70
+
71
+ // Shift + Tab
72
+ if (e.code === TAB && e.shiftKey) {
73
+ if (document.activeElement === firstFocusable) {
74
+ lastFocusable.focus()
75
+ e.preventDefault()
76
+ }
77
+
78
+ return
79
+ }
80
+
81
+ if (options.allowArrowUpDown) {
82
+ if (e.code === ARROW_DOWN) {
83
+ focusNext()
84
+ return
85
+ }
86
+
87
+ if (e.code === ARROW_UP) {
88
+ focusPrevious()
89
+ return
90
+ }
91
+ }
92
+
93
+ if (options.allowArrowLeftRight) {
94
+ if (e.code === ARROW_RIGHT) {
95
+ focusNext()
96
+ return
97
+ }
98
+
99
+ if (e.code === ARROW_LEFT) {
100
+ focusPrevious()
101
+ }
102
+ }
103
+ }
104
+
105
+ const release = () => {
106
+ parent.removeEventListener('keydown', onKeydown)
107
+
108
+ // Is this necessary?
109
+ document.activeElement.blur()
110
+ }
111
+
112
+ // Set initial focus
113
+ if (options.focusFirstElement) {
114
+ firstFocusable.focus()
115
+ } else {
116
+ if (parent.tabIndex < 0) {
117
+ parent.tabIndex = 0
118
+ }
119
+
120
+ parent.focus()
121
+ }
122
+
123
+ parent.addEventListener('keydown', onKeydown)
124
+
125
+ return {
126
+ release,
127
+ }
128
+ }