vira 30.1.2 → 30.1.4
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.
|
@@ -88,33 +88,34 @@ export const ViraMenuItem = defineViraElement()({
|
|
|
88
88
|
host.setAttribute('aria-selected', String(!!inputs.selected));
|
|
89
89
|
host.setAttribute('aria-disabled', String(!!inputs.disabled));
|
|
90
90
|
state.cleanup?.();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
const propagating = {};
|
|
92
|
+
function propagateMouseEvent(event) {
|
|
93
|
+
if (propagating[event.type]) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
else if (inputs.disabled) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const slotElement = assertWrap.instanceOf(host.shadowRoot.querySelector('slot'), HTMLSlotElement);
|
|
102
|
+
slotElement
|
|
103
|
+
.assignedElements({
|
|
104
|
+
flatten: true,
|
|
105
|
+
})
|
|
106
|
+
.forEach((element) => {
|
|
107
|
+
if (element instanceof HTMLElement && !event.composedPath().includes(element)) {
|
|
98
108
|
event.preventDefault();
|
|
99
109
|
event.stopPropagation();
|
|
100
|
-
|
|
110
|
+
propagating[event.type] = true;
|
|
111
|
+
element.dispatchEvent(new MouseEvent(event.type, event));
|
|
112
|
+
delete propagating[event.type];
|
|
101
113
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.forEach((element) => {
|
|
108
|
-
if (element instanceof HTMLElement &&
|
|
109
|
-
!event.composedPath().includes(element)) {
|
|
110
|
-
event.preventDefault();
|
|
111
|
-
event.stopPropagation();
|
|
112
|
-
propagating = true;
|
|
113
|
-
element.dispatchEvent(new MouseEvent(event.type, event));
|
|
114
|
-
propagating = false;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const listenerRemovers = [
|
|
117
|
+
listenTo(host, 'click', propagateMouseEvent),
|
|
118
|
+
listenTo(host, 'mousedown', propagateMouseEvent),
|
|
118
119
|
listenTo(host, 'mouseenter', () => {
|
|
119
120
|
if (!inputs.disabled) {
|
|
120
121
|
host.focus();
|
|
@@ -32,6 +32,8 @@ export declare const ViraSelect: import("element-vir").DeclarativeElementDefinit
|
|
|
32
32
|
* provided.
|
|
33
33
|
*/
|
|
34
34
|
randomId: string;
|
|
35
|
+
/** Removes event listeners registered during init. */
|
|
36
|
+
cleanup: undefined | (() => void);
|
|
35
37
|
}, {
|
|
36
38
|
valueChange: import("element-vir").DefineEvent<string>;
|
|
37
39
|
}, "vira-select-disabled" | "vira-select-error" | "vira-select-not-raw", "vira-select-padding-horizontal" | "vira-select-padding-vertical" | "vira-select-icon-padding", readonly [], readonly []>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { assertWrap } from '@augment-vir/assert';
|
|
1
2
|
import { randomString } from '@augment-vir/common';
|
|
2
3
|
import { extractEventTarget } from '@augment-vir/web';
|
|
3
4
|
import { attributes, classMap, css, defineElementEvent, html, ifDefined, listen, nothing, } from 'element-vir';
|
|
5
|
+
import { listenTo } from 'typed-event-target';
|
|
4
6
|
import { ChevronUp24Icon } from '../icons/index.js';
|
|
5
7
|
import { viraDisabledStyles } from '../styles/disabled.js';
|
|
6
8
|
import { createFocusStyles } from '../styles/focus.js';
|
|
@@ -25,6 +27,8 @@ export const ViraSelect = defineViraElement()({
|
|
|
25
27
|
* provided.
|
|
26
28
|
*/
|
|
27
29
|
randomId: randomString(32),
|
|
30
|
+
/** Removes event listeners registered during init. */
|
|
31
|
+
cleanup: undefined,
|
|
28
32
|
};
|
|
29
33
|
},
|
|
30
34
|
events: {
|
|
@@ -72,7 +76,7 @@ export const ViraSelect = defineViraElement()({
|
|
|
72
76
|
cursor: pointer;
|
|
73
77
|
/* Prevent the left pixel of text getting cut off. */
|
|
74
78
|
padding-left: 0.5px;
|
|
75
|
-
padding-right:
|
|
79
|
+
padding-right: 28px;
|
|
76
80
|
overflow: hidden;
|
|
77
81
|
text-overflow: ellipsis;
|
|
78
82
|
|
|
@@ -182,6 +186,35 @@ export const ViraSelect = defineViraElement()({
|
|
|
182
186
|
border-color: ${viraFormCssVars['vira-form-error-color'].value};
|
|
183
187
|
}
|
|
184
188
|
`,
|
|
189
|
+
init({ state, updateState, host }) {
|
|
190
|
+
state.cleanup?.();
|
|
191
|
+
const listenerRemovers = [
|
|
192
|
+
listenTo(host, 'mousedown', (event) => {
|
|
193
|
+
const selectElement = assertWrap.instanceOf(host.shadowRoot.querySelector('select'), HTMLSelectElement);
|
|
194
|
+
if (event.composedPath().includes(selectElement)) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
/** `showPicker` is not in Safari. */
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
201
|
+
if (selectElement.showPicker) {
|
|
202
|
+
selectElement.showPicker();
|
|
203
|
+
}
|
|
204
|
+
}),
|
|
205
|
+
];
|
|
206
|
+
updateState({
|
|
207
|
+
cleanup: () => {
|
|
208
|
+
listenerRemovers.forEach((remover) => remover());
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
cleanup({ state, updateState }) {
|
|
213
|
+
state.cleanup?.();
|
|
214
|
+
updateState({
|
|
215
|
+
cleanup: undefined,
|
|
216
|
+
});
|
|
217
|
+
},
|
|
185
218
|
render({ inputs, state, dispatch, events }) {
|
|
186
219
|
const value = inputs.value || undefined;
|
|
187
220
|
const placeholderOptionTemplate = inputs.placeholder || value == undefined
|