Skip to content

Commit d87ad6b

Browse files
committed
feat: refactor FilterDropdown component for improved button and dropdown handling
1 parent 63a809a commit d87ad6b

1 file changed

Lines changed: 29 additions & 38 deletions

File tree

adminforth/spa/src/afcl/FilterDropdown.vue

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,38 @@
22
<div class="afcl-select afcl-select-wrapper relative inline-block af-button-shadow rounded" ref="internalSelect"
33
:class="{'opacity-50': readonly}"
44
>
5-
<div class="relative">
6-
<button
7-
ref="inputEl"
8-
type="button"
9-
@click="inputClick"
10-
class="group block w-full pl-3 pr-10 text-left cursor-pointer
11-
text-sm font-medium transition-all rounded border af-button-shadow outline-none
12-
bg-lightListViewButtonBackground text-lightListViewButtonText border-lightListViewButtonBorder
13-
dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder
14-
hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover
15-
dark:hover:text-darkListViewButtonTextHover dark:hover:bg-darkListViewButtonBackgroundHover"
16-
:class="classesForInput"
17-
>
18-
<span v-if="displayLabel">
19-
{{ displayLabel }}
20-
</span>
21-
<span
22-
v-else
23-
class="opacity-100 transition-colors"
24-
:class="[
25-
'text-lightListViewButtonText dark:text-darkListViewButtonText',
26-
'group-hover:text-lightListViewButtonTextHover dark:group-hover:text-darkListViewButtonTextHover'
27-
]"
5+
<div class="relative w-fit">
6+
<button
7+
ref="dropdownFilterEl"
8+
type="button"
9+
@click="dropdownClick"
10+
class="group h-[34px] inline-flex items-center justify-between min-w-max px-3 py-2 text-left cursor-pointer
11+
text-sm font-medium transition-all rounded border outline-none gap-x-2
12+
bg-lightListViewButtonBackground text-lightListViewButtonText border-lightListViewButtonBorder
13+
dark:bg-darkListViewButtonBackground dark:text-darkListViewButtonText dark:border-darkListViewButtonBorder
14+
hover:bg-lightListViewButtonBackgroundHover hover:text-lightListViewButtonTextHover"
2815
>
29-
{{ filter?.name || placeholder || $t('Select...') }}
30-
</span>
31-
</button>
32-
33-
<div class="absolute inset-y-0 right-2 flex items-center pointer-events-none">
34-
<IconCaretDownSolid class="h-5 w-5 text-lightPrimary dark:text-darkPrimary opacity-50 transition duration-150 ease-in"
16+
<span v-if="displayLabel" class="whitespace-nowrap">
17+
{{ displayLabel }}
18+
</span>
19+
<span
20+
v-else
21+
class="opacity-100 transition-colors whitespace-nowrap"
22+
>
23+
{{ filter?.name || placeholder || $t('Select...') }}
24+
</span>
25+
26+
<IconCaretDownSolid class="h-4 w-4 text-lightPrimary dark:text-darkPrimary opacity-50 transition duration-150 ease-in flex-shrink-0"
3527
:class="{ 'transform rotate-180': showDropdown }"
3628
/>
37-
</div>
29+
</button>
3830
</div>
3931

4032
<teleport to="body" v-if="teleportToBody && showDropdown">
4133
<div
4234
ref="dropdownEl"
4335
:style="getDropdownPosition"
44-
class="fixed z-[1000] bg-lightDropdownOptionsBackground shadow-lg dark:shadow-black dark:bg-darkDropdownOptionsBackground
36+
class="fixed z-[1000] w-max min-w-fit bg-lightDropdownOptionsBackground shadow-lg dark:shadow-black dark:bg-darkDropdownOptionsBackground
4537
dark:border-gray-600 rounded-md text-base ring-1 ring-black ring-opacity-5 overflow-hidden focus:outline-none sm:text-sm max-h-64 flex flex-col"
4638
>
4739
<div class="py-1 overflow-y-auto grow" @scroll="handleDropdownScroll">
@@ -91,13 +83,12 @@ const props = defineProps({
9183
placeholder: String,
9284
readonly: Boolean,
9385
teleportToBody: Boolean,
94-
classesForInput: String,
9586
});
9687
9788
const emit = defineEmits(['update:modelValue', 'scroll-near-end']);
9889
9990
const showDropdown = ref(false);
100-
const inputEl = ref<HTMLElement | null>(null);
91+
const dropdownFilterEl = ref<HTMLElement | null>(null);
10192
const dropdownEl = ref<HTMLElement | null>(null);
10293
const internalSelect = ref<HTMLElement | null>(null);
10394
@@ -118,17 +109,17 @@ const clearSelection = () => {
118109
showDropdown.value = false;
119110
};
120111
121-
const inputClick = () => {
112+
const dropdownClick = () => {
122113
if (!props.readonly) showDropdown.value = !showDropdown.value;
123114
};
124115
125116
const getDropdownPosition = computed(() => {
126-
if (!inputEl.value) return {};
127-
const rect = inputEl.value.getBoundingClientRect();
117+
if (!dropdownFilterEl.value) return {};
118+
const rect = dropdownFilterEl.value.getBoundingClientRect();
128119
return {
129120
top: `${rect.bottom + window.scrollY + 4}px`,
130-
left: `${rect.left + window.scrollX}px`,
131-
width: `${rect.width}px`
121+
left: `${rect.right + window.scrollX - (dropdownEl.value?.offsetWidth || rect.width)}px`,
122+
minWidth: `${rect.width}px`
132123
};
133124
});
134125

0 commit comments

Comments
 (0)