@spectrum-web-components/picker 0.15.0 → 0.15.1-overlay.7
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 +5 -5
- package/src/Picker.d.ts +18 -30
- package/src/Picker.dev.js +118 -167
- package/src/Picker.dev.js.map +3 -3
- package/src/Picker.js +29 -16
- package/src/Picker.js.map +3 -3
- package/src/picker.css.dev.js +1 -1
- package/src/picker.css.dev.js.map +1 -1
- package/src/picker.css.js +1 -1
- package/src/picker.css.js.map +1 -1
- package/sync/index.d.ts +4 -1
- package/sync/index.dev.js +1 -6
- package/sync/index.dev.js.map +2 -2
- package/sync/index.js +1 -1
- package/sync/index.js.map +3 -3
- package/test/index.js +117 -75
- package/test/index.js.map +2 -2
- package/test/picker-reparenting.test.js +16 -2
- package/test/picker-reparenting.test.js.map +2 -2
- package/test/picker-responsive.test.js +2 -2
- package/test/picker-responsive.test.js.map +2 -2
- package/test/picker.test.js +1 -1
- package/test/picker.test.js.map +2 -2
- package/custom-elements.json +0 -1741
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/picker",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1-overlay.7+a493756c7",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"@spectrum-web-components/icon": "^0.12.9",
|
|
71
71
|
"@spectrum-web-components/icons-ui": "^0.9.10",
|
|
72
72
|
"@spectrum-web-components/icons-workflow": "^0.9.10",
|
|
73
|
-
"@spectrum-web-components/menu": "^0.16.
|
|
74
|
-
"@spectrum-web-components/overlay": "^0.19.
|
|
75
|
-
"@spectrum-web-components/popover": "^0.12.
|
|
73
|
+
"@spectrum-web-components/menu": "^0.16.16-overlay.7+a493756c7",
|
|
74
|
+
"@spectrum-web-components/overlay": "^0.19.4-overlay.7+a493756c7",
|
|
75
|
+
"@spectrum-web-components/popover": "^0.12.16-overlay.7+a493756c7",
|
|
76
76
|
"@spectrum-web-components/reactive-controllers": "^0.3.5",
|
|
77
77
|
"@spectrum-web-components/shared": "^0.15.5",
|
|
78
78
|
"@spectrum-web-components/tray": "^0.5.1"
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"./sync/index.js",
|
|
89
89
|
"./sync/sp-*.js"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "a493756c787f12c6266ddeb11cba260cd66b6e41"
|
|
92
92
|
}
|
package/src/Picker.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import { StyleInfo } from '@spectrum-web-components/base/src/directives.js';
|
|
2
3
|
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
3
4
|
import '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';
|
|
4
5
|
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
|
|
6
|
+
import '@spectrum-web-components/overlay/sp-overlay.js';
|
|
5
7
|
import '@spectrum-web-components/menu/sp-menu.js';
|
|
6
|
-
import type { Menu, MenuItem,
|
|
8
|
+
import type { Menu, MenuItem, MenuItemChildren } from '@spectrum-web-components/menu';
|
|
7
9
|
import '@spectrum-web-components/tray/sp-tray.js';
|
|
8
10
|
import '@spectrum-web-components/popover/sp-popover.js';
|
|
9
|
-
import {
|
|
11
|
+
import { Placement } from '@spectrum-web-components/overlay';
|
|
10
12
|
import { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';
|
|
11
13
|
declare const PickerBase_base: typeof Focusable & {
|
|
12
14
|
new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
|
|
@@ -22,10 +24,6 @@ declare const PickerBase_base: typeof Focusable & {
|
|
|
22
24
|
* @fires sp-closed - Announces that the overlay has been closed
|
|
23
25
|
*/
|
|
24
26
|
export declare class PickerBase extends PickerBase_base {
|
|
25
|
-
/**
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
static openOverlay: (target: HTMLElement, interaction: TriggerInteractions, content: HTMLElement, options: OverlayOptions) => Promise<() => void>;
|
|
29
27
|
protected isMobile: MatchMediaController;
|
|
30
28
|
button: HTMLButtonElement;
|
|
31
29
|
get target(): HTMLButtonElement | this;
|
|
@@ -37,8 +35,7 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
37
35
|
open: boolean;
|
|
38
36
|
readonly: boolean;
|
|
39
37
|
selects: undefined | 'single';
|
|
40
|
-
menuItems: MenuItem[];
|
|
41
|
-
private restoreChildren?;
|
|
38
|
+
get menuItems(): MenuItem[];
|
|
42
39
|
optionsMenu: Menu;
|
|
43
40
|
/**
|
|
44
41
|
* @type {"auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end" | "none"}
|
|
@@ -47,9 +44,9 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
47
44
|
placement: Placement;
|
|
48
45
|
quiet: boolean;
|
|
49
46
|
value: string;
|
|
50
|
-
selectedItem
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
get selectedItem(): MenuItem | undefined;
|
|
48
|
+
set selectedItem(selectedItem: MenuItem | undefined);
|
|
49
|
+
_selectedItem?: MenuItem;
|
|
53
50
|
protected listRole: 'listbox' | 'menu';
|
|
54
51
|
protected itemRole: string;
|
|
55
52
|
constructor();
|
|
@@ -64,33 +61,24 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
64
61
|
protected onKeydown: (event: KeyboardEvent) => void;
|
|
65
62
|
setValueFromItem(item: MenuItem, menuChangeEvent?: Event): Promise<void>;
|
|
66
63
|
protected setMenuItemSelected(item: MenuItem, value: boolean): void;
|
|
64
|
+
private preventToggle;
|
|
67
65
|
toggle(target?: boolean): void;
|
|
68
66
|
close(): void;
|
|
69
|
-
|
|
70
|
-
overlayCloseCallback: () => Promise<void>;
|
|
71
|
-
private popoverFragment;
|
|
72
|
-
private generatePopover;
|
|
73
|
-
private openMenu;
|
|
74
|
-
protected sizePopover(popover: HTMLElement): void;
|
|
75
|
-
private closeMenu;
|
|
67
|
+
protected get containerStyles(): StyleInfo;
|
|
76
68
|
protected get selectedItemContent(): MenuItemChildren;
|
|
69
|
+
protected set selectedItemContent(selectedItemContent: MenuItemChildren | undefined);
|
|
70
|
+
_selectedItemContent?: MenuItemChildren;
|
|
77
71
|
protected renderLabelContent(content: Node[]): TemplateResult | Node[];
|
|
78
72
|
protected get buttonContent(): TemplateResult[];
|
|
73
|
+
protected get renderOverlay(): TemplateResult;
|
|
79
74
|
protected render(): TemplateResult;
|
|
80
75
|
protected update(changes: PropertyValues<this>): void;
|
|
81
76
|
protected get dismissHelper(): TemplateResult;
|
|
82
|
-
protected get
|
|
83
|
-
private
|
|
84
|
-
protected
|
|
85
|
-
|
|
86
|
-
* Acquire the available MenuItems in the Picker by
|
|
87
|
-
* direct element query or by assuming the list managed
|
|
88
|
-
* by the Menu within the open options overlay.
|
|
89
|
-
*/
|
|
90
|
-
protected updateMenuItems(event?: MenuItemAddedOrUpdatedEvent | MenuItemRemovedEvent): void;
|
|
77
|
+
protected get renderContainer(): TemplateResult;
|
|
78
|
+
private willManageSelection;
|
|
79
|
+
protected shouldScheduleManageSelection(event?: Event): void;
|
|
80
|
+
protected shouldManageSelection(): void;
|
|
91
81
|
protected manageSelection(): Promise<void>;
|
|
92
|
-
private menuStatePromise;
|
|
93
|
-
private menuStateResolver;
|
|
94
82
|
private selectionPromise;
|
|
95
83
|
private selectionResolver;
|
|
96
84
|
protected getUpdateComplete(): Promise<boolean>;
|
|
@@ -99,7 +87,7 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
99
87
|
}
|
|
100
88
|
export declare class Picker extends PickerBase {
|
|
101
89
|
static get styles(): CSSResultArray;
|
|
102
|
-
protected
|
|
90
|
+
protected get containerStyles(): StyleInfo;
|
|
103
91
|
protected onKeydown: (event: KeyboardEvent) => void;
|
|
104
92
|
}
|
|
105
93
|
export {};
|
package/src/Picker.dev.js
CHANGED
|
@@ -13,10 +13,12 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
13
13
|
import {
|
|
14
14
|
html,
|
|
15
15
|
nothing,
|
|
16
|
-
render,
|
|
17
16
|
SizedMixin
|
|
18
17
|
} from "@spectrum-web-components/base";
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
classMap,
|
|
20
|
+
styleMap
|
|
21
|
+
} from "@spectrum-web-components/base/src/directives.js";
|
|
20
22
|
import {
|
|
21
23
|
property,
|
|
22
24
|
query
|
|
@@ -24,15 +26,12 @@ import {
|
|
|
24
26
|
import pickerStyles from "./picker.css.js";
|
|
25
27
|
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
26
28
|
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
27
|
-
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
28
29
|
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
29
30
|
import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
|
|
31
|
+
import "@spectrum-web-components/overlay/sp-overlay.js";
|
|
30
32
|
import "@spectrum-web-components/menu/sp-menu.js";
|
|
31
33
|
import "@spectrum-web-components/tray/sp-tray.js";
|
|
32
34
|
import "@spectrum-web-components/popover/sp-popover.js";
|
|
33
|
-
import {
|
|
34
|
-
openOverlay
|
|
35
|
-
} from "@spectrum-web-components/overlay";
|
|
36
35
|
import {
|
|
37
36
|
IS_MOBILE,
|
|
38
37
|
MatchMediaController
|
|
@@ -53,7 +52,6 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
53
52
|
this.open = false;
|
|
54
53
|
this.readonly = false;
|
|
55
54
|
this.selects = "single";
|
|
56
|
-
this.menuItems = [];
|
|
57
55
|
this.placement = "bottom-start";
|
|
58
56
|
this.quiet = false;
|
|
59
57
|
this.value = "";
|
|
@@ -67,29 +65,34 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
67
65
|
event.preventDefault();
|
|
68
66
|
this.toggle(true);
|
|
69
67
|
};
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
await this.itemsUpdated;
|
|
73
|
-
await this.optionsMenu.updateComplete;
|
|
74
|
-
requestAnimationFrame(() => this.menuStateResolver());
|
|
75
|
-
};
|
|
76
|
-
this.overlayCloseCallback = async () => {
|
|
77
|
-
if (this.restoreChildren) {
|
|
78
|
-
this.restoreChildren();
|
|
79
|
-
this.restoreChildren = void 0;
|
|
80
|
-
}
|
|
81
|
-
this.close();
|
|
82
|
-
requestAnimationFrame(() => this.menuStateResolver());
|
|
83
|
-
};
|
|
84
|
-
this._willUpdateItems = false;
|
|
85
|
-
this.itemsUpdated = Promise.resolve();
|
|
86
|
-
this.menuStatePromise = Promise.resolve();
|
|
68
|
+
this.preventToggle = false;
|
|
69
|
+
this.willManageSelection = false;
|
|
87
70
|
this.selectionPromise = Promise.resolve();
|
|
88
71
|
this.onKeydown = this.onKeydown.bind(this);
|
|
72
|
+
this.addEventListener("focusout", (event) => {
|
|
73
|
+
if (event.relatedTarget && this.contains(event.relatedTarget) || event.target !== this) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.open = false;
|
|
77
|
+
});
|
|
89
78
|
}
|
|
90
79
|
get target() {
|
|
91
80
|
return this.button;
|
|
92
81
|
}
|
|
82
|
+
get menuItems() {
|
|
83
|
+
return this.optionsMenu.childItems;
|
|
84
|
+
}
|
|
85
|
+
get selectedItem() {
|
|
86
|
+
return this._selectedItem;
|
|
87
|
+
}
|
|
88
|
+
set selectedItem(selectedItem) {
|
|
89
|
+
this.selectedItemContent = selectedItem ? selectedItem.itemChildren : void 0;
|
|
90
|
+
if (selectedItem === this.selectedItem)
|
|
91
|
+
return;
|
|
92
|
+
const oldSelectedItem = this.selectedItem;
|
|
93
|
+
this._selectedItem = selectedItem;
|
|
94
|
+
this.requestUpdate("selectedItem", oldSelectedItem);
|
|
95
|
+
}
|
|
93
96
|
get focusElement() {
|
|
94
97
|
if (this.open) {
|
|
95
98
|
return this.optionsMenu;
|
|
@@ -128,20 +131,22 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
128
131
|
handleChange(event) {
|
|
129
132
|
const target = event.target;
|
|
130
133
|
const [selected] = target.selectedItems;
|
|
134
|
+
event.stopPropagation();
|
|
131
135
|
if (event.cancelable) {
|
|
132
|
-
event.stopPropagation();
|
|
133
136
|
this.setValueFromItem(selected, event);
|
|
134
137
|
} else {
|
|
135
138
|
this.open = false;
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
async setValueFromItem(item, menuChangeEvent) {
|
|
142
|
+
this.open = false;
|
|
139
143
|
const oldSelectedItem = this.selectedItem;
|
|
140
144
|
const oldValue = this.value;
|
|
141
|
-
this.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
if (this.selects) {
|
|
146
|
+
this.selectedItem = item;
|
|
147
|
+
this.value = item.value;
|
|
148
|
+
await this.updateComplete;
|
|
149
|
+
}
|
|
145
150
|
const applyDefault = this.dispatchEvent(
|
|
146
151
|
new Event("change", {
|
|
147
152
|
bubbles: true,
|
|
@@ -149,7 +154,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
149
154
|
composed: true
|
|
150
155
|
})
|
|
151
156
|
);
|
|
152
|
-
if (!applyDefault) {
|
|
157
|
+
if (!applyDefault && this.selects) {
|
|
153
158
|
if (menuChangeEvent) {
|
|
154
159
|
menuChangeEvent.preventDefault();
|
|
155
160
|
}
|
|
@@ -173,6 +178,8 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
173
178
|
item.selected = value;
|
|
174
179
|
}
|
|
175
180
|
toggle(target) {
|
|
181
|
+
if (this.preventToggle)
|
|
182
|
+
return;
|
|
176
183
|
if (this.readonly) {
|
|
177
184
|
return;
|
|
178
185
|
}
|
|
@@ -184,74 +191,23 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
184
191
|
}
|
|
185
192
|
this.open = false;
|
|
186
193
|
}
|
|
187
|
-
|
|
188
|
-
if (!this.popoverFragment) {
|
|
189
|
-
this.popoverFragment = document.createDocumentFragment();
|
|
190
|
-
}
|
|
191
|
-
render(this.renderPopover, this.popoverFragment, { host: this });
|
|
192
|
-
this.popoverEl = this.popoverFragment.children[0];
|
|
193
|
-
this.optionsMenu = this.popoverEl.children[1];
|
|
194
|
-
}
|
|
195
|
-
async openMenu() {
|
|
196
|
-
let reparentableChildren = [];
|
|
197
|
-
const deprecatedMenu = this.querySelector(":scope > sp-menu");
|
|
198
|
-
await this.generatePopover();
|
|
199
|
-
if (deprecatedMenu) {
|
|
200
|
-
reparentableChildren = Array.from(deprecatedMenu.children);
|
|
201
|
-
} else {
|
|
202
|
-
reparentableChildren = Array.from(this.children).filter(
|
|
203
|
-
(element) => {
|
|
204
|
-
return !element.hasAttribute("slot");
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
if (reparentableChildren.length === 0) {
|
|
209
|
-
this.menuStateResolver();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
this.restoreChildren = reparentChildren(reparentableChildren, this.optionsMenu, {
|
|
213
|
-
position: "beforeend",
|
|
214
|
-
prepareCallback: (el) => {
|
|
215
|
-
if (this.value === el.value) {
|
|
216
|
-
this.setMenuItemSelected(el, true);
|
|
217
|
-
}
|
|
218
|
-
return (el2) => {
|
|
219
|
-
if (typeof el2.focused !== "undefined") {
|
|
220
|
-
el2.focused = false;
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
this.sizePopover(this.popoverEl);
|
|
226
|
-
if (true) {
|
|
227
|
-
window.__swc.ignoreWarningLevels.deprecation = true;
|
|
228
|
-
}
|
|
229
|
-
this.closeOverlay = Picker.openOverlay(this, "modal", this.popoverEl, {
|
|
230
|
-
placement: this.isMobile.matches ? "none" : this.placement,
|
|
231
|
-
receivesFocus: "auto"
|
|
232
|
-
});
|
|
233
|
-
if (true) {
|
|
234
|
-
window.__swc.ignoreWarningLevels.deprecation = false;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
sizePopover(popover) {
|
|
194
|
+
get containerStyles() {
|
|
238
195
|
if (this.isMobile.matches) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
async closeMenu() {
|
|
244
|
-
if (this.closeOverlay) {
|
|
245
|
-
const closeOverlay = this.closeOverlay;
|
|
246
|
-
delete this.closeOverlay;
|
|
247
|
-
(await closeOverlay)();
|
|
196
|
+
return {
|
|
197
|
+
"--swc-menu-width": "100%"
|
|
198
|
+
};
|
|
248
199
|
}
|
|
200
|
+
return {};
|
|
249
201
|
}
|
|
250
202
|
get selectedItemContent() {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
203
|
+
return this._selectedItemContent || { icon: [], content: [] };
|
|
204
|
+
}
|
|
205
|
+
set selectedItemContent(selectedItemContent) {
|
|
206
|
+
if (selectedItemContent === this.selectedItemContent)
|
|
207
|
+
return;
|
|
208
|
+
const oldContent = this.selectedItemContent;
|
|
209
|
+
this._selectedItemContent = selectedItemContent;
|
|
210
|
+
this.requestUpdate("selectedItemContent", oldContent);
|
|
255
211
|
}
|
|
256
212
|
renderLabelContent(content) {
|
|
257
213
|
if (this.value && this.selectedItem) {
|
|
@@ -285,13 +241,39 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
285
241
|
`
|
|
286
242
|
];
|
|
287
243
|
}
|
|
244
|
+
get renderOverlay() {
|
|
245
|
+
return html`
|
|
246
|
+
<sp-overlay
|
|
247
|
+
.triggerElement=${this}
|
|
248
|
+
.offset=${0}
|
|
249
|
+
?open=${this.open}
|
|
250
|
+
.placement=${this.placement}
|
|
251
|
+
type="auto"
|
|
252
|
+
@beforetoggle=${(event) => {
|
|
253
|
+
this.open = event.target.open;
|
|
254
|
+
if (!this.open) {
|
|
255
|
+
this.preventToggle = true;
|
|
256
|
+
requestAnimationFrame(
|
|
257
|
+
() => this.preventToggle = false
|
|
258
|
+
);
|
|
259
|
+
this.optionsMenu.updateSelectedItemIndex();
|
|
260
|
+
this.optionsMenu.closeDescendentOverlays();
|
|
261
|
+
} else {
|
|
262
|
+
this.optionsMenu.focus();
|
|
263
|
+
}
|
|
264
|
+
}}
|
|
265
|
+
>
|
|
266
|
+
${this.renderContainer}
|
|
267
|
+
</sp-overlay>
|
|
268
|
+
`;
|
|
269
|
+
}
|
|
288
270
|
// a helper to throw focus to the button is needed because Safari
|
|
289
271
|
// won't include buttons in the tab order even with tabindex="0"
|
|
290
272
|
render() {
|
|
291
273
|
return html`
|
|
292
274
|
<span
|
|
293
275
|
id="focus-helper"
|
|
294
|
-
tabindex="${this.focused ? "-1" : "0"}"
|
|
276
|
+
tabindex="${this.focused || this.open ? "-1" : "0"}"
|
|
295
277
|
@focus=${this.onHelperFocus}
|
|
296
278
|
></span>
|
|
297
279
|
<button
|
|
@@ -308,6 +290,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
308
290
|
>
|
|
309
291
|
${this.buttonContent}
|
|
310
292
|
</button>
|
|
293
|
+
${this.renderOverlay}
|
|
311
294
|
`;
|
|
312
295
|
}
|
|
313
296
|
update(changes) {
|
|
@@ -317,18 +300,8 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
317
300
|
if (changes.has("disabled") && this.disabled) {
|
|
318
301
|
this.open = false;
|
|
319
302
|
}
|
|
320
|
-
if (changes.has("
|
|
321
|
-
this.
|
|
322
|
-
(res) => this.menuStateResolver = res
|
|
323
|
-
);
|
|
324
|
-
if (this.open) {
|
|
325
|
-
this.openMenu();
|
|
326
|
-
} else {
|
|
327
|
-
this.closeMenu();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (changes.has("value") && !changes.has("selectedItem")) {
|
|
331
|
-
this.updateMenuItems();
|
|
303
|
+
if (changes.has("value")) {
|
|
304
|
+
this.shouldScheduleManageSelection();
|
|
332
305
|
}
|
|
333
306
|
if (true) {
|
|
334
307
|
if (!this.hasUpdated && this.querySelector("sp-menu")) {
|
|
@@ -354,7 +327,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
354
327
|
</div>
|
|
355
328
|
`;
|
|
356
329
|
}
|
|
357
|
-
get
|
|
330
|
+
get renderContainer() {
|
|
358
331
|
const content = html`
|
|
359
332
|
${this.dismissHelper}
|
|
360
333
|
<sp-menu
|
|
@@ -362,7 +335,11 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
362
335
|
role="${this.listRole}"
|
|
363
336
|
@change=${this.handleChange}
|
|
364
337
|
.selects=${this.selects}
|
|
365
|
-
|
|
338
|
+
.selected=${this.value ? [this.value] : []}
|
|
339
|
+
@sp-menu-item-added-or-updated=${this.shouldManageSelection}
|
|
340
|
+
>
|
|
341
|
+
<slot @slotchange=${this.shouldScheduleManageSelection}></slot>
|
|
342
|
+
</sp-menu>
|
|
366
343
|
${this.dismissHelper}
|
|
367
344
|
`;
|
|
368
345
|
if (this.isMobile.matches) {
|
|
@@ -370,9 +347,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
370
347
|
<sp-tray
|
|
371
348
|
id="popover"
|
|
372
349
|
role="dialog"
|
|
373
|
-
|
|
374
|
-
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
375
|
-
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
350
|
+
style=${styleMap(this.containerStyles)}
|
|
376
351
|
>
|
|
377
352
|
${content}
|
|
378
353
|
</sp-tray>
|
|
@@ -382,56 +357,38 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
382
357
|
<sp-popover
|
|
383
358
|
id="popover"
|
|
384
359
|
role="dialog"
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
360
|
+
style=${styleMap(this.containerStyles)}
|
|
361
|
+
placement=${this.placement}
|
|
388
362
|
>
|
|
389
363
|
${content}
|
|
390
364
|
</sp-popover>
|
|
391
365
|
`;
|
|
392
366
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (this._willUpdateItems)
|
|
402
|
-
return;
|
|
403
|
-
this._willUpdateItems = true;
|
|
404
|
-
if ((event == null ? void 0 : event.item) === this.selectedItem) {
|
|
405
|
-
this.requestUpdate();
|
|
367
|
+
shouldScheduleManageSelection(event) {
|
|
368
|
+
if (!this.willManageSelection && (!event || event.target.getRootNode().host === this)) {
|
|
369
|
+
this.willManageSelection = true;
|
|
370
|
+
requestAnimationFrame(() => {
|
|
371
|
+
requestAnimationFrame(() => {
|
|
372
|
+
this.manageSelection();
|
|
373
|
+
});
|
|
374
|
+
});
|
|
406
375
|
}
|
|
407
|
-
|
|
376
|
+
}
|
|
377
|
+
shouldManageSelection() {
|
|
378
|
+
if (this.willManageSelection) {
|
|
408
379
|
return;
|
|
409
|
-
}
|
|
410
|
-
this.
|
|
411
|
-
|
|
412
|
-
if (this.open) {
|
|
413
|
-
await this.optionsMenu.updateComplete;
|
|
414
|
-
this.menuItems = this.optionsMenu.childItems;
|
|
415
|
-
} else {
|
|
416
|
-
this.menuItems = [
|
|
417
|
-
...this.querySelectorAll(
|
|
418
|
-
'sp-menu-item:not([slot="submenu"] *)'
|
|
419
|
-
)
|
|
420
|
-
];
|
|
421
|
-
}
|
|
422
|
-
this.manageSelection();
|
|
423
|
-
resolve();
|
|
424
|
-
this._willUpdateItems = false;
|
|
425
|
-
});
|
|
380
|
+
}
|
|
381
|
+
this.willManageSelection = true;
|
|
382
|
+
this.manageSelection();
|
|
426
383
|
}
|
|
427
384
|
async manageSelection() {
|
|
428
385
|
if (this.selects == null)
|
|
429
386
|
return;
|
|
430
|
-
await this.menuStatePromise;
|
|
431
387
|
this.selectionPromise = new Promise(
|
|
432
388
|
(res) => this.selectionResolver = res
|
|
433
389
|
);
|
|
434
390
|
let selectedItem;
|
|
391
|
+
await this.optionsMenu.updateComplete;
|
|
435
392
|
this.menuItems.forEach((item) => {
|
|
436
393
|
if (this.value === item.value && !item.disabled) {
|
|
437
394
|
selectedItem = item;
|
|
@@ -451,21 +408,14 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
451
408
|
this.optionsMenu.updateSelectedItemIndex();
|
|
452
409
|
}
|
|
453
410
|
this.selectionResolver();
|
|
411
|
+
this.willManageSelection = false;
|
|
454
412
|
}
|
|
455
413
|
async getUpdateComplete() {
|
|
456
414
|
const complete = await super.getUpdateComplete();
|
|
457
|
-
await this.menuStatePromise;
|
|
458
|
-
await this.itemsUpdated;
|
|
459
415
|
await this.selectionPromise;
|
|
460
416
|
return complete;
|
|
461
417
|
}
|
|
462
418
|
connectedCallback() {
|
|
463
|
-
this.updateMenuItems();
|
|
464
|
-
this.addEventListener(
|
|
465
|
-
"sp-menu-item-added-or-updated",
|
|
466
|
-
this.updateMenuItems
|
|
467
|
-
);
|
|
468
|
-
this.addEventListener("sp-menu-item-removed", this.updateMenuItems);
|
|
469
419
|
super.connectedCallback();
|
|
470
420
|
}
|
|
471
421
|
disconnectedCallback() {
|
|
@@ -473,12 +423,6 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
473
423
|
super.disconnectedCallback();
|
|
474
424
|
}
|
|
475
425
|
}
|
|
476
|
-
/**
|
|
477
|
-
* @private
|
|
478
|
-
*/
|
|
479
|
-
PickerBase.openOverlay = async (target, interaction, content, options) => {
|
|
480
|
-
return await openOverlay(target, interaction, content, options);
|
|
481
|
-
};
|
|
482
426
|
__decorateClass([
|
|
483
427
|
query("#button")
|
|
484
428
|
], PickerBase.prototype, "button", 2);
|
|
@@ -503,6 +447,9 @@ __decorateClass([
|
|
|
503
447
|
__decorateClass([
|
|
504
448
|
property({ type: Boolean, reflect: true })
|
|
505
449
|
], PickerBase.prototype, "readonly", 2);
|
|
450
|
+
__decorateClass([
|
|
451
|
+
query("sp-menu")
|
|
452
|
+
], PickerBase.prototype, "optionsMenu", 2);
|
|
506
453
|
__decorateClass([
|
|
507
454
|
property()
|
|
508
455
|
], PickerBase.prototype, "placement", 2);
|
|
@@ -514,7 +461,10 @@ __decorateClass([
|
|
|
514
461
|
], PickerBase.prototype, "value", 2);
|
|
515
462
|
__decorateClass([
|
|
516
463
|
property({ attribute: false })
|
|
517
|
-
], PickerBase.prototype, "selectedItem",
|
|
464
|
+
], PickerBase.prototype, "selectedItem", 1);
|
|
465
|
+
__decorateClass([
|
|
466
|
+
property({ attribute: false })
|
|
467
|
+
], PickerBase.prototype, "selectedItemContent", 1);
|
|
518
468
|
export class Picker extends PickerBase {
|
|
519
469
|
constructor() {
|
|
520
470
|
super(...arguments);
|
|
@@ -546,11 +496,12 @@ export class Picker extends PickerBase {
|
|
|
546
496
|
static get styles() {
|
|
547
497
|
return [pickerStyles, chevronStyles];
|
|
548
498
|
}
|
|
549
|
-
|
|
550
|
-
super.
|
|
551
|
-
if (this.quiet)
|
|
552
|
-
|
|
553
|
-
|
|
499
|
+
get containerStyles() {
|
|
500
|
+
const styles = super.containerStyles;
|
|
501
|
+
if (!this.quiet) {
|
|
502
|
+
styles["min-width"] = `${this.offsetWidth}px`;
|
|
503
|
+
}
|
|
504
|
+
return styles;
|
|
554
505
|
}
|
|
555
506
|
}
|
|
556
507
|
//# sourceMappingURL=Picker.dev.js.map
|