@spectrum-web-components/picker 0.31.1-overlay.29 → 0.31.1-react.21
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/custom-elements.json +1734 -0
- package/package.json +14 -14
- package/src/Picker.d.ts +31 -19
- package/src/Picker.dev.js +171 -126
- package/src/Picker.dev.js.map +3 -3
- package/src/Picker.js +16 -31
- package/src/Picker.js.map +3 -3
- package/src/picker.css.dev.js +67 -35
- package/src/picker.css.dev.js.map +2 -2
- package/src/picker.css.js +67 -35
- package/src/picker.css.js.map +2 -2
- package/src/spectrum-picker.css.dev.js +66 -34
- package/src/spectrum-picker.css.dev.js.map +2 -2
- package/src/spectrum-picker.css.js +66 -34
- package/src/spectrum-picker.css.js.map +2 -2
- package/sync/index.d.ts +1 -4
- package/sync/index.dev.js +6 -1
- 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 +142 -185
- package/test/index.js.map +2 -2
- package/test/picker-reparenting.test.js +17 -10
- package/test/picker-reparenting.test.js.map +2 -2
- package/test/picker-responsive.test.js +2 -3
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/picker",
|
|
3
|
-
"version": "0.31.1-
|
|
3
|
+
"version": "0.31.1-react.21+44f0b1df9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -65,20 +65,20 @@
|
|
|
65
65
|
"lit-html"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@spectrum-web-components/base": "^0.31.1-
|
|
69
|
-
"@spectrum-web-components/button": "^0.31.1-
|
|
70
|
-
"@spectrum-web-components/icon": "^0.31.1-
|
|
71
|
-
"@spectrum-web-components/icons-ui": "^0.31.1-
|
|
72
|
-
"@spectrum-web-components/icons-workflow": "^0.31.1-
|
|
73
|
-
"@spectrum-web-components/menu": "^0.31.1-
|
|
74
|
-
"@spectrum-web-components/overlay": "^0.31.1-
|
|
75
|
-
"@spectrum-web-components/popover": "^0.31.1-
|
|
76
|
-
"@spectrum-web-components/reactive-controllers": "^0.31.1-
|
|
77
|
-
"@spectrum-web-components/shared": "^0.31.1-
|
|
78
|
-
"@spectrum-web-components/tray": "^0.31.1-
|
|
68
|
+
"@spectrum-web-components/base": "^0.31.1-react.21+44f0b1df9",
|
|
69
|
+
"@spectrum-web-components/button": "^0.31.1-react.21+44f0b1df9",
|
|
70
|
+
"@spectrum-web-components/icon": "^0.31.1-react.21+44f0b1df9",
|
|
71
|
+
"@spectrum-web-components/icons-ui": "^0.31.1-react.21+44f0b1df9",
|
|
72
|
+
"@spectrum-web-components/icons-workflow": "^0.31.1-react.21+44f0b1df9",
|
|
73
|
+
"@spectrum-web-components/menu": "^0.31.1-react.21+44f0b1df9",
|
|
74
|
+
"@spectrum-web-components/overlay": "^0.31.1-react.21+44f0b1df9",
|
|
75
|
+
"@spectrum-web-components/popover": "^0.31.1-react.21+44f0b1df9",
|
|
76
|
+
"@spectrum-web-components/reactive-controllers": "^0.31.1-react.21+44f0b1df9",
|
|
77
|
+
"@spectrum-web-components/shared": "^0.31.1-react.21+44f0b1df9",
|
|
78
|
+
"@spectrum-web-components/tray": "^0.31.1-react.21+44f0b1df9"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@spectrum-css/picker": "^
|
|
81
|
+
"@spectrum-css/picker": "^4.0.7"
|
|
82
82
|
},
|
|
83
83
|
"types": "./src/index.d.ts",
|
|
84
84
|
"customElements": "custom-elements.json",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"./sync/index.js",
|
|
89
89
|
"./sync/sp-*.js"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "44f0b1df9e1ea77d9e931629a63918ceee2744c2"
|
|
92
92
|
}
|
package/src/Picker.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
-
import { StyleInfo } from '@spectrum-web-components/base/src/directives.js';
|
|
3
2
|
import { Focusable } from '@spectrum-web-components/shared/src/focusable.js';
|
|
4
3
|
import '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';
|
|
5
4
|
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js';
|
|
6
|
-
import '@spectrum-web-components/overlay/sp-overlay.js';
|
|
7
5
|
import '@spectrum-web-components/menu/sp-menu.js';
|
|
8
|
-
import type { Menu, MenuItem, MenuItemChildren } from '@spectrum-web-components/menu';
|
|
6
|
+
import type { Menu, MenuItem, MenuItemAddedOrUpdatedEvent, MenuItemChildren, MenuItemRemovedEvent } from '@spectrum-web-components/menu';
|
|
9
7
|
import '@spectrum-web-components/tray/sp-tray.js';
|
|
10
8
|
import '@spectrum-web-components/popover/sp-popover.js';
|
|
11
|
-
import { Placement } from '@spectrum-web-components/overlay';
|
|
9
|
+
import { OverlayOptions, Placement, TriggerInteractions } from '@spectrum-web-components/overlay';
|
|
12
10
|
import { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';
|
|
13
11
|
declare const PickerBase_base: typeof Focusable & {
|
|
14
12
|
new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
|
|
15
13
|
prototype: import("@spectrum-web-components/base").SizedElementInterface;
|
|
16
14
|
};
|
|
17
15
|
export declare class PickerBase extends PickerBase_base {
|
|
16
|
+
/**
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
static openOverlay: (target: HTMLElement, interaction: TriggerInteractions, content: HTMLElement, options: OverlayOptions) => Promise<() => void>;
|
|
18
20
|
protected isMobile: MatchMediaController;
|
|
19
21
|
button: HTMLButtonElement;
|
|
20
22
|
get target(): HTMLButtonElement | this;
|
|
@@ -26,7 +28,8 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
26
28
|
open: boolean;
|
|
27
29
|
readonly: boolean;
|
|
28
30
|
selects: undefined | 'single';
|
|
29
|
-
|
|
31
|
+
menuItems: MenuItem[];
|
|
32
|
+
private restoreChildren?;
|
|
30
33
|
optionsMenu: Menu;
|
|
31
34
|
/**
|
|
32
35
|
* @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"}
|
|
@@ -35,17 +38,15 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
35
38
|
placement: Placement;
|
|
36
39
|
quiet: boolean;
|
|
37
40
|
value: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
selectedItem?: MenuItem;
|
|
42
|
+
private closeOverlay?;
|
|
43
|
+
private popoverEl;
|
|
41
44
|
protected listRole: 'listbox' | 'menu';
|
|
42
45
|
protected itemRole: string;
|
|
43
46
|
constructor();
|
|
44
47
|
get focusElement(): HTMLElement;
|
|
45
48
|
forceFocusVisible(): void;
|
|
46
49
|
onButtonBlur(): void;
|
|
47
|
-
private preventNextToggle;
|
|
48
|
-
protected handlePointerdown(): void;
|
|
49
50
|
protected onButtonClick(): void;
|
|
50
51
|
focus(options?: FocusOptions): void;
|
|
51
52
|
onHelperFocus(): void;
|
|
@@ -56,24 +57,35 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
56
57
|
protected setMenuItemSelected(item: MenuItem, value: boolean): void;
|
|
57
58
|
toggle(target?: boolean): void;
|
|
58
59
|
close(): void;
|
|
59
|
-
|
|
60
|
+
overlayOpenCallback: () => Promise<void>;
|
|
61
|
+
overlayCloseCallback: () => Promise<void>;
|
|
62
|
+
private popoverFragment;
|
|
63
|
+
private generatePopover;
|
|
64
|
+
private openMenu;
|
|
65
|
+
protected sizePopover(popover: HTMLElement): void;
|
|
66
|
+
private closeMenu;
|
|
60
67
|
protected get selectedItemContent(): MenuItemChildren;
|
|
61
|
-
protected set selectedItemContent(selectedItemContent: MenuItemChildren | undefined);
|
|
62
|
-
_selectedItemContent?: MenuItemChildren;
|
|
63
68
|
protected renderLabelContent(content: Node[]): TemplateResult | Node[];
|
|
64
69
|
protected get buttonContent(): TemplateResult[];
|
|
65
|
-
protected get renderOverlay(): TemplateResult;
|
|
66
70
|
protected render(): TemplateResult;
|
|
67
71
|
protected update(changes: PropertyValues<this>): void;
|
|
68
72
|
protected get dismissHelper(): TemplateResult;
|
|
69
|
-
protected get
|
|
70
|
-
private
|
|
71
|
-
protected
|
|
72
|
-
|
|
73
|
+
protected get renderPopover(): TemplateResult;
|
|
74
|
+
private _willUpdateItems;
|
|
75
|
+
protected itemsUpdated: Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Acquire the available MenuItems in the Picker by
|
|
78
|
+
* direct element query or by assuming the list managed
|
|
79
|
+
* by the Menu within the open options overlay.
|
|
80
|
+
*/
|
|
81
|
+
protected updateMenuItems(event?: MenuItemAddedOrUpdatedEvent | MenuItemRemovedEvent): void;
|
|
73
82
|
protected manageSelection(): Promise<void>;
|
|
83
|
+
private menuStatePromise;
|
|
84
|
+
private menuStateResolver;
|
|
74
85
|
private selectionPromise;
|
|
75
86
|
private selectionResolver;
|
|
76
87
|
protected getUpdateComplete(): Promise<boolean>;
|
|
88
|
+
connectedCallback(): void;
|
|
77
89
|
disconnectedCallback(): void;
|
|
78
90
|
}
|
|
79
91
|
/**
|
|
@@ -87,7 +99,7 @@ export declare class PickerBase extends PickerBase_base {
|
|
|
87
99
|
*/
|
|
88
100
|
export declare class Picker extends PickerBase {
|
|
89
101
|
static get styles(): CSSResultArray;
|
|
90
|
-
protected
|
|
102
|
+
protected sizePopover(popover: HTMLElement): void;
|
|
91
103
|
protected onKeydown: (event: KeyboardEvent) => void;
|
|
92
104
|
}
|
|
93
105
|
export {};
|
package/src/Picker.dev.js
CHANGED
|
@@ -13,12 +13,10 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
13
13
|
import {
|
|
14
14
|
html,
|
|
15
15
|
nothing,
|
|
16
|
+
render,
|
|
16
17
|
SizedMixin
|
|
17
18
|
} from "@spectrum-web-components/base";
|
|
18
|
-
import {
|
|
19
|
-
classMap,
|
|
20
|
-
styleMap
|
|
21
|
-
} from "@spectrum-web-components/base/src/directives.js";
|
|
19
|
+
import { classMap } from "@spectrum-web-components/base/src/directives.js";
|
|
22
20
|
import {
|
|
23
21
|
property,
|
|
24
22
|
query
|
|
@@ -26,12 +24,15 @@ import {
|
|
|
26
24
|
import pickerStyles from "./picker.css.js";
|
|
27
25
|
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
28
26
|
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
27
|
+
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
29
28
|
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
30
29
|
import "@spectrum-web-components/icons-workflow/icons/sp-icon-alert.js";
|
|
31
|
-
import "@spectrum-web-components/overlay/sp-overlay.js";
|
|
32
30
|
import "@spectrum-web-components/menu/sp-menu.js";
|
|
33
31
|
import "@spectrum-web-components/tray/sp-tray.js";
|
|
34
32
|
import "@spectrum-web-components/popover/sp-popover.js";
|
|
33
|
+
import {
|
|
34
|
+
openOverlay
|
|
35
|
+
} from "@spectrum-web-components/overlay";
|
|
35
36
|
import {
|
|
36
37
|
IS_MOBILE,
|
|
37
38
|
MatchMediaController
|
|
@@ -52,12 +53,12 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
52
53
|
this.open = false;
|
|
53
54
|
this.readonly = false;
|
|
54
55
|
this.selects = "single";
|
|
56
|
+
this.menuItems = [];
|
|
55
57
|
this.placement = "bottom-start";
|
|
56
58
|
this.quiet = false;
|
|
57
59
|
this.value = "";
|
|
58
60
|
this.listRole = "listbox";
|
|
59
61
|
this.itemRole = "option";
|
|
60
|
-
this.preventNextToggle = false;
|
|
61
62
|
this.onKeydown = (event) => {
|
|
62
63
|
this.focused = true;
|
|
63
64
|
if (event.code !== "ArrowDown" && event.code !== "ArrowUp") {
|
|
@@ -66,33 +67,29 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
66
67
|
event.preventDefault();
|
|
67
68
|
this.toggle(true);
|
|
68
69
|
};
|
|
69
|
-
this.
|
|
70
|
+
this.overlayOpenCallback = async () => {
|
|
71
|
+
this.updateMenuItems();
|
|
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();
|
|
70
87
|
this.selectionPromise = Promise.resolve();
|
|
71
88
|
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
|
-
});
|
|
78
89
|
}
|
|
79
90
|
get target() {
|
|
80
91
|
return this.button;
|
|
81
92
|
}
|
|
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
|
-
}
|
|
96
93
|
get focusElement() {
|
|
97
94
|
if (this.open) {
|
|
98
95
|
return this.optionsMenu;
|
|
@@ -109,14 +106,8 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
109
106
|
this.onKeydown
|
|
110
107
|
);
|
|
111
108
|
}
|
|
112
|
-
handlePointerdown() {
|
|
113
|
-
this.preventNextToggle = this.open;
|
|
114
|
-
}
|
|
115
109
|
onButtonClick() {
|
|
116
|
-
|
|
117
|
-
this.toggle();
|
|
118
|
-
}
|
|
119
|
-
this.preventNextToggle = false;
|
|
110
|
+
this.toggle();
|
|
120
111
|
}
|
|
121
112
|
focus(options) {
|
|
122
113
|
super.focus(options);
|
|
@@ -137,22 +128,20 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
137
128
|
handleChange(event) {
|
|
138
129
|
const target = event.target;
|
|
139
130
|
const [selected] = target.selectedItems;
|
|
140
|
-
event.stopPropagation();
|
|
141
131
|
if (event.cancelable) {
|
|
132
|
+
event.stopPropagation();
|
|
142
133
|
this.setValueFromItem(selected, event);
|
|
143
134
|
} else {
|
|
144
135
|
this.open = false;
|
|
145
136
|
}
|
|
146
137
|
}
|
|
147
138
|
async setValueFromItem(item, menuChangeEvent) {
|
|
148
|
-
this.open = false;
|
|
149
139
|
const oldSelectedItem = this.selectedItem;
|
|
150
140
|
const oldValue = this.value;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
141
|
+
this.selectedItem = item;
|
|
142
|
+
this.value = item.value;
|
|
143
|
+
this.open = false;
|
|
144
|
+
await this.updateComplete;
|
|
156
145
|
const applyDefault = this.dispatchEvent(
|
|
157
146
|
new Event("change", {
|
|
158
147
|
bubbles: true,
|
|
@@ -160,7 +149,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
160
149
|
composed: true
|
|
161
150
|
})
|
|
162
151
|
);
|
|
163
|
-
if (!applyDefault
|
|
152
|
+
if (!applyDefault) {
|
|
164
153
|
if (menuChangeEvent) {
|
|
165
154
|
menuChangeEvent.preventDefault();
|
|
166
155
|
}
|
|
@@ -195,23 +184,74 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
195
184
|
}
|
|
196
185
|
this.open = false;
|
|
197
186
|
}
|
|
198
|
-
|
|
187
|
+
async generatePopover() {
|
|
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) {
|
|
199
238
|
if (this.isMobile.matches) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
};
|
|
239
|
+
popover.style.setProperty("--swc-menu-width", `100%`);
|
|
240
|
+
return;
|
|
203
241
|
}
|
|
204
|
-
return {};
|
|
205
242
|
}
|
|
206
|
-
|
|
207
|
-
|
|
243
|
+
async closeMenu() {
|
|
244
|
+
if (this.closeOverlay) {
|
|
245
|
+
const closeOverlay = this.closeOverlay;
|
|
246
|
+
delete this.closeOverlay;
|
|
247
|
+
(await closeOverlay)();
|
|
248
|
+
}
|
|
208
249
|
}
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
return;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this.requestUpdate("selectedItemContent", oldContent);
|
|
250
|
+
get selectedItemContent() {
|
|
251
|
+
if (this.selectedItem) {
|
|
252
|
+
return this.selectedItem.itemChildren;
|
|
253
|
+
}
|
|
254
|
+
return { icon: [], content: [] };
|
|
215
255
|
}
|
|
216
256
|
renderLabelContent(content) {
|
|
217
257
|
if (this.value && this.selectedItem) {
|
|
@@ -245,37 +285,13 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
245
285
|
`
|
|
246
286
|
];
|
|
247
287
|
}
|
|
248
|
-
get renderOverlay() {
|
|
249
|
-
return html`
|
|
250
|
-
<sp-overlay
|
|
251
|
-
.triggerElement=${this}
|
|
252
|
-
.offset=${0}
|
|
253
|
-
?open=${this.open}
|
|
254
|
-
.placement=${this.placement}
|
|
255
|
-
type="auto"
|
|
256
|
-
.receivesFocus=${"true"}
|
|
257
|
-
@beforetoggle=${(event) => {
|
|
258
|
-
if (event.composedPath()[0] !== event.target) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
this.open = event.newState === "open";
|
|
262
|
-
if (!this.open) {
|
|
263
|
-
this.optionsMenu.updateSelectedItemIndex();
|
|
264
|
-
this.optionsMenu.closeDescendentOverlays();
|
|
265
|
-
}
|
|
266
|
-
}}
|
|
267
|
-
>
|
|
268
|
-
${this.renderContainer}
|
|
269
|
-
</sp-overlay>
|
|
270
|
-
`;
|
|
271
|
-
}
|
|
272
288
|
// a helper to throw focus to the button is needed because Safari
|
|
273
289
|
// won't include buttons in the tab order even with tabindex="0"
|
|
274
290
|
render() {
|
|
275
291
|
return html`
|
|
276
292
|
<span
|
|
277
293
|
id="focus-helper"
|
|
278
|
-
tabindex="${this.focused
|
|
294
|
+
tabindex="${this.focused ? "-1" : "0"}"
|
|
279
295
|
@focus=${this.onHelperFocus}
|
|
280
296
|
></span>
|
|
281
297
|
<button
|
|
@@ -287,13 +303,11 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
287
303
|
@blur=${this.onButtonBlur}
|
|
288
304
|
@click=${this.onButtonClick}
|
|
289
305
|
@focus=${this.onButtonFocus}
|
|
290
|
-
@pointerdown=${this.handlePointerdown}
|
|
291
306
|
?disabled=${this.disabled}
|
|
292
307
|
tabindex="-1"
|
|
293
308
|
>
|
|
294
309
|
${this.buttonContent}
|
|
295
310
|
</button>
|
|
296
|
-
${this.renderOverlay}
|
|
297
311
|
`;
|
|
298
312
|
}
|
|
299
313
|
update(changes) {
|
|
@@ -303,15 +317,21 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
303
317
|
if (changes.has("disabled") && this.disabled) {
|
|
304
318
|
this.open = false;
|
|
305
319
|
}
|
|
306
|
-
if (changes.has("
|
|
307
|
-
this.
|
|
320
|
+
if (changes.has("open") && (this.open || typeof changes.get("open") !== "undefined")) {
|
|
321
|
+
this.menuStatePromise = new Promise(
|
|
322
|
+
(res) => this.menuStateResolver = res
|
|
323
|
+
);
|
|
324
|
+
if (this.open) {
|
|
325
|
+
this.openMenu();
|
|
326
|
+
} else {
|
|
327
|
+
this.closeMenu();
|
|
328
|
+
}
|
|
308
329
|
}
|
|
309
|
-
if (!
|
|
310
|
-
|
|
311
|
-
deprecatedMenu == null ? void 0 : deprecatedMenu.setAttribute("selects", "inherit");
|
|
330
|
+
if (changes.has("value") && !changes.has("selectedItem")) {
|
|
331
|
+
this.updateMenuItems();
|
|
312
332
|
}
|
|
313
333
|
if (true) {
|
|
314
|
-
if (!this.hasUpdated && this.querySelector("
|
|
334
|
+
if (!this.hasUpdated && this.querySelector("sp-menu")) {
|
|
315
335
|
const { localName } = this;
|
|
316
336
|
window.__swc.warn(
|
|
317
337
|
this,
|
|
@@ -334,7 +354,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
334
354
|
</div>
|
|
335
355
|
`;
|
|
336
356
|
}
|
|
337
|
-
get
|
|
357
|
+
get renderPopover() {
|
|
338
358
|
const content = html`
|
|
339
359
|
${this.dismissHelper}
|
|
340
360
|
<sp-menu
|
|
@@ -342,11 +362,7 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
342
362
|
role="${this.listRole}"
|
|
343
363
|
@change=${this.handleChange}
|
|
344
364
|
.selects=${this.selects}
|
|
345
|
-
|
|
346
|
-
@sp-menu-item-added-or-updated=${this.shouldManageSelection}
|
|
347
|
-
>
|
|
348
|
-
<slot @slotchange=${this.shouldScheduleManageSelection}></slot>
|
|
349
|
-
</sp-menu>
|
|
365
|
+
></sp-menu>
|
|
350
366
|
${this.dismissHelper}
|
|
351
367
|
`;
|
|
352
368
|
if (this.isMobile.matches) {
|
|
@@ -354,7 +370,9 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
354
370
|
<sp-tray
|
|
355
371
|
id="popover"
|
|
356
372
|
role="dialog"
|
|
357
|
-
|
|
373
|
+
@sp-menu-item-added-or-updated=${this.updateMenuItems}
|
|
374
|
+
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
375
|
+
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
358
376
|
>
|
|
359
377
|
${content}
|
|
360
378
|
</sp-tray>
|
|
@@ -364,38 +382,56 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
364
382
|
<sp-popover
|
|
365
383
|
id="popover"
|
|
366
384
|
role="dialog"
|
|
367
|
-
|
|
368
|
-
|
|
385
|
+
@sp-menu-item-added-or-updated=${this.updateMenuItems}
|
|
386
|
+
.overlayOpenCallback=${this.overlayOpenCallback}
|
|
387
|
+
.overlayCloseCallback=${this.overlayCloseCallback}
|
|
369
388
|
>
|
|
370
389
|
${content}
|
|
371
390
|
</sp-popover>
|
|
372
391
|
`;
|
|
373
392
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
shouldManageSelection() {
|
|
385
|
-
if (this.willManageSelection) {
|
|
393
|
+
/**
|
|
394
|
+
* Acquire the available MenuItems in the Picker by
|
|
395
|
+
* direct element query or by assuming the list managed
|
|
396
|
+
* by the Menu within the open options overlay.
|
|
397
|
+
*/
|
|
398
|
+
updateMenuItems(event) {
|
|
399
|
+
if (this.open && (event == null ? void 0 : event.type) === "sp-menu-item-removed")
|
|
386
400
|
return;
|
|
401
|
+
if (this._willUpdateItems)
|
|
402
|
+
return;
|
|
403
|
+
this._willUpdateItems = true;
|
|
404
|
+
if ((event == null ? void 0 : event.item) === this.selectedItem) {
|
|
405
|
+
this.requestUpdate();
|
|
387
406
|
}
|
|
388
|
-
|
|
389
|
-
|
|
407
|
+
let resolve = () => {
|
|
408
|
+
return;
|
|
409
|
+
};
|
|
410
|
+
this.itemsUpdated = new Promise((res) => resolve = res);
|
|
411
|
+
window.requestAnimationFrame(async () => {
|
|
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
|
+
});
|
|
390
426
|
}
|
|
391
427
|
async manageSelection() {
|
|
392
428
|
if (this.selects == null)
|
|
393
429
|
return;
|
|
430
|
+
await this.menuStatePromise;
|
|
394
431
|
this.selectionPromise = new Promise(
|
|
395
432
|
(res) => this.selectionResolver = res
|
|
396
433
|
);
|
|
397
434
|
let selectedItem;
|
|
398
|
-
await this.optionsMenu.updateComplete;
|
|
399
435
|
this.menuItems.forEach((item) => {
|
|
400
436
|
if (this.value === item.value && !item.disabled) {
|
|
401
437
|
selectedItem = item;
|
|
@@ -415,18 +451,34 @@ export class PickerBase extends SizedMixin(Focusable) {
|
|
|
415
451
|
this.optionsMenu.updateSelectedItemIndex();
|
|
416
452
|
}
|
|
417
453
|
this.selectionResolver();
|
|
418
|
-
this.willManageSelection = false;
|
|
419
454
|
}
|
|
420
455
|
async getUpdateComplete() {
|
|
421
456
|
const complete = await super.getUpdateComplete();
|
|
457
|
+
await this.menuStatePromise;
|
|
458
|
+
await this.itemsUpdated;
|
|
422
459
|
await this.selectionPromise;
|
|
423
460
|
return complete;
|
|
424
461
|
}
|
|
462
|
+
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
|
+
super.connectedCallback();
|
|
470
|
+
}
|
|
425
471
|
disconnectedCallback() {
|
|
426
472
|
this.close();
|
|
427
473
|
super.disconnectedCallback();
|
|
428
474
|
}
|
|
429
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* @private
|
|
478
|
+
*/
|
|
479
|
+
PickerBase.openOverlay = async (target, interaction, content, options) => {
|
|
480
|
+
return await openOverlay(target, interaction, content, options);
|
|
481
|
+
};
|
|
430
482
|
__decorateClass([
|
|
431
483
|
query("#button")
|
|
432
484
|
], PickerBase.prototype, "button", 2);
|
|
@@ -451,9 +503,6 @@ __decorateClass([
|
|
|
451
503
|
__decorateClass([
|
|
452
504
|
property({ type: Boolean, reflect: true })
|
|
453
505
|
], PickerBase.prototype, "readonly", 2);
|
|
454
|
-
__decorateClass([
|
|
455
|
-
query("sp-menu")
|
|
456
|
-
], PickerBase.prototype, "optionsMenu", 2);
|
|
457
506
|
__decorateClass([
|
|
458
507
|
property()
|
|
459
508
|
], PickerBase.prototype, "placement", 2);
|
|
@@ -465,10 +514,7 @@ __decorateClass([
|
|
|
465
514
|
], PickerBase.prototype, "value", 2);
|
|
466
515
|
__decorateClass([
|
|
467
516
|
property({ attribute: false })
|
|
468
|
-
], PickerBase.prototype, "selectedItem",
|
|
469
|
-
__decorateClass([
|
|
470
|
-
property({ attribute: false })
|
|
471
|
-
], PickerBase.prototype, "selectedItemContent", 1);
|
|
517
|
+
], PickerBase.prototype, "selectedItem", 2);
|
|
472
518
|
export class Picker extends PickerBase {
|
|
473
519
|
constructor() {
|
|
474
520
|
super(...arguments);
|
|
@@ -500,12 +546,11 @@ export class Picker extends PickerBase {
|
|
|
500
546
|
static get styles() {
|
|
501
547
|
return [pickerStyles, chevronStyles];
|
|
502
548
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
}
|
|
508
|
-
return styles;
|
|
549
|
+
sizePopover(popover) {
|
|
550
|
+
super.sizePopover(popover);
|
|
551
|
+
if (this.quiet)
|
|
552
|
+
return;
|
|
553
|
+
popover.style.setProperty("min-width", `${this.offsetWidth}px`);
|
|
509
554
|
}
|
|
510
555
|
}
|
|
511
556
|
//# sourceMappingURL=Picker.dev.js.map
|