@spectrum-web-components/action-group 0.8.6 → 0.10.1-devmode.0

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 (35) hide show
  1. package/custom-elements.json +0 -8
  2. package/package.json +24 -10
  3. package/sp-action-group.dev.js +3 -0
  4. package/sp-action-group.dev.js.map +7 -0
  5. package/sp-action-group.js +3 -14
  6. package/sp-action-group.js.map +7 -1
  7. package/src/ActionGroup.d.ts +1 -3
  8. package/src/ActionGroup.dev.js +309 -0
  9. package/src/ActionGroup.dev.js.map +7 -0
  10. package/src/ActionGroup.js +291 -310
  11. package/src/ActionGroup.js.map +7 -1
  12. package/src/action-group.css.dev.js +149 -0
  13. package/src/action-group.css.dev.js.map +7 -0
  14. package/src/action-group.css.js +6 -33
  15. package/src/action-group.css.js.map +7 -1
  16. package/src/index.dev.js +2 -0
  17. package/src/index.dev.js.map +7 -0
  18. package/src/index.js +2 -13
  19. package/src/index.js.map +7 -1
  20. package/src/spectrum-action-group.css.dev.js +143 -0
  21. package/src/spectrum-action-group.css.dev.js.map +7 -0
  22. package/src/spectrum-action-group.css.js +3 -14
  23. package/src/spectrum-action-group.css.js.map +7 -1
  24. package/stories/action-group-tooltip.stories.js +116 -129
  25. package/stories/action-group-tooltip.stories.js.map +7 -1
  26. package/stories/action-group.stories.js +124 -135
  27. package/stories/action-group.stories.js.map +7 -1
  28. package/test/action-group-tooltip.test-vrt.js +4 -15
  29. package/test/action-group-tooltip.test-vrt.js.map +7 -1
  30. package/test/action-group.test-vrt.js +4 -15
  31. package/test/action-group.test-vrt.js.map +7 -1
  32. package/test/action-group.test.js +454 -465
  33. package/test/action-group.test.js.map +7 -1
  34. package/test/benchmark/basic-test.js +11 -17
  35. package/test/benchmark/basic-test.js.map +7 -1
@@ -1,328 +1,309 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { __decorate } from "tslib";
13
- import { html, SpectrumElement, } from '@spectrum-web-components/base';
14
- import { property } from '@spectrum-web-components/base/src/decorators.js';
15
- import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
16
- import styles from './action-group.css.js';
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import {
13
+ html,
14
+ SpectrumElement
15
+ } from "@spectrum-web-components/base";
16
+ import { property } from "@spectrum-web-components/base/src/decorators.js";
17
+ import { RovingTabindexController } from "@spectrum-web-components/reactive-controllers/src/RovingTabindex.js";
18
+ import { MutationController } from "@lit-labs/observers/mutation_controller.js";
19
+ import styles from "./action-group.css.js";
17
20
  const EMPTY_SELECTION = [];
18
- /**
19
- * @element sp-action-group
20
- * @slot - the sp-action-button elements that make up the group
21
- *
22
- * @fires change - Announces that selection state has been changed by user
23
- */
24
21
  export class ActionGroup extends SpectrumElement {
25
- constructor() {
26
- super(...arguments);
27
- this._buttons = [];
28
- this._buttonSelector = 'sp-action-button';
29
- this.rovingTabindexController = new RovingTabindexController(this, {
30
- focusInIndex: (elements) => {
31
- let firstEnabledIndex = -1;
32
- const firstSelectedIndex = elements.findIndex((el, index) => {
33
- if (!elements[firstEnabledIndex] && !el.disabled) {
34
- firstEnabledIndex = index;
35
- }
36
- return el.selected && !el.disabled;
37
- });
38
- return elements[firstSelectedIndex]
39
- ? firstSelectedIndex
40
- : firstEnabledIndex;
41
- },
42
- elements: () => this.buttons,
43
- isFocusableElement: (el) => !el.disabled,
22
+ constructor() {
23
+ super();
24
+ this._buttons = [];
25
+ this._buttonSelector = "sp-action-button";
26
+ this.rovingTabindexController = new RovingTabindexController(this, {
27
+ focusInIndex: (elements) => {
28
+ let firstEnabledIndex = -1;
29
+ const firstSelectedIndex = elements.findIndex((el, index) => {
30
+ if (!elements[firstEnabledIndex] && !el.disabled) {
31
+ firstEnabledIndex = index;
32
+ }
33
+ return el.selected && !el.disabled;
44
34
  });
45
- this.compact = false;
46
- this.emphasized = false;
47
- this.justified = false;
48
- this.label = '';
49
- this.quiet = false;
50
- this.vertical = false;
51
- this._selected = EMPTY_SELECTION;
52
- this.manageButtons = () => {
53
- const slot = this.shadowRoot.querySelector('slot');
54
- if (!slot)
55
- return;
56
- const assignedElements = slot.assignedElements({ flatten: true });
57
- const buttons = assignedElements.reduce((acc, el) => {
58
- if (el.matches(this._buttonSelector)) {
59
- acc.push(el);
60
- }
61
- else {
62
- const buttonDescendents = Array.from(el.querySelectorAll(`:scope > ${this._buttonSelector}`));
63
- acc.push(...buttonDescendents);
64
- }
65
- return acc;
66
- }, []);
67
- this.buttons = buttons;
68
- // <selected> element merges selected so following paradigm here
69
- const currentlySelectedButtons = [];
70
- this.buttons.forEach((button) => {
71
- if (button.selected) {
72
- currentlySelectedButtons.push(button.value);
73
- }
74
- });
75
- this.setSelected(this.selected.concat(currentlySelectedButtons));
76
- this.manageChildren();
77
- this.manageSelects();
78
- };
79
- }
80
- static get styles() {
81
- return [styles];
82
- }
83
- set buttons(tabs) {
84
- if (tabs === this.buttons)
85
- return;
86
- this._buttons = tabs;
87
- this.rovingTabindexController.clearElementCache();
88
- }
89
- get buttons() {
90
- return this._buttons;
91
- }
92
- set selected(selected) {
93
- this.requestUpdate('selected', this._selected);
94
- this._selected = selected;
95
- this.updateComplete.then(() => {
96
- this.applySelects();
97
- this.manageChildren();
98
- });
99
- }
100
- get selected() {
101
- return this._selected;
102
- }
103
- dispatchChange(old) {
104
- const applyDefault = this.dispatchEvent(new Event('change', {
105
- bubbles: true,
106
- composed: true,
107
- cancelable: true,
108
- }));
109
- if (!applyDefault) {
110
- this.setSelected(old);
111
- this.buttons.map((button) => {
112
- button.selected = this.selected.includes(button.value);
113
- });
35
+ return elements[firstSelectedIndex] ? firstSelectedIndex : firstEnabledIndex;
36
+ },
37
+ elements: () => this.buttons,
38
+ isFocusableElement: (el) => !el.disabled
39
+ });
40
+ this.compact = false;
41
+ this.emphasized = false;
42
+ this.justified = false;
43
+ this.label = "";
44
+ this.quiet = false;
45
+ this.vertical = false;
46
+ this._selected = EMPTY_SELECTION;
47
+ this.manageButtons = () => {
48
+ const slot = this.shadowRoot.querySelector("slot");
49
+ if (!slot)
50
+ return;
51
+ const assignedElements = slot.assignedElements({ flatten: true });
52
+ const buttons = assignedElements.reduce((acc, el) => {
53
+ if (el.matches(this._buttonSelector)) {
54
+ acc.push(el);
55
+ } else {
56
+ const buttonDescendents = Array.from(el.querySelectorAll(`:scope > ${this._buttonSelector}`));
57
+ acc.push(...buttonDescendents);
114
58
  }
59
+ return acc;
60
+ }, []);
61
+ this.buttons = buttons;
62
+ const currentlySelectedButtons = [];
63
+ this.buttons.forEach((button) => {
64
+ if (button.selected) {
65
+ currentlySelectedButtons.push(button.value);
66
+ }
67
+ });
68
+ this.setSelected(this.selected.concat(currentlySelectedButtons));
69
+ this.manageChildren();
70
+ this.manageSelects();
71
+ };
72
+ new MutationController(this, {
73
+ config: {
74
+ childList: true,
75
+ subtree: true
76
+ },
77
+ callback: () => {
78
+ this.manageButtons();
79
+ }
80
+ });
81
+ }
82
+ static get styles() {
83
+ return [styles];
84
+ }
85
+ set buttons(tabs) {
86
+ if (tabs === this.buttons)
87
+ return;
88
+ this._buttons = tabs;
89
+ this.rovingTabindexController.clearElementCache();
90
+ }
91
+ get buttons() {
92
+ return this._buttons;
93
+ }
94
+ set selected(selected) {
95
+ this.requestUpdate("selected", this._selected);
96
+ this._selected = selected;
97
+ this.updateComplete.then(() => {
98
+ this.applySelects();
99
+ this.manageChildren();
100
+ });
101
+ }
102
+ get selected() {
103
+ return this._selected;
104
+ }
105
+ dispatchChange(old) {
106
+ const applyDefault = this.dispatchEvent(new Event("change", {
107
+ bubbles: true,
108
+ composed: true,
109
+ cancelable: true
110
+ }));
111
+ if (!applyDefault) {
112
+ this.setSelected(old);
113
+ this.buttons.map((button) => {
114
+ button.selected = this.selected.includes(button.value);
115
+ });
115
116
  }
116
- setSelected(selected, announce) {
117
- if (selected === this.selected)
118
- return;
119
- const old = this.selected;
120
- this.requestUpdate('selected', old);
121
- this._selected = selected;
122
- if (!announce)
123
- return;
124
- this.dispatchChange(old);
125
- }
126
- focus(options) {
127
- this.rovingTabindexController.focus(options);
128
- }
129
- deselectSelectedButtons() {
130
- const selected = [
131
- ...this.querySelectorAll('[selected]'),
132
- ];
133
- selected.forEach((el) => {
134
- el.selected = false;
135
- el.tabIndex = -1;
136
- el.setAttribute('aria-checked', 'false');
137
- });
117
+ }
118
+ setSelected(selected, announce) {
119
+ if (selected === this.selected)
120
+ return;
121
+ const old = this.selected;
122
+ this.requestUpdate("selected", old);
123
+ this._selected = selected;
124
+ if (!announce)
125
+ return;
126
+ this.dispatchChange(old);
127
+ }
128
+ focus(options) {
129
+ this.rovingTabindexController.focus(options);
130
+ }
131
+ deselectSelectedButtons() {
132
+ const selected = [
133
+ ...this.querySelectorAll("[selected]")
134
+ ];
135
+ selected.forEach((el) => {
136
+ el.selected = false;
137
+ el.tabIndex = -1;
138
+ el.setAttribute("aria-checked", "false");
139
+ });
140
+ }
141
+ handleClick(event) {
142
+ const target = event.target;
143
+ if (typeof target.value === "undefined") {
144
+ return;
138
145
  }
139
- handleClick(event) {
140
- const target = event.target;
141
- if (typeof target.value === 'undefined') {
142
- return;
143
- }
144
- switch (this.selects) {
145
- case 'single': {
146
- this.deselectSelectedButtons();
147
- target.selected = true;
148
- target.tabIndex = 0;
149
- target.setAttribute('aria-checked', 'true');
150
- this.setSelected([target.value], true);
151
- target.focus();
152
- break;
153
- }
154
- case 'multiple': {
155
- const selected = [...this.selected];
156
- target.selected = !target.selected;
157
- target.setAttribute('aria-checked', target.selected ? 'true' : 'false');
158
- if (target.selected) {
159
- selected.push(target.value);
160
- }
161
- else {
162
- selected.splice(this.selected.indexOf(target.value), 1);
163
- }
164
- this.setSelected(selected, true);
165
- this.buttons.forEach((button) => {
166
- button.tabIndex = -1;
167
- });
168
- target.tabIndex = 0;
169
- break;
170
- }
171
- default:
172
- break;
146
+ switch (this.selects) {
147
+ case "single": {
148
+ this.deselectSelectedButtons();
149
+ target.selected = true;
150
+ target.tabIndex = 0;
151
+ target.setAttribute("aria-checked", "true");
152
+ this.setSelected([target.value], true);
153
+ target.focus();
154
+ break;
155
+ }
156
+ case "multiple": {
157
+ const selected = [...this.selected];
158
+ target.selected = !target.selected;
159
+ target.setAttribute("aria-checked", target.selected ? "true" : "false");
160
+ if (target.selected) {
161
+ selected.push(target.value);
162
+ } else {
163
+ selected.splice(this.selected.indexOf(target.value), 1);
173
164
  }
165
+ this.setSelected(selected, true);
166
+ this.buttons.forEach((button) => {
167
+ button.tabIndex = -1;
168
+ });
169
+ target.tabIndex = 0;
170
+ break;
171
+ }
172
+ default:
173
+ break;
174
174
  }
175
- async applySelects() {
176
- await this.manageSelects(true);
175
+ }
176
+ async applySelects() {
177
+ await this.manageSelects(true);
178
+ }
179
+ async manageSelects(applied) {
180
+ if (!this.buttons.length) {
181
+ return;
177
182
  }
178
- async manageSelects(applied) {
179
- if (!this.buttons.length) {
180
- return;
181
- }
182
- const options = this.buttons;
183
- switch (this.selects) {
184
- case 'single': {
185
- this.setAttribute('role', 'radiogroup');
186
- const selections = [];
187
- const updates = options.map(async (option) => {
188
- await option.updateComplete;
189
- option.setAttribute('role', 'radio');
190
- option.setAttribute('aria-checked', option.selected ? 'true' : 'false');
191
- if (option.selected) {
192
- selections.push(option);
193
- }
194
- });
195
- if (applied)
196
- break;
197
- await Promise.all(updates);
198
- const selected = selections.map((button) => {
199
- return button.value;
200
- });
201
- this.setSelected(selected || EMPTY_SELECTION);
202
- break;
203
- }
204
- case 'multiple': {
205
- this.setAttribute('role', 'group');
206
- const selection = [];
207
- const selections = [];
208
- const updates = options.map(async (option) => {
209
- await option.updateComplete;
210
- option.setAttribute('role', 'checkbox');
211
- option.setAttribute('aria-checked', option.selected ? 'true' : 'false');
212
- if (option.selected) {
213
- selection.push(option.value);
214
- selections.push(option);
215
- }
216
- });
217
- if (applied)
218
- break;
219
- await Promise.all(updates);
220
- const selected = !!selection.length
221
- ? selection
222
- : EMPTY_SELECTION;
223
- this.setSelected(selected);
224
- break;
183
+ const options = this.buttons;
184
+ switch (this.selects) {
185
+ case "single": {
186
+ this.setAttribute("role", "radiogroup");
187
+ const selections = [];
188
+ const updates = options.map(async (option) => {
189
+ await option.updateComplete;
190
+ option.setAttribute("role", "radio");
191
+ option.setAttribute("aria-checked", option.selected ? "true" : "false");
192
+ if (option.selected) {
193
+ selections.push(option);
194
+ }
195
+ });
196
+ if (applied)
197
+ break;
198
+ await Promise.all(updates);
199
+ const selected = selections.map((button) => {
200
+ return button.value;
201
+ });
202
+ this.setSelected(selected || EMPTY_SELECTION);
203
+ break;
204
+ }
205
+ case "multiple": {
206
+ this.setAttribute("role", "group");
207
+ const selection = [];
208
+ const selections = [];
209
+ const updates = options.map(async (option) => {
210
+ await option.updateComplete;
211
+ option.setAttribute("role", "checkbox");
212
+ option.setAttribute("aria-checked", option.selected ? "true" : "false");
213
+ if (option.selected) {
214
+ selection.push(option.value);
215
+ selections.push(option);
216
+ }
217
+ });
218
+ if (applied)
219
+ break;
220
+ await Promise.all(updates);
221
+ const selected = !!selection.length ? selection : EMPTY_SELECTION;
222
+ this.setSelected(selected);
223
+ break;
224
+ }
225
+ default:
226
+ if (this.selected.length) {
227
+ const selections = [];
228
+ const updates = options.map(async (option) => {
229
+ await option.updateComplete;
230
+ option.setAttribute("aria-checked", option.selected ? "true" : "false");
231
+ option.setAttribute("role", "button");
232
+ if (option.selected) {
233
+ selections.push(option);
225
234
  }
226
- default:
227
- // if user defines .selected
228
- if (this.selected.length) {
229
- const selections = [];
230
- const updates = options.map(async (option) => {
231
- await option.updateComplete;
232
- option.setAttribute('aria-checked', option.selected ? 'true' : 'false');
233
- option.setAttribute('role', 'button');
234
- if (option.selected) {
235
- selections.push(option);
236
- }
237
- });
238
- if (applied)
239
- break;
240
- await Promise.all(updates);
241
- this.setSelected(selections.map((button) => {
242
- return button.value;
243
- }));
244
- }
245
- else {
246
- this.buttons.forEach((option) => {
247
- option.setAttribute('role', 'button');
248
- });
249
- this.removeAttribute('role');
250
- break;
251
- }
235
+ });
236
+ if (applied)
237
+ break;
238
+ await Promise.all(updates);
239
+ this.setSelected(selections.map((button) => {
240
+ return button.value;
241
+ }));
242
+ } else {
243
+ this.buttons.forEach((option) => {
244
+ option.setAttribute("role", "button");
245
+ });
246
+ this.removeAttribute("role");
247
+ break;
252
248
  }
253
249
  }
254
- render() {
255
- return html `
250
+ }
251
+ render() {
252
+ return html`
256
253
  <slot role="presentation" @slotchange=${this.manageButtons}></slot>
257
254
  `;
255
+ }
256
+ firstUpdated(changes) {
257
+ super.firstUpdated(changes);
258
+ this.addEventListener("click", this.handleClick);
259
+ }
260
+ updated(changes) {
261
+ super.updated(changes);
262
+ if (changes.has("selects")) {
263
+ this.manageSelects();
264
+ this.manageChildren();
258
265
  }
259
- firstUpdated(changes) {
260
- super.firstUpdated(changes);
261
- this.addEventListener('click', this.handleClick);
262
- }
263
- updated(changes) {
264
- super.updated(changes);
265
- if (changes.has('selects')) {
266
- this.manageSelects();
267
- this.manageChildren();
268
- }
269
- if ((changes.has('quiet') && this.quiet) ||
270
- (changes.has('emphasized') && this.emphasized)) {
271
- this.manageChildren();
272
- }
273
- // Update `aria-label` when `label` available or not first `updated`
274
- if (changes.has('label') &&
275
- (this.label || typeof changes.get('label') !== 'undefined')) {
276
- if (this.label.length) {
277
- this.setAttribute('aria-label', this.label);
278
- }
279
- else {
280
- this.removeAttribute('aria-label');
281
- }
282
- }
283
- }
284
- manageChildren() {
285
- this.buttons.forEach((button) => {
286
- button.quiet = this.quiet;
287
- button.emphasized = this.emphasized;
288
- button.selected = this.selected.includes(button.value);
289
- });
290
- }
291
- connectedCallback() {
292
- super.connectedCallback();
293
- if (!this.observer) {
294
- this.observer = new MutationObserver(this.manageButtons);
295
- this.manageButtons();
296
- }
297
- this.observer.observe(this, { childList: true, subtree: true });
266
+ if (changes.has("quiet") && this.quiet || changes.has("emphasized") && this.emphasized) {
267
+ this.manageChildren();
298
268
  }
299
- disconnectedCallback() {
300
- this.observer.disconnect();
301
- super.disconnectedCallback();
269
+ if (changes.has("label") && (this.label || typeof changes.get("label") !== "undefined")) {
270
+ if (this.label.length) {
271
+ this.setAttribute("aria-label", this.label);
272
+ } else {
273
+ this.removeAttribute("aria-label");
274
+ }
302
275
  }
276
+ }
277
+ manageChildren() {
278
+ this.buttons.forEach((button) => {
279
+ button.quiet = this.quiet;
280
+ button.emphasized = this.emphasized;
281
+ button.selected = this.selected.includes(button.value);
282
+ });
283
+ }
303
284
  }
304
- __decorate([
305
- property({ type: Boolean, reflect: true })
306
- ], ActionGroup.prototype, "compact", void 0);
307
- __decorate([
308
- property({ type: Boolean, reflect: true })
309
- ], ActionGroup.prototype, "emphasized", void 0);
310
- __decorate([
311
- property({ type: Boolean, reflect: true })
312
- ], ActionGroup.prototype, "justified", void 0);
313
- __decorate([
314
- property({ type: String })
315
- ], ActionGroup.prototype, "label", void 0);
316
- __decorate([
317
- property({ type: Boolean, reflect: true })
318
- ], ActionGroup.prototype, "quiet", void 0);
319
- __decorate([
320
- property({ type: String })
321
- ], ActionGroup.prototype, "selects", void 0);
322
- __decorate([
323
- property({ type: Boolean, reflect: true })
324
- ], ActionGroup.prototype, "vertical", void 0);
325
- __decorate([
326
- property({ type: Array })
327
- ], ActionGroup.prototype, "selected", null);
328
- //# sourceMappingURL=ActionGroup.js.map
285
+ __decorateClass([
286
+ property({ type: Boolean, reflect: true })
287
+ ], ActionGroup.prototype, "compact", 2);
288
+ __decorateClass([
289
+ property({ type: Boolean, reflect: true })
290
+ ], ActionGroup.prototype, "emphasized", 2);
291
+ __decorateClass([
292
+ property({ type: Boolean, reflect: true })
293
+ ], ActionGroup.prototype, "justified", 2);
294
+ __decorateClass([
295
+ property({ type: String })
296
+ ], ActionGroup.prototype, "label", 2);
297
+ __decorateClass([
298
+ property({ type: Boolean, reflect: true })
299
+ ], ActionGroup.prototype, "quiet", 2);
300
+ __decorateClass([
301
+ property({ type: String })
302
+ ], ActionGroup.prototype, "selects", 2);
303
+ __decorateClass([
304
+ property({ type: Boolean, reflect: true })
305
+ ], ActionGroup.prototype, "vertical", 2);
306
+ __decorateClass([
307
+ property({ type: Array })
308
+ ], ActionGroup.prototype, "selected", 1);
309
+ //# sourceMappingURL=ActionGroup.js.map