Skip to content

A self-hosted media server and file management system

fix: input multichip checking for unset value

aminnausin5d0b12e433c6
diff --git a/resources/js/components/pinesUI/InputMultiChip.vue b/resources/js/components/pinesUI/InputMultiChip.vue
index b3c2ba54..6a2abb3b 100644
--- a/resources/js/components/pinesUI/InputMultiChip.vue
+++ b/resources/js/components/pinesUI/InputMultiChip.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, ref, useTemplateRef, watch } from 'vue';
+import { isInputLikeElement } from '@/service/util';
import { OnClickOutside } from '@vueuse/components';
import { UseFocusTrap } from '@vueuse/integrations/useFocusTrap/component.mjs';
@@ -94,6 +95,9 @@ const handleItemClick = (item: any, setFocus = true, triggerSelect = true) => {
const handleItemHover = (item: any) => {
select.selectableItemActive = item;
lastActiveItemId.value = item.id;
+
+ if (isInputLikeElement(document.activeElement as HTMLElement, '')) return;
+
(document.activeElement as HTMLElement)?.blur();
};
@@ -219,7 +223,7 @@ watch(
'bottom-0 mb-11': select.selectDropdownPosition == 'top',
'top-0 mt-11': select.selectDropdownPosition == 'bottom',
}"
- class="z-30 absolute w-full mt-1 overflow-auto scrollbar-thin text-sm rounded-md shadow-md max-h-56 focus:outline-none ring-1 ring-opacity-5 ring-black dark:ring-neutral-700 bg-white dark:bg-neutral-800/70 backdrop-blur-lg"
+ class="z-30 absolute w-full mt-1 text-sm rounded-md shadow-md focus:outline-none ring-1 ring-opacity-5 ring-black dark:ring-neutral-700 bg-white dark:bg-neutral-800/70 backdrop-blur-lg"
:options="{ allowOutsideClick: true, initialFocus: selectInput?.$el, returnFocusOnDeactivate: false }"
>
<OnClickOutside
@@ -285,7 +289,13 @@ watch(
>
<span class="block truncate">No Results... Add New?</span>
</section>
- <ul class="max-h-56 last:rounded-b-md" id="selectableItemsList" ref="selectableItemsList" role="listbox" @focusin="handleListFocus">
+ <ul
+ class="max-h-48 overflow-auto scrollbar-thin last:rounded-b-md"
+ id="selectableItemsList"
+ ref="selectableItemsList"
+ role="listbox"
+ @focusin="handleListFocus"
+ >
<template v-for="item in filteredItemsList" :key="item.value">
<li
@keydown.enter.prevent.stop="handleItemClick(select.selectableItemActive)"
diff --git a/resources/js/composables/useMultiSelect.js b/resources/js/composables/useMultiSelect.js
index dc15fd7e..ce9542a7 100644
--- a/resources/js/composables/useMultiSelect.js
+++ b/resources/js/composables/useMultiSelect.js
@@ -27,34 +27,30 @@ export default function useMultiSelect({ options, defaultItems }, refs) {
selectableItemIsActive() {
return false;
},
- async selectScrollToActiveItem(id) {
+ async selectScrollToActiveItem(id, focus = true) {
let activeElement = document.getElementById(id + '-' + this.selectId);
if (!activeElement) return;
activeElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
- activeElement.focus({ preventScroll: false });
+ if (focus) activeElement.focus({ preventScroll: false });
},
selectKeydown(event) {
- if (event.keyCode >= 65 && event.keyCode <= 90) {
- this.selectKeydownValue += event.key;
- let selectedItemBestMatch = this.selectItemsFindBestMatch();
- if (selectedItemBestMatch) {
- if (this.selectOpen) {
- this.selectableItemActive = selectedItemBestMatch;
- this.selectScrollToActiveItem(selectableItemActive.id);
- } else {
- // this.selectedItem = this.selectableItemActive === selectedItemBestMatch; // What does this line do there was only 1 equal
- }
- }
+ if (event.keyCode < 65 || event.keyCode > 90) return;
- if (this.selectKeydownValue != '') {
- clearTimeout(this.selectKeydownClearTimeout);
- this.selectKeydownClearTimeout = setTimeout(() => {
- this.selectKeydownValue = '';
- }, this.selectKeydownTimeout);
- }
+ this.selectKeydownValue += event.key;
+ let selectedItemBestMatch = this.selectItemsFindBestMatch();
+
+ if (selectedItemBestMatch && this.selectOpen) {
+ this.selectableItemActive = selectedItemBestMatch;
}
+
+ if (this.selectKeydownValue === '') return;
+
+ clearTimeout(this.selectKeydownClearTimeout);
+ this.selectKeydownClearTimeout = setTimeout(() => {
+ this.selectKeydownValue = '';
+ }, this.selectKeydownTimeout);
},
selectItemsFindBestMatch() {
let typedValue = this.selectKeydownValue.toLowerCase();
@@ -76,11 +72,7 @@ export default function useMultiSelect({ options, defaultItems }, refs) {
let selectDropdownBottomPos =
this.selectButton?.getBoundingClientRect().top + this.selectButton.offsetHeight + parseInt(window.getComputedStyle(this.selectableItemsList).maxHeight);
- if (window.innerHeight < selectDropdownBottomPos) {
- this.selectDropdownPosition = 'top';
- } else {
- this.selectDropdownPosition = 'bottom';
- }
+ this.selectDropdownPosition = window.innerHeight < selectDropdownBottomPos ? 'top' : 'bottom';
},
setOptions(options) {
if (Array.isArray(options)) this.selectableItems = options;