@vaadin/accordion 23.2.2 → 23.3.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/accordion",
3
- "version": "23.2.2",
3
+ "version": "23.3.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,11 +36,11 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/component-base": "~23.2.2",
40
- "@vaadin/details": "~23.2.2",
41
- "@vaadin/vaadin-lumo-styles": "~23.2.2",
42
- "@vaadin/vaadin-material-styles": "~23.2.2",
43
- "@vaadin/vaadin-themable-mixin": "~23.2.2"
39
+ "@vaadin/component-base": "23.3.0-alpha2",
40
+ "@vaadin/details": "23.3.0-alpha2",
41
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha2",
42
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha2",
43
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@esm-bundle/chai": "^4.3.4",
@@ -51,5 +51,5 @@
51
51
  "web-types.json",
52
52
  "web-types.lit.json"
53
53
  ],
54
- "gitHead": "a98818979098f4542ce557a58858fb6dad910a25"
54
+ "gitHead": "ae61027c62ffa7f7d70cfc50e43f333addfc74b6"
55
55
  }
@@ -4,6 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
+ import { KeyboardDirectionMixin } from '@vaadin/component-base/src/keyboard-direction-mixin.js';
7
8
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
9
  import type { AccordionPanel } from './vaadin-accordion-panel.js';
9
10
 
@@ -69,7 +70,7 @@ export type AccordionEventMap = AccordionCustomEventMap & HTMLElementEventMap;
69
70
  * @fires {CustomEvent} items-changed - Fired when the `items` property changes.
70
71
  * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
71
72
  */
72
- declare class Accordion extends ElementMixin(ThemableMixin(HTMLElement)) {
73
+ declare class Accordion extends KeyboardDirectionMixin(ElementMixin(ThemableMixin(HTMLElement))) {
73
74
  /**
74
75
  * The index of currently opened panel. First panel is opened by
75
76
  * default. Only one panel can be opened at the same time.
@@ -6,6 +6,7 @@
6
6
  import { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
7
7
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
+ import { KeyboardDirectionMixin } from '@vaadin/component-base/src/keyboard-direction-mixin.js';
9
10
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
11
  import { AccordionPanel } from './vaadin-accordion-panel.js';
11
12
 
@@ -55,9 +56,10 @@ import { AccordionPanel } from './vaadin-accordion-panel.js';
55
56
  *
56
57
  * @extends HTMLElement
57
58
  * @mixes ElementMixin
59
+ * @mixes KeyboardDirectionMixin
58
60
  * @mixes ThemableMixin
59
61
  */
60
- class Accordion extends ThemableMixin(ElementMixin(PolymerElement)) {
62
+ class Accordion extends KeyboardDirectionMixin(ThemableMixin(ElementMixin(PolymerElement))) {
61
63
  static get template() {
62
64
  return html`
63
65
  <style>
@@ -115,35 +117,21 @@ class Accordion extends ThemableMixin(ElementMixin(PolymerElement)) {
115
117
  this._boundUpdateOpened = this._updateOpened.bind(this);
116
118
  }
117
119
 
118
- /**
119
- * @return {Element | null}
120
- * @protected
121
- */
122
- get focused() {
123
- return this.getRootNode().activeElement;
124
- }
125
-
126
120
  /**
127
121
  * @protected
122
+ * @override
128
123
  */
129
124
  focus() {
130
125
  if (this._observer) {
131
126
  this._observer.flush();
132
127
  }
133
- if (Array.isArray(this.items)) {
134
- const idx = this._getAvailableIndex(0);
135
- if (idx >= 0) {
136
- this.items[idx].focus();
137
- }
138
- }
128
+ super.focus();
139
129
  }
140
130
 
141
131
  /** @protected */
142
132
  ready() {
143
133
  super.ready();
144
134
 
145
- this.addEventListener('keydown', (e) => this._onKeydown(e));
146
-
147
135
  this._observer = new FlattenedNodesObserver(this, (info) => {
148
136
  this._setItems(this._filterItems(Array.from(this.children)));
149
137
 
@@ -153,6 +141,18 @@ class Accordion extends ThemableMixin(ElementMixin(PolymerElement)) {
153
141
  });
154
142
  }
155
143
 
144
+ /**
145
+ * Override method inherited from `KeyboardDirectionMixin`
146
+ * to use the stored list of accordion panels as items.
147
+ *
148
+ * @return {Element[]}
149
+ * @protected
150
+ * @override
151
+ */
152
+ _getItems() {
153
+ return this.items;
154
+ }
155
+
156
156
  /**
157
157
  * @param {!Array<!Element>} array
158
158
  * @return {!Array<!AccordionPanel>}
@@ -173,71 +173,21 @@ class Accordion extends ThemableMixin(ElementMixin(PolymerElement)) {
173
173
  }
174
174
 
175
175
  /**
176
+ * Override an event listener from `KeyboardMixin`
177
+ * to only handle details toggle buttons events.
178
+ *
176
179
  * @param {!KeyboardEvent} event
177
180
  * @protected
181
+ * @override
178
182
  */
179
- _onKeydown(event) {
183
+ _onKeyDown(event) {
180
184
  // Only check keyboard events on details toggle buttons
181
185
  const item = event.composedPath()[0];
182
186
  if (!this.items.some((el) => el.focusElement === item)) {
183
187
  return;
184
188
  }
185
189
 
186
- const currentIdx = this.items.indexOf(this.focused);
187
- let idx;
188
- let increment;
189
-
190
- switch (event.key) {
191
- case 'ArrowUp':
192
- increment = -1;
193
- idx = currentIdx - 1;
194
- break;
195
- case 'ArrowDown':
196
- increment = 1;
197
- idx = currentIdx + 1;
198
- break;
199
- case 'Home':
200
- increment = 1;
201
- idx = 0;
202
- break;
203
- case 'End':
204
- increment = -1;
205
- idx = this.items.length - 1;
206
- break;
207
- default:
208
- // Do nothing.
209
- }
210
-
211
- idx = this._getAvailableIndex(idx, increment);
212
- if (idx >= 0) {
213
- this.items[idx].focus();
214
- this.items[idx].setAttribute('focus-ring', '');
215
- event.preventDefault();
216
- }
217
- }
218
-
219
- /**
220
- * @param {number} index
221
- * @param {number} increment
222
- * @return {number}
223
- * @protected
224
- */
225
- _getAvailableIndex(index, increment) {
226
- const totalItems = this.items.length;
227
- let idx = index;
228
- for (let i = 0; typeof idx === 'number' && i < totalItems; i++, idx += increment || 1) {
229
- if (idx < 0) {
230
- idx = totalItems - 1;
231
- } else if (idx >= totalItems) {
232
- idx = 0;
233
- }
234
-
235
- const item = this.items[idx];
236
- if (!item.disabled) {
237
- return idx;
238
- }
239
- }
240
- return -1;
190
+ super._onKeyDown(event);
241
191
  }
242
192
 
243
193
  /** @private */
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/accordion",
4
- "version": "23.2.2",
4
+ "version": "23.3.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -97,7 +97,7 @@
97
97
  },
98
98
  {
99
99
  "name": "vaadin-accordion",
100
- "description": "`<vaadin-accordion>` is a Web Component implementing accordion widget —\na vertically stacked set of expandable panels. The component should be\nused as a wrapper for two or more `<vaadin-accordion-panel>` components.\n\nPanel headings function as controls that enable users to open (expand)\nor hide (collapse) their associated sections of content. The user can\ntoggle panels by mouse click, Enter and Space keys.\n\nOnly one panel can be opened at a time, opening a new one forces\nprevious panel to close and hide its content.\n\n```\n<vaadin-accordion>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 1</div>\n This panel is opened, so the text is visible by default.\n </vaadin-accordion-panel>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 2</div>\n After opening this panel, the first one becomes closed.\n </vaadin-accordion-panel>\n</vaadin-accordion>\n```\n\n### Styling\n\nSee the [`<vaadin-accordion-panel>`](https://cdn.vaadin.com/vaadin-web-components/23.2.2/#/elements/vaadin-accordion-panel)\ndocumentation for the available state attributes and stylable shadow parts.\n\n**Note:** You can apply the theme to `<vaadin-accordion>` component itself,\nespecially by using the following CSS selector:\n\n```\n:host ::slotted(vaadin-accordion-panel) {\n margin-bottom: 5px;\n}\n```\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
100
+ "description": "`<vaadin-accordion>` is a Web Component implementing accordion widget —\na vertically stacked set of expandable panels. The component should be\nused as a wrapper for two or more `<vaadin-accordion-panel>` components.\n\nPanel headings function as controls that enable users to open (expand)\nor hide (collapse) their associated sections of content. The user can\ntoggle panels by mouse click, Enter and Space keys.\n\nOnly one panel can be opened at a time, opening a new one forces\nprevious panel to close and hide its content.\n\n```\n<vaadin-accordion>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 1</div>\n This panel is opened, so the text is visible by default.\n </vaadin-accordion-panel>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 2</div>\n After opening this panel, the first one becomes closed.\n </vaadin-accordion-panel>\n</vaadin-accordion>\n```\n\n### Styling\n\nSee the [`<vaadin-accordion-panel>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha2/#/elements/vaadin-accordion-panel)\ndocumentation for the available state attributes and stylable shadow parts.\n\n**Note:** You can apply the theme to `<vaadin-accordion>` component itself,\nespecially by using the following CSS selector:\n\n```\n:host ::slotted(vaadin-accordion-panel) {\n margin-bottom: 5px;\n}\n```\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
101
101
  "attributes": [
102
102
  {
103
103
  "name": "opened",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/accordion",
4
- "version": "23.2.2",
4
+ "version": "23.3.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -51,7 +51,7 @@
51
51
  },
52
52
  {
53
53
  "name": "vaadin-accordion",
54
- "description": "`<vaadin-accordion>` is a Web Component implementing accordion widget —\na vertically stacked set of expandable panels. The component should be\nused as a wrapper for two or more `<vaadin-accordion-panel>` components.\n\nPanel headings function as controls that enable users to open (expand)\nor hide (collapse) their associated sections of content. The user can\ntoggle panels by mouse click, Enter and Space keys.\n\nOnly one panel can be opened at a time, opening a new one forces\nprevious panel to close and hide its content.\n\n```\n<vaadin-accordion>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 1</div>\n This panel is opened, so the text is visible by default.\n </vaadin-accordion-panel>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 2</div>\n After opening this panel, the first one becomes closed.\n </vaadin-accordion-panel>\n</vaadin-accordion>\n```\n\n### Styling\n\nSee the [`<vaadin-accordion-panel>`](https://cdn.vaadin.com/vaadin-web-components/23.2.2/#/elements/vaadin-accordion-panel)\ndocumentation for the available state attributes and stylable shadow parts.\n\n**Note:** You can apply the theme to `<vaadin-accordion>` component itself,\nespecially by using the following CSS selector:\n\n```\n:host ::slotted(vaadin-accordion-panel) {\n margin-bottom: 5px;\n}\n```\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
54
+ "description": "`<vaadin-accordion>` is a Web Component implementing accordion widget —\na vertically stacked set of expandable panels. The component should be\nused as a wrapper for two or more `<vaadin-accordion-panel>` components.\n\nPanel headings function as controls that enable users to open (expand)\nor hide (collapse) their associated sections of content. The user can\ntoggle panels by mouse click, Enter and Space keys.\n\nOnly one panel can be opened at a time, opening a new one forces\nprevious panel to close and hide its content.\n\n```\n<vaadin-accordion>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 1</div>\n This panel is opened, so the text is visible by default.\n </vaadin-accordion-panel>\n <vaadin-accordion-panel>\n <div slot=\"summary\">Panel 2</div>\n After opening this panel, the first one becomes closed.\n </vaadin-accordion-panel>\n</vaadin-accordion>\n```\n\n### Styling\n\nSee the [`<vaadin-accordion-panel>`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha2/#/elements/vaadin-accordion-panel)\ndocumentation for the available state attributes and stylable shadow parts.\n\n**Note:** You can apply the theme to `<vaadin-accordion>` component itself,\nespecially by using the following CSS selector:\n\n```\n:host ::slotted(vaadin-accordion-panel) {\n margin-bottom: 5px;\n}\n```\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
55
55
  "extension": true,
56
56
  "attributes": [
57
57
  {