vira 30.0.0 → 30.1.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.
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +0 -1
- package/dist/elements/pop-up/vira-menu-trigger.element.js +0 -1
- package/dist/elements/pop-up/vira-menu.element.d.ts +1 -1
- package/dist/elements/pop-up/vira-menu.element.js +1 -1
- package/dist/elements/pop-up/vira-pop-up-trigger.element.js +21 -2
- package/dist/elements/vira-dropdown.element.js +3 -3
- package/dist/util/pop-up-helpers.d.ts +5 -5
- package/dist/util/pop-up-helpers.js +3 -3
- package/package.json +1 -1
|
@@ -29,6 +29,5 @@ export declare const ViraMenuTrigger: import("element-vir").DeclarativeElementDe
|
|
|
29
29
|
/** `undefined` means the pop up is not currently showing. */
|
|
30
30
|
showPopUpResult: ShowPopUpResult | undefined;
|
|
31
31
|
}, {
|
|
32
|
-
itemActivate: import("element-vir").DefineEvent<PropertyKey[]>;
|
|
33
32
|
openChange: import("element-vir").DefineEvent<ShowPopUpResult | undefined>;
|
|
34
33
|
}, "vira-menu-trigger-", "vira-menu-trigger-", readonly ["trigger"], readonly []>;
|
|
@@ -22,7 +22,7 @@ export declare enum ViraMenuPopUpDirection {
|
|
|
22
22
|
Upwards = "upwards"
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* A simple default style wrapper for pop-up menus. Consider using `
|
|
25
|
+
* A simple default style wrapper for pop-up menus. Consider using `renderMenuItemEntries` to help
|
|
26
26
|
* rendering many menu items.
|
|
27
27
|
*
|
|
28
28
|
* @category PopUp
|
|
@@ -27,7 +27,7 @@ export var ViraMenuPopUpDirection;
|
|
|
27
27
|
ViraMenuPopUpDirection["Upwards"] = "upwards";
|
|
28
28
|
})(ViraMenuPopUpDirection || (ViraMenuPopUpDirection = {}));
|
|
29
29
|
/**
|
|
30
|
-
* A simple default style wrapper for pop-up menus. Consider using `
|
|
30
|
+
* A simple default style wrapper for pop-up menus. Consider using `renderMenuItemEntries` to help
|
|
31
31
|
* rendering many menu items.
|
|
32
32
|
*
|
|
33
33
|
* @category PopUp
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert } from '@augment-vir/assert';
|
|
1
|
+
import { assert, assertWrap } from '@augment-vir/assert';
|
|
2
2
|
import { walkActiveElement } from '@augment-vir/web';
|
|
3
3
|
import { NavController } from 'device-navigation';
|
|
4
4
|
import { classMap, css, defineElementEvent, html, listen, renderIf } from 'element-vir';
|
|
@@ -301,10 +301,29 @@ export const ViraPopUpTrigger = defineViraElement()({
|
|
|
301
301
|
}
|
|
302
302
|
respondToClick(event);
|
|
303
303
|
}
|
|
304
|
+
else if (event.button === 0 && state.showPopUpResult) {
|
|
305
|
+
const dropdownTrigger = host.shadowRoot.querySelector('.dropdown-trigger');
|
|
306
|
+
/**
|
|
307
|
+
* Close the menu when a mouse click originates from the pop-up area (e.g. a
|
|
308
|
+
* menu item was clicked). The trigger's mousedown already handles
|
|
309
|
+
* open/close toggling for the trigger itself.
|
|
310
|
+
*/
|
|
311
|
+
if (dropdownTrigger && !event.composedPath().includes(dropdownTrigger)) {
|
|
312
|
+
triggerPopUp({ emitEvent: true, open: false }, event);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
304
315
|
})}
|
|
305
316
|
${listen('mousedown', (event) => {
|
|
306
317
|
/** Ignore any clicks that aren't the main button. */
|
|
307
|
-
if (event.button
|
|
318
|
+
if (event.button !== 0) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const dropdownTrigger = assertWrap.instanceOf(host.shadowRoot.querySelector('.dropdown-trigger'), HTMLElement);
|
|
322
|
+
/**
|
|
323
|
+
* Only respond if the mousedown originated from the trigger slot, not from
|
|
324
|
+
* within the pop-up menu items, to avoid prematurely closing the menu.
|
|
325
|
+
*/
|
|
326
|
+
if (event.composedPath().includes(dropdownTrigger)) {
|
|
308
327
|
respondToClick(event);
|
|
309
328
|
}
|
|
310
329
|
})}
|
|
@@ -5,7 +5,7 @@ import { ChevronUp24Icon } from '../icons/index.js';
|
|
|
5
5
|
import { viraFormCssVars } from '../styles/form-styles.js';
|
|
6
6
|
import { noUserSelect, viraAnimationDurations } from '../styles/index.js';
|
|
7
7
|
import { defineViraElement } from '../util/define-vira-element.js';
|
|
8
|
-
import {
|
|
8
|
+
import { renderMenuItemEntries } from '../util/pop-up-helpers.js';
|
|
9
9
|
import { ViraMenu, ViraMenuPopUpDirection } from './pop-up/vira-menu.element.js';
|
|
10
10
|
import { HorizontalAnchor, ViraPopUpTrigger, } from './pop-up/vira-pop-up-trigger.element.js';
|
|
11
11
|
import { ViraIcon } from './vira-icon.element.js';
|
|
@@ -133,10 +133,10 @@ export const ViraDropdown = defineViraElement()({
|
|
|
133
133
|
})}
|
|
134
134
|
slot=${ViraPopUpTrigger.slotNames.popUp}
|
|
135
135
|
>
|
|
136
|
-
${
|
|
136
|
+
${renderMenuItemEntries(inputs.options.map((option) => {
|
|
137
137
|
return {
|
|
138
138
|
content: option.label,
|
|
139
|
-
|
|
139
|
+
onClick() {
|
|
140
140
|
dispatch(new events.selectedChange([option.value]));
|
|
141
141
|
},
|
|
142
142
|
disabled: option.disabled,
|
|
@@ -24,7 +24,7 @@ export declare function triggerPopUpState({ open, callback, popUpManager, host,
|
|
|
24
24
|
options?: Partial<PopUpManagerOptions> | undefined;
|
|
25
25
|
}>>): void;
|
|
26
26
|
/**
|
|
27
|
-
* A helper type to be used with {@link
|
|
27
|
+
* A helper type to be used with {@link renderMenuItemEntries}.
|
|
28
28
|
*
|
|
29
29
|
* @category PopUp
|
|
30
30
|
*/
|
|
@@ -33,14 +33,14 @@ export type ViraMenuItemEntry = {
|
|
|
33
33
|
} & PartialWithUndefined<{
|
|
34
34
|
selected: boolean;
|
|
35
35
|
/** Called when any item is activated. */
|
|
36
|
-
|
|
36
|
+
onClick: MenuItemClickCallback;
|
|
37
37
|
}> & typeof ViraMenuItem.InputsType;
|
|
38
38
|
/**
|
|
39
|
-
* A callback for menu items getting activated, to be used with {@link
|
|
39
|
+
* A callback for menu items getting activated, to be used with {@link renderMenuItemEntries}.
|
|
40
40
|
*
|
|
41
41
|
* @category PopUp
|
|
42
42
|
*/
|
|
43
|
-
export type
|
|
43
|
+
export type MenuItemClickCallback = (params: Readonly<{
|
|
44
44
|
/** The menu item's index in the array. */
|
|
45
45
|
index: number;
|
|
46
46
|
event: MouseEvent;
|
|
@@ -50,4 +50,4 @@ export type MenuItemActivateCallback = (params: Readonly<{
|
|
|
50
50
|
*
|
|
51
51
|
* @category PopUp
|
|
52
52
|
*/
|
|
53
|
-
export declare function
|
|
53
|
+
export declare function renderMenuItemEntries(items: ReadonlyArray<Readonly<ViraMenuItemEntry>>): import("lit-html").HTMLTemplateResult[];
|
|
@@ -41,14 +41,14 @@ export function triggerPopUpState({ open, callback, popUpManager, host, options,
|
|
|
41
41
|
*
|
|
42
42
|
* @category PopUp
|
|
43
43
|
*/
|
|
44
|
-
export function
|
|
44
|
+
export function renderMenuItemEntries(items) {
|
|
45
45
|
return items.map((item, index) => {
|
|
46
46
|
return html `
|
|
47
47
|
<${ViraMenuItem.assign({
|
|
48
48
|
...item,
|
|
49
49
|
})}
|
|
50
|
-
${listen('
|
|
51
|
-
await item.
|
|
50
|
+
${listen('click', async (event) => {
|
|
51
|
+
await item.onClick?.({
|
|
52
52
|
event,
|
|
53
53
|
index,
|
|
54
54
|
});
|