@vaadin/virtual-list 24.7.0-alpha1 → 24.7.0-alpha2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/virtual-list",
3
- "version": "24.7.0-alpha1",
3
+ "version": "24.7.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,15 +39,15 @@
39
39
  "dependencies": {
40
40
  "@open-wc/dedupe-mixin": "^1.3.0",
41
41
  "@polymer/polymer": "^3.0.0",
42
- "@vaadin/component-base": "24.7.0-alpha1",
43
- "@vaadin/lit-renderer": "24.7.0-alpha1",
44
- "@vaadin/vaadin-lumo-styles": "24.7.0-alpha1",
45
- "@vaadin/vaadin-material-styles": "24.7.0-alpha1",
46
- "@vaadin/vaadin-themable-mixin": "24.7.0-alpha1",
42
+ "@vaadin/component-base": "24.7.0-alpha2",
43
+ "@vaadin/lit-renderer": "24.7.0-alpha2",
44
+ "@vaadin/vaadin-lumo-styles": "24.7.0-alpha2",
45
+ "@vaadin/vaadin-material-styles": "24.7.0-alpha2",
46
+ "@vaadin/vaadin-themable-mixin": "24.7.0-alpha2",
47
47
  "lit": "^3.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@vaadin/chai-plugins": "24.7.0-alpha1",
50
+ "@vaadin/chai-plugins": "24.7.0-alpha2",
51
51
  "@vaadin/testing-helpers": "^1.0.0",
52
52
  "sinon": "^18.0.0"
53
53
  },
@@ -55,5 +55,5 @@
55
55
  "web-types.json",
56
56
  "web-types.lit.json"
57
57
  ],
58
- "gitHead": "04be941c9a7b659871c97f31b9cc3ffd7528087b"
58
+ "gitHead": "e2523f9b4abc5a9586fb758166f823dc40c399dd"
59
59
  }
@@ -53,6 +53,15 @@ export declare class VirtualListMixinClass<TItem = VirtualListDefaultItem> {
53
53
  */
54
54
  items: TItem[] | undefined;
55
55
 
56
+ /**
57
+ * A function that generates accessible names for virtual list items.
58
+ * The function gets the item as an argument and the
59
+ * return value should be a string representing that item. The
60
+ * result gets applied to the corresponding virtual list child element
61
+ * as an `aria-label` attribute.
62
+ */
63
+ itemAccessibleNameGenerator?: (item: TItem) => string;
64
+
56
65
  /**
57
66
  * Scroll to a specific index in the virtual list.
58
67
  */
@@ -36,13 +36,25 @@ export const VirtualListMixin = (superClass) =>
36
36
  */
37
37
  renderer: { type: Function, sync: true },
38
38
 
39
+ /**
40
+ * A function that generates accessible names for virtual list items.
41
+ * The function gets the item as an argument and the
42
+ * return value should be a string representing that item. The
43
+ * result gets applied to the corresponding virtual list child element
44
+ * as an `aria-label` attribute.
45
+ */
46
+ itemAccessibleNameGenerator: {
47
+ type: Function,
48
+ sync: true,
49
+ },
50
+
39
51
  /** @private */
40
52
  __virtualizer: Object,
41
53
  };
42
54
  }
43
55
 
44
56
  static get observers() {
45
- return ['__itemsOrRendererChanged(items, renderer, __virtualizer)'];
57
+ return ['__itemsOrRendererChanged(items, renderer, __virtualizer, itemAccessibleNameGenerator)'];
46
58
  }
47
59
 
48
60
  /**
@@ -65,7 +77,7 @@ export const VirtualListMixin = (superClass) =>
65
77
 
66
78
  constructor() {
67
79
  super();
68
- this.__onDragStart = this.__onDragStart.bind(this);
80
+ this.__onDocumentDragStart = this.__onDocumentDragStart.bind(this);
69
81
  }
70
82
 
71
83
  /** @protected */
@@ -84,22 +96,19 @@ export const VirtualListMixin = (superClass) =>
84
96
  this.addController(this.__overflowController);
85
97
 
86
98
  processTemplates(this);
99
+ this.__updateAria();
87
100
  }
88
101
 
89
102
  /** @protected */
90
103
  connectedCallback() {
91
104
  super.connectedCallback();
92
- // Chromium based browsers cannot properly generate drag images for elements
93
- // that have children with massive heights. This workaround prevents crashes
94
- // and performance issues by excluding the items from the drag image.
95
- // https://github.com/vaadin/web-components/issues/7985
96
- document.addEventListener('dragstart', this.__onDragStart, { capture: true });
105
+ document.addEventListener('dragstart', this.__onDocumentDragStart, { capture: true });
97
106
  }
98
107
 
99
108
  /** @protected */
100
109
  disconnectedCallback() {
101
110
  super.disconnectedCallback();
102
- document.removeEventListener('dragstart', this.__onDragStart, { capture: true });
111
+ document.removeEventListener('dragstart', this.__onDocumentDragStart, { capture: true });
103
112
  }
104
113
 
105
114
  /**
@@ -116,18 +125,34 @@ export const VirtualListMixin = (superClass) =>
116
125
  return [...Array(count)].map(() => document.createElement('div'));
117
126
  }
118
127
 
128
+ /** @private */
129
+ __updateAria() {
130
+ this.role = 'list';
131
+ }
132
+
119
133
  /** @private */
120
134
  __updateElement(el, index) {
135
+ const item = this.items[index];
136
+ el.ariaSetSize = String(this.items.length);
137
+ el.ariaPosInSet = String(index + 1);
138
+ el.ariaLabel = this.itemAccessibleNameGenerator ? this.itemAccessibleNameGenerator(item) : null;
139
+ this.__updateElementRole(el);
140
+
121
141
  if (el.__renderer !== this.renderer) {
122
142
  el.__renderer = this.renderer;
123
143
  this.__clearRenderTargetContent(el);
124
144
  }
125
145
 
126
146
  if (this.renderer) {
127
- this.renderer(el, this, { item: this.items[index], index });
147
+ this.renderer(el, this, { item, index });
128
148
  }
129
149
  }
130
150
 
151
+ /** @private */
152
+ __updateElementRole(el) {
153
+ el.role = 'listitem';
154
+ }
155
+
131
156
  /**
132
157
  * Clears the content of a render target.
133
158
  * @private
@@ -153,25 +178,24 @@ export const VirtualListMixin = (superClass) =>
153
178
  }
154
179
  }
155
180
 
156
- /** @private */
157
- __onDragStart(e) {
158
- // The dragged element can be the element itself or a parent of the element
159
- if (!e.target.contains(this)) {
160
- return;
161
- }
162
- // The threshold value 20000 provides a buffer to both
163
- // - avoid the crash and the performance issues
164
- // - unnecessarily avoid excluding items from the drag image
165
- if (this.$.items.offsetHeight > 20000) {
166
- const initialItemsMaxHeight = this.$.items.style.maxHeight;
167
- const initialVirtualListOverflow = this.style.overflow;
168
- // Momentarily hides the items until the browser starts generating the
169
- // drag image.
170
- this.$.items.style.maxHeight = '0';
171
- this.style.overflow = 'hidden';
181
+ /**
182
+ * Webkit-based browsers have issues with generating drag images
183
+ * for elements that have children with massive heights. Chromium
184
+ * browsers crash, while Safari experiences significant performance
185
+ * issues. To mitigate these issues, we hide the items container
186
+ * when drag starts to remove it from the drag image.
187
+ *
188
+ * Related issues:
189
+ * - https://github.com/vaadin/web-components/issues/7985
190
+ * - https://issues.chromium.org/issues/383356871
191
+ *
192
+ * @private
193
+ */
194
+ __onDocumentDragStart(e) {
195
+ if (e.target.contains(this) && this.scrollHeight > 20000) {
196
+ this.$.items.style.display = 'none';
172
197
  requestAnimationFrame(() => {
173
- this.$.items.style.maxHeight = initialItemsMaxHeight;
174
- this.style.overflow = initialVirtualListOverflow;
198
+ this.$.items.style.display = '';
175
199
  });
176
200
  }
177
201
  }
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/virtual-list",
4
- "version": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -43,6 +43,17 @@
43
43
  "undefined"
44
44
  ]
45
45
  }
46
+ },
47
+ {
48
+ "name": "itemAccessibleNameGenerator",
49
+ "description": "A function that generates accessible names for virtual list items.\nThe function gets the item as an argument and the\nreturn value should be a string representing that item. The\nresult gets applied to the corresponding virtual list child element\nas an `aria-label` attribute.",
50
+ "value": {
51
+ "type": [
52
+ "Function",
53
+ "null",
54
+ "undefined"
55
+ ]
56
+ }
46
57
  }
47
58
  ],
48
59
  "events": []
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/virtual-list",
4
- "version": "24.7.0-alpha1",
4
+ "version": "24.7.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -32,6 +32,13 @@
32
32
  "value": {
33
33
  "kind": "expression"
34
34
  }
35
+ },
36
+ {
37
+ "name": ".itemAccessibleNameGenerator",
38
+ "description": "A function that generates accessible names for virtual list items.\nThe function gets the item as an argument and the\nreturn value should be a string representing that item. The\nresult gets applied to the corresponding virtual list child element\nas an `aria-label` attribute.",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
35
42
  }
36
43
  ]
37
44
  }