@txstate-mws/svelte-components 1.5.7 → 1.5.9
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.
|
@@ -61,11 +61,13 @@ export let menuItemClass = '';
|
|
|
61
61
|
export let menuItemHilitedClass = '';
|
|
62
62
|
export let menuItemSelectedClass = '';
|
|
63
63
|
export let menuDividerClass = '';
|
|
64
|
+
export let hideSelectedIndicator = false;
|
|
64
65
|
export let usemenurole = false;
|
|
65
66
|
let menuelement;
|
|
66
67
|
const itemelements = [];
|
|
67
68
|
let firstactive = 0;
|
|
68
69
|
let lastactive = items.length - 1;
|
|
70
|
+
$: hasMeaningfulItems = showSelected ? !!items.filter(itm => 'value' in itm).length : !!items.filter(itm => 'value' in itm && itm.value !== value).length;
|
|
69
71
|
function hiddenItem(item) {
|
|
70
72
|
return !!item && !showSelected && item.value === value;
|
|
71
73
|
}
|
|
@@ -74,6 +76,8 @@ async function reactToItems(..._) {
|
|
|
74
76
|
lastactive = items.length - [...items].reverse().findIndex(itm => 'value' in itm && !itm.disabled && !hiddenItem(itm)) - 1;
|
|
75
77
|
if (hilited && items[hilited]?.disabled)
|
|
76
78
|
hilited = firstactive;
|
|
79
|
+
if (document.activeElement === buttonelement && hasMeaningfulItems && !loading)
|
|
80
|
+
menushown = true;
|
|
77
81
|
}
|
|
78
82
|
$: void reactToItems(items, value);
|
|
79
83
|
async function reactToMenuShown(_) {
|
|
@@ -116,7 +120,7 @@ function isSelectable(itm) {
|
|
|
116
120
|
return 'value' in itm && !itm.disabled && !hiddenItem(itm);
|
|
117
121
|
}
|
|
118
122
|
function onkeydown(e) {
|
|
119
|
-
if (modifierKey(e))
|
|
123
|
+
if (modifierKey(e) || loading)
|
|
120
124
|
return;
|
|
121
125
|
if (e.key === 'ArrowDown') {
|
|
122
126
|
e.preventDefault();
|
|
@@ -266,7 +270,7 @@ const onclick = (item) => (e) => {
|
|
|
266
270
|
value = item.value;
|
|
267
271
|
dispatch('change', item);
|
|
268
272
|
};
|
|
269
|
-
$: hasSelected = showSelected && items.some(itm => 'value' in itm && itm.value === value);
|
|
273
|
+
$: hasSelected = showSelected && !hideSelectedIndicator && items.some(itm => 'value' in itm && itm.value === value);
|
|
270
274
|
</script>
|
|
271
275
|
|
|
272
276
|
{#if menushown}
|
|
@@ -285,7 +289,7 @@ $: hasSelected = showSelected && items.some(itm => 'value' in itm && itm.value =
|
|
|
285
289
|
class={`${menuItemClass} ${i === hilited ? menuItemHilitedClass : ''} ${value === item.value ? menuItemSelectedClass : ''}`}
|
|
286
290
|
class:disabled={!!item.disabled}
|
|
287
291
|
class:hilited={!menuItemHilitedClass && i === hilited}
|
|
288
|
-
class:selected={showSelected && !
|
|
292
|
+
class:selected={showSelected && !hideSelectedIndicator && value === item.value}
|
|
289
293
|
on:click={onclick(item)}
|
|
290
294
|
role={usemenurole ? 'menuitem' : 'option'}
|
|
291
295
|
tabindex=-1
|
|
@@ -297,7 +301,7 @@ $: hasSelected = showSelected && items.some(itm => 'value' in itm && itm.value =
|
|
|
297
301
|
<li class={`divider ${menuDividerClass}`} on:mousedown|stopPropagation|preventDefault class:group={isNotBlank(item.label)}>{item.label}</li>
|
|
298
302
|
{/if}
|
|
299
303
|
{/each}
|
|
300
|
-
{#if
|
|
304
|
+
{#if !hasMeaningfulItems}
|
|
301
305
|
<li role={usemenurole ? 'menuitem' : 'option'} class={`${menuItemClass} disabled`} aria-live="assertive" aria-selected={usemenurole ? undefined : false}>
|
|
302
306
|
<slot name="noresults">
|
|
303
307
|
{#if !emptyText}
|
|
@@ -42,6 +42,7 @@ declare const __propDef: {
|
|
|
42
42
|
menuItemHilitedClass?: string | undefined;
|
|
43
43
|
menuItemSelectedClass?: string | undefined;
|
|
44
44
|
menuDividerClass?: string | undefined;
|
|
45
|
+
hideSelectedIndicator?: boolean | undefined;
|
|
45
46
|
usemenurole?: boolean | undefined;
|
|
46
47
|
};
|
|
47
48
|
events: {
|