@sveltia/ui 0.13.0 → 0.13.1

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.
@@ -7,6 +7,7 @@ import { sleep } from '@sveltia/utils/misc';
7
7
  * childRoles: string[],
8
8
  * childSelectedAttr: 'aria-selected' | 'aria-checked',
9
9
  * focusChild: boolean
10
+ * selectFirst: boolean
10
11
  * } }}
11
12
  */
12
13
  const config = {
@@ -15,36 +16,42 @@ const config = {
15
16
  childRoles: ['row'],
16
17
  childSelectedAttr: 'aria-selected',
17
18
  focusChild: true,
19
+ selectFirst: false,
18
20
  },
19
21
  listbox: {
20
22
  orientation: 'vertical',
21
23
  childRoles: ['option'],
22
24
  childSelectedAttr: 'aria-selected',
23
25
  focusChild: false,
26
+ selectFirst: false,
24
27
  },
25
28
  menu: {
26
29
  orientation: 'vertical',
27
30
  childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
28
31
  childSelectedAttr: 'aria-checked',
29
32
  focusChild: true,
33
+ selectFirst: false,
30
34
  },
31
35
  menubar: {
32
36
  orientation: 'horizontal',
33
37
  childRoles: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
34
38
  childSelectedAttr: 'aria-checked',
35
39
  focusChild: true,
40
+ selectFirst: false,
36
41
  },
37
42
  radiogroup: {
38
43
  orientation: 'horizontal',
39
44
  childRoles: ['radio'],
40
45
  childSelectedAttr: 'aria-checked',
41
46
  focusChild: true,
47
+ selectFirst: false,
42
48
  },
43
49
  tablist: {
44
50
  orientation: 'horizontal',
45
51
  childRoles: ['tab'],
46
52
  childSelectedAttr: 'aria-selected',
47
53
  focusChild: true,
54
+ selectFirst: true,
48
55
  },
49
56
  };
50
57
 
@@ -66,7 +73,8 @@ class Group {
66
73
  this.id = generateElementId(this.role);
67
74
  this.parentGroupSelector = `[role="group"], [role="${this.role}"]`;
68
75
 
69
- const { orientation, childRoles, childSelectedAttr, focusChild } = config[this.role];
76
+ const { orientation, childRoles, childSelectedAttr, focusChild, selectFirst } =
77
+ config[this.role];
70
78
 
71
79
  this.orientation = this.grid
72
80
  ? 'horizontal'
@@ -75,6 +83,7 @@ class Group {
75
83
  this.childSelectedAttr = childSelectedAttr;
76
84
  this.childSelectedProp = childSelectedAttr.replace('aria-', '');
77
85
  this.focusChild = focusChild;
86
+ this.selectFirst = selectFirst;
78
87
 
79
88
  // Wait a bit before the relevant components, including the `aria-controls` target are mounted
80
89
  (async () => {
@@ -91,7 +100,9 @@ class Group {
91
100
 
92
101
  allMembers.forEach((element, index) => {
93
102
  // Select the first one if no member has the `selected` attribute
94
- const isSelected = defaultSelected ? element === defaultSelected : index === 0;
103
+ const isSelected = defaultSelected
104
+ ? element === defaultSelected
105
+ : this.selectFirst && index === 0;
95
106
 
96
107
  const controlTarget = /** @type {HTMLElement | null} */ (
97
108
  document.querySelector(`#${element.getAttribute('aria-controls')}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {