@stack-spot/portal-layout 0.0.11 → 0.0.12

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 (52) hide show
  1. package/dist/Layout.js +1 -1
  2. package/dist/Layout.js.map +1 -1
  3. package/dist/LayoutOverlayManager.d.ts +4 -0
  4. package/dist/LayoutOverlayManager.d.ts.map +1 -1
  5. package/dist/LayoutOverlayManager.js +51 -21
  6. package/dist/LayoutOverlayManager.js.map +1 -1
  7. package/dist/components/OverlayContent.d.ts +1 -0
  8. package/dist/components/OverlayContent.d.ts.map +1 -1
  9. package/dist/components/OverlayContent.js +2 -1
  10. package/dist/components/OverlayContent.js.map +1 -1
  11. package/dist/components/SelectionList.d.ts +2 -1
  12. package/dist/components/SelectionList.d.ts.map +1 -1
  13. package/dist/components/SelectionList.js +87 -30
  14. package/dist/components/SelectionList.js.map +1 -1
  15. package/dist/components/UserMenu.d.ts.map +1 -1
  16. package/dist/components/UserMenu.js +14 -3
  17. package/dist/components/UserMenu.js.map +1 -1
  18. package/dist/components/menu/MenuContent.d.ts.map +1 -1
  19. package/dist/components/menu/MenuContent.js +10 -6
  20. package/dist/components/menu/MenuContent.js.map +1 -1
  21. package/dist/components/menu/MenuSections.d.ts.map +1 -1
  22. package/dist/components/menu/MenuSections.js +12 -2
  23. package/dist/components/menu/MenuSections.js.map +1 -1
  24. package/dist/components/menu/PageSelector.d.ts.map +1 -1
  25. package/dist/components/menu/PageSelector.js +13 -2
  26. package/dist/components/menu/PageSelector.js.map +1 -1
  27. package/dist/elements.d.ts +13 -0
  28. package/dist/elements.d.ts.map +1 -0
  29. package/dist/elements.js +13 -0
  30. package/dist/elements.js.map +1 -0
  31. package/dist/index.d.ts +2 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/layout.css +5 -1
  36. package/dist/utils.d.ts +45 -0
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js +80 -0
  39. package/dist/utils.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/Layout.tsx +3 -3
  42. package/src/LayoutOverlayManager.tsx +54 -30
  43. package/src/components/OverlayContent.tsx +3 -1
  44. package/src/components/SelectionList.tsx +111 -28
  45. package/src/components/UserMenu.tsx +23 -3
  46. package/src/components/menu/MenuContent.tsx +18 -7
  47. package/src/components/menu/MenuSections.tsx +14 -1
  48. package/src/components/menu/PageSelector.tsx +24 -2
  49. package/src/elements.ts +19 -0
  50. package/src/index.ts +2 -1
  51. package/src/layout.css +5 -1
  52. package/src/utils.ts +94 -0
@@ -0,0 +1,19 @@
1
+ export const elementIds = {
2
+ backdrop: 'backdrop',
3
+ modal: 'modal',
4
+ rightPanel: 'rightPanel',
5
+ bottomDialog: 'bottomDialog',
6
+ page: 'page',
7
+ header: 'header',
8
+ menu: 'menu',
9
+ } as const
10
+
11
+ export type LayoutElement = keyof typeof elementIds
12
+ export type LayoutElements = Record<LayoutElement, HTMLElement | null>
13
+
14
+ export function getLayoutElements() {
15
+ return (Object.keys(elementIds) as LayoutElement[]).reduce<LayoutElements>(
16
+ (result, id) => ({ ...result, [id]: document.getElementById(id) }),
17
+ {} as LayoutElements,
18
+ )
19
+ }
package/src/index.ts CHANGED
@@ -8,7 +8,8 @@ export { MenuContent } from './components/menu/MenuContent'
8
8
  export { MenuSections } from './components/menu/MenuSections'
9
9
  export * from './components/menu/types'
10
10
  export * from './components/types'
11
+ export * from './elements'
11
12
  export * from './errors'
12
13
  export { Logo as StackspotLogo } from './svg/Logo'
13
- export { valueOfLayoutVar } from './utils'
14
+ export { focusFirstChild, focusNextIgnoringChildren, valueOfLayoutVar } from './utils'
14
15
 
package/src/layout.css CHANGED
@@ -188,7 +188,9 @@ body {
188
188
  }
189
189
 
190
190
  #menuSections .toggle:hover,
191
- #menuSections > ul li a:hover {
191
+ #menuSections > ul li a:hover,
192
+ #menuSections .toggle:focus,
193
+ #menuSections > ul li a:focus {
192
194
  background: var(--light-500);
193
195
  }
194
196
 
@@ -313,6 +315,8 @@ body {
313
315
  transition: right var(--right-panel-animation-duration);
314
316
  background-color: var(--light-400);
315
317
  right: -800px;
318
+ border-top-left-radius: 1rem;
319
+ border-bottom-left-radius: 1rem;
316
320
  }
317
321
 
318
322
  #rightPanel.small {
package/src/utils.ts CHANGED
@@ -5,3 +5,97 @@ export function valueOfLayoutVar(varname: string): string {
5
5
  if (!layout) return ''
6
6
  return valueOf(varname, layout)
7
7
  }
8
+
9
+ /**
10
+ * Important for accessibility.
11
+ *
12
+ * Makes it so we focus the next focusable element in the DOM hierarchy, disregarding the element passed as parameter and its children.
13
+ *
14
+ * If there's no next focusable element, the first focusable of the page will be focused. If the page doesn't contain any focusable
15
+ * element, nothing happens.
16
+ *
17
+ * @param current the reference element to focus the next. If not provided, will be the currently active element.
18
+ */
19
+ export function focusNextIgnoringChildren(current?: HTMLElement | null) {
20
+ current = current ?? document.activeElement as HTMLElement
21
+ while (current && !current.nextElementSibling) {
22
+ current = current?.parentElement
23
+ }
24
+ current = current?.nextElementSibling as HTMLElement
25
+ while (current && current.tabIndex < 0) {
26
+ current = (current.children.length ? current.firstChild : current.nextElementSibling) as HTMLElement
27
+ }
28
+ if (current) current?.focus?.()
29
+ else focusFirstChild(document)
30
+ }
31
+
32
+ type TagPriority = 'a' | 'button' | 'input' | 'textarea' | 'select' | 'other'
33
+ type TagPriorityElement = TagPriority | TagPriority[]
34
+
35
+ interface FocusOptions {
36
+ /**
37
+ * Instead of focusing the first element overall, focus the first according to this list of priorities.
38
+ */
39
+ priority?: TagPriorityElement[],
40
+ /**
41
+ * Ignores any element that matches this query selector.
42
+ */
43
+ ignore?: string,
44
+ }
45
+
46
+ const selectors: Record<TagPriority, string> = {
47
+ a: 'a[href]:not(:disabled)',
48
+ button: 'button:not(:disabled)',
49
+ input: 'input:not(:disabled):not([type="hidden"])',
50
+ select: 'textarea:not(:disabled)',
51
+ textarea: 'select:not(:disabled)',
52
+ other: '[tabindex]:not([tabindex="-1"])',
53
+ }
54
+
55
+ /**
56
+ * Focus the first focusable child of the element provided. If the element has no focusable child, nothing happens.
57
+ *
58
+ * A priority list can be passed in the second parameter, as an option. If it's provided, it will focus the first element according to the
59
+ * list.
60
+ *
61
+ * An ignore query selector can also be passed in the options parameter. If the first focusable element matches the query selector, the
62
+ * next element is focused instead.
63
+ *
64
+ * @example
65
+ * Suppose the children of element are: h1, button, p, input, select.
66
+ * 1. We don't pass a priority list. The focused element will be the button.
67
+ * 2. Our priority list is ['button']. The focused element will be the button.
68
+ * 3. Our priority list is ['input', 'button']. The focused element will be the input.
69
+ * 4. Our priority list is ['select', 'input']. The focused element will be the select.
70
+ * 5. Our priority list is [['select', 'input'], 'button']. The focused element will be the input.
71
+ *
72
+ * @param element the element to search a child to focus.
73
+ * @param options optional.
74
+ */
75
+ export function focusFirstChild(element: HTMLElement | Document | null | undefined, { priority = [], ignore }: FocusOptions = {}) {
76
+ let focusable: NodeListOf<HTMLElement> | null | undefined
77
+ let missing: TagPriority[] = ['a', 'button', 'input', 'other', 'select', 'textarea']
78
+ for (const p of priority) {
79
+ const tags = Array.isArray(p) ? p : [p]
80
+ const querySelectors = tags.map(t => {
81
+ missing = missing.filter(tag => tag != t)
82
+ return selectors[t]
83
+ })
84
+ focusable = element?.querySelectorAll(querySelectors.join(', '))
85
+ if (focusable) break
86
+ }
87
+ if (!focusable) {
88
+ element?.querySelectorAll(missing.map(t => selectors[t]).join(', '))
89
+ }
90
+ let elementToFocus: HTMLElement | undefined
91
+ for (const f of focusable ?? []) {
92
+ if (!ignore || !f.matches(ignore)) {
93
+ const styles = window.getComputedStyle(f)
94
+ if (styles.display != 'none' && styles.visibility != 'hidden') {
95
+ elementToFocus = f
96
+ break
97
+ }
98
+ }
99
+ }
100
+ elementToFocus?.focus?.()
101
+ }