Skip to content

Beautiful Open-Source Form Builder

ESC-687 - Refactor VSelect component to utilize UPopover for dropdown functiona… (#866)

Chirag Chhatralae8e31217982f
diff --git a/client/components/forms/core/components/VSelect.vue b/client/components/forms/core/components/VSelect.vue
index 7288967cc..fbe6e6fc2 100644
--- a/client/components/forms/core/components/VSelect.vue
+++ b/client/components/forms/core/components/VSelect.vue
@@ -4,230 +4,239 @@
class="v-select relative"
:class="[{ 'w-0': multiple, 'min-w-full': multiple }]"
>
- <div
- class="w-full flex overflow-hidden"
- :style="inputStyle"
- :class="[
- theme.SelectInput.input,
- theme.SelectInput.borderRadius,
- {
- 'ring-red-500! ring-2! border-transparent!': hasError,
- '!cursor-not-allowed bg-neutral-200! dark:bg-neutral-800!': disabled,
- 'focus-within:ring-2 focus-within:ring-form/100 focus-within:border-transparent': !hasError && !disabled
- },
- inputClass
- ]"
+ <UPopover
+ v-model:open="isOpen"
+ :content="{
+ align: 'start',
+ side: 'bottom',
+ sideOffset: 4
+ }"
+ :ui="{
+ content: 'w-(--reka-popper-anchor-width) bg-white dark:!bg-notion-dark-light shadow-xl z-30 overflow-auto ' + [theme.SelectInput.borderRadius].join(' ')
+ }"
>
- <button
- type="button"
- aria-haspopup="listbox"
- aria-expanded="true"
- aria-labelledby="listbox-label"
- class="cursor-pointer w-full grow relative focus:outline-hidden min-w-0 truncate"
- :class="[
- theme.SelectInput.spacing.horizontal,
- theme.SelectInput.spacing.vertical
- ]"
- @click="toggleDropdown"
- @focus="onFocus"
- @blur="onBlur"
- >
+ <template #anchor>
<div
- class="flex items-center"
+ class="w-full flex overflow-hidden"
+ :style="inputStyle"
:class="[
- theme.SelectInput.minHeight,
- 'ltr:pr-8 rtl:pl-8'
+ theme.SelectInput.input,
+ theme.SelectInput.borderRadius,
+ {
+ 'ring-red-500! ring-2! border-transparent!': hasError,
+ '!cursor-not-allowed bg-neutral-200! dark:bg-neutral-800!': disabled,
+ 'focus-within:ring-2 focus-within:ring-form/100 focus-within:border-transparent': !hasError && !disabled
+ },
+ inputClass
]"
>
- <transition
- name="fade"
- mode="out-in"
+ <button
+ type="button"
+ aria-haspopup="listbox"
+ :aria-expanded="isOpen"
+ aria-labelledby="listbox-label"
+ class="cursor-pointer w-full grow relative focus:outline-hidden min-w-0 truncate"
+ :class="[
+ theme.SelectInput.spacing.horizontal,
+ theme.SelectInput.spacing.vertical
+ ]"
+ @click.stop="toggleDropdown"
+ @focus="onFocus"
+ @blur="onBlur"
+ >
+ <div
+ class="flex items-center"
+ :class="[
+ theme.SelectInput.minHeight,
+ 'ltr:pr-8 rtl:pl-8'
+ ]"
+ >
+ <transition
+ name="fade"
+ mode="out-in"
+ >
+ <Loader
+ v-if="loading"
+ key="loader"
+ class="h-6 w-6 text-form mx-auto"
+ />
+ <div
+ v-else-if="modelValue"
+ key="value"
+ class="flex"
+ >
+ <slot
+ name="selected"
+ :option="modelValue"
+ :toggle="select"
+ />
+ </div>
+ <div
+ v-else
+ key="placeholder"
+ >
+ <slot name="placeholder">
+ <div
+ class="text-neutral-400 dark:text-neutral-500 w-full ltr:text-left rtl:text-right! truncate ltr:pr-3 rtl:pl-3 rtl:pr-0!"
+ :class="[
+ { 'py-1': multiple && !loading },
+ theme.SelectInput.fontSize
+ ]"
+ >
+ {{ placeholder }}
+ </div>
+ </slot>
+ </div>
+ </transition>
+ </div>
+ <div
+ class="absolute inset-y-0 ltr:right-6 rtl:left-6 w-10 pointer-events-none -z-1"
+ :class="[disabled ? 'bg-linear-to-r from-transparent to-neutral-200 dark:to-neutral-800' : theme.SelectInput.chevronGradient]"
+ />
+ <span
+ class="absolute inset-y-0 ltr:right-0 rtl:left-0 rtl:right-auto! flex items-center ltr:pr-2 rtl:pl-2 rtl:pr-0! pointer-events-none"
+ :class="[disabled ? 'bg-neutral-200 dark:bg-neutral-800' : theme.SelectInput.background]"
>
- <Loader
- v-if="loading"
- key="loader"
- class="h-6 w-6 text-form mx-auto"
+ <Icon
+ name="heroicons:chevron-up-down-16-solid"
+ class="h-5 w-5 text-neutral-500"
/>
+ </span>
+ </button>
+ <button
+ v-if="clearable && showClearButton && !disabled && !isEmpty"
+ class="hover:bg-neutral-50 dark:hover:bg-neutral-900 ltr:border-l rtl:border-l-0! rtl:border-r px-2 flex items-center shrink-0"
+ :class="[theme.SelectInput.spacing.vertical]"
+ @click.stop.prevent="clear()"
+ >
+ <Icon
+ name="heroicons:x-mark-20-solid"
+ class="w-5 h-5 text-neutral-500"
+ width="2em"
+ dynamic
+ />
+ </button>
+ </div>
+ </template>
+
+ <template #content>
+ <ul
+ tabindex="-1"
+ role="listbox"
+ class="leading-6 shadow-xs overflow-auto focus:outline-hidden sm:text-sm sm:leading-5 relative"
+ :class="[
+ { 'max-h-42': !isSearchable, 'max-h-48': isSearchable },
+ theme.SelectInput.fontSize
+ ]"
+ >
+ <div
+ v-if="isSearchable"
+ class="sticky top-0 z-10 flex border-b bg-white dark:!bg-notion-dark-light"
+ >
+ <input
+ v-model="searchTerm"
+ type="text"
+ class="grow ltr:pl-3 ltr:pr-7 rtl:pr-3! rtl:pl-7 py-2 w-full focus:outline-hidden dark:text-white"
+ :placeholder="allowCreation ? $t('forms.select.searchOrTypeToCreateNew') : $t('forms.select.search')"
+ >
<div
- v-else-if="modelValue"
- key="value"
- class="flex"
+ v-if="!searchTerm"
+ class="flex absolute ltr:right-0 rtl:left-0 rtl:right-auto! inset-y-0 items-center px-2 justify-center pointer-events-none"
>
- <slot
- name="selected"
- :option="modelValue"
- :toggle="select"
+ <Icon
+ name="heroicons:magnifying-glass-solid"
+ class="h-5 w-5 text-neutral-500 dark:text-neutral-400"
/>
</div>
<div
v-else
- key="placeholder"
+ role="button"
+ class="flex absolute ltr:right-0 rtl:right-auto! rtl:left-0 inset-y-0 items-center px-2 justify-center"
+ @click.stop="searchTerm = ''"
>
- <slot name="placeholder">
- <div
- class="text-neutral-400 dark:text-neutral-500 w-full ltr:text-left rtl:text-right! truncate ltr:pr-3 rtl:pl-3 rtl:pr-0!"
- :class="[
- { 'py-1': multiple && !loading },
- theme.SelectInput.fontSize
- ]"
- >
- {{ placeholder }}
- </div>
- </slot>
+ <Icon
+ name="heroicons:backspace"
+ class="h-5 w-5 rtl:rotate-180 text-neutral-500 dark:text-neutral-400"
+ />
</div>
- </transition>
- </div>
- <div
- class="absolute inset-y-0 ltr:right-6 rtl:left-6 w-10 pointer-events-none -z-1"
- :class="[disabled ? 'bg-linear-to-r from-transparent to-neutral-200 dark:to-neutral-800' : theme.SelectInput.chevronGradient]"
- />
- <span
- class="absolute inset-y-0 ltr:right-0 rtl:left-0 rtl:right-auto! flex items-center ltr:pr-2 rtl:pl-2 rtl:pr-0! pointer-events-none"
- :class="[disabled ? 'bg-neutral-200 dark:bg-neutral-800' : theme.SelectInput.background]"
- >
- <Icon
- name="heroicons:chevron-up-down-16-solid"
- class="h-5 w-5 text-neutral-500"
- />
- </span>
- </button>
- <button
- v-if="clearable && showClearButton && !disabled && !isEmpty"
- class="hover:bg-neutral-50 dark:hover:bg-neutral-900 ltr:border-l rtl:border-l-0! rtl:border-r px-2 flex items-center shrink-0"
- :class="[theme.SelectInput.spacing.vertical]"
- @click.prevent="clear()"
- >
- <Icon
- name="heroicons:x-mark-20-solid"
- class="w-5 h-5 text-neutral-500"
- width="2em"
- dynamic
- />
- </button>
- </div>
- <collapsible
- v-model="isOpen"
- class="absolute mt-1 bg-white overflow-auto dark:bg-notion-dark-light shadow-xl z-30"
- :class="[dropdownClass,theme.SelectInput.dropdown, theme.SelectInput.borderRadius]"
- @click-away="onClickAway"
- >
- <ul
- tabindex="-1"
- role="listbox"
- class="leading-6 shadow-xs overflow-auto focus:outline-hidden sm:text-sm sm:leading-5 relative"
- :class="[
- { 'max-h-42': !isSearchable, 'max-h-48': isSearchable },
- theme.SelectInput.fontSize
- ]"
- >
- <div
- v-if="isSearchable"
- class="sticky top-0 z-10 flex border-b bg-white dark:bg-notion-dark-light"
- >
- <input
- v-model="searchTerm"
- type="text"
- class="grow ltr:pl-3 ltr:pr-7 rtl:pr-3! rtl:pl-7 py-2 w-full focus:outline-hidden dark:text-white"
- :placeholder="allowCreation ? $t('forms.select.searchOrTypeToCreateNew') : $t('forms.select.search')"
- >
+ </div>
<div
- v-if="!searchTerm"
- class="flex absolute ltr:right-0 rtl:left-0 rtl:right-auto! inset-y-0 items-center px-2 justify-center pointer-events-none"
+ v-if="loading"
+ class="w-full py-2 flex justify-center"
>
- <Icon
- name="heroicons:magnifying-glass-solid"
- class="h-5 w-5 text-neutral-500 dark:text-neutral-400"
- />
+ <Loader class="h-6 w-6 text-blue-500 mx-auto" />
</div>
<div
- v-else
- role="button"
- class="flex absolute ltr:right-0 rtl:right-auto! rtl:left-0 inset-y-0 items-center px-2 justify-center"
- @click="searchTerm = ''"
+ v-if="filteredOptions.length > 0"
+ class="p-1"
>
- <Icon
- name="heroicons:backspace"
- class="h-5 w-5 rtl:rotate-180 text-neutral-500 dark:text-neutral-400"
- />
+ <li
+ v-for="item in filteredOptions"
+ :key="item[optionKey]"
+ role="option"
+ :style="optionStyle"
+ :class="[
+ dropdownClass,
+ theme.SelectInput.option,
+ theme.SelectInput.spacing.horizontal,
+ theme.SelectInput.spacing.vertical,
+ { 'pr-9': multiple},
+ {
+ 'opacity-50 cursor-not-allowed': disabledOptionsMap[item[optionKey]],
+ 'cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-900': !disabledOptionsMap[item[optionKey]]
+ }
+ ]"
+ class="text-neutral-900 dark:text-neutral-50 select-none relative group rounded-sm focus:outline-hidden"
+ @click.stop="select(item)"
+ >
+ <slot
+ name="option"
+ :option="item"
+ :selected="isSelected(item)"
+ />
+ </li>
</div>
- </div>
- <div
- v-if="loading"
- class="w-full py-2 flex justify-center"
- >
- <Loader class="h-6 w-6 text-blue-500 mx-auto" />
- </div>
- <div
- v-if="filteredOptions.length > 0"
- class="p-1"
- >
- <li
- v-for="item in filteredOptions"
- :key="item[optionKey]"
- role="option"
- :style="optionStyle"
- :class="[
- dropdownClass,
- theme.SelectInput.option,
- theme.SelectInput.spacing.horizontal,
- theme.SelectInput.spacing.vertical,
- { 'pr-9': multiple},
- {
- 'opacity-50 cursor-not-allowed': disabledOptionsMap[item[optionKey]],
- 'cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-900': !disabledOptionsMap[item[optionKey]]
- }
- ]"
- class="text-neutral-900 dark:text-neutral-50 select-none relative group rounded-sm focus:outline-hidden"
- @click="select(item)"
+ <slot
+ v-else-if="!loading && !(allowCreation && searchTerm)"
+ name="empty-placeholder"
>
- <slot
- name="option"
- :option="item"
- :selected="isSelected(item)"
- />
- </li>
- </div>
- <slot
- v-else-if="!loading && !(allowCreation && searchTerm)"
- name="empty-placeholder"
- >
- <p
- class="w-full text-neutral-500 text-center py-2"
- >
- {{ (allowCreation ? $t('forms.select.typeSomethingToAddAnOption') : $t('forms.select.noOptionAvailable')) }}.
- </p>
- </slot>
- <div
- v-if="allowCreation && searchTerm"
- class="border-t border-neutral-300 p-1"
- >
- <li
- role="option"
- :style="optionStyle"
- :class="[{ 'px-3 pr-9': multiple, 'px-3': !multiple },dropdownClass,theme.SelectInput.option]"
- class="text-neutral-900 select-none relative py-2 cursor-pointer group hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded-sm focus:outline-hidden"
- @click="createOption(searchTerm)"
+ <p
+ class="w-full text-neutral-500 text-center py-2"
+ >
+ {{ (allowCreation ? $t('forms.select.typeSomethingToAddAnOption') : $t('forms.select.noOptionAvailable')) }}.
+ </p>
+ </slot>
+ <div
+ v-if="allowCreation && searchTerm"
+ class="border-t border-neutral-300 p-1"
>
- {{ $t('forms.select.create') }} <span class="px-2 bg-neutral-100 border border-neutral-300 rounded-sm group-hover-text-black">{{
- searchTerm
- }}</span>
- </li>
- </div>
- <slot name="after-options" />
- </ul>
- </collapsible>
+ <li
+ role="option"
+ :style="optionStyle"
+ :class="[{ 'px-3 pr-9': multiple, 'px-3': !multiple },dropdownClass,theme.SelectInput.option]"
+ class="text-neutral-900 select-none relative py-2 cursor-pointer group hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded-sm focus:outline-hidden"
+ @click.stop="createOption(searchTerm)"
+ >
+ {{ $t('forms.select.create') }} <span class="px-2 bg-neutral-100 border border-neutral-300 rounded-sm group-hover-text-black">{{
+ searchTerm
+ }}</span>
+ </li>
+ </div>
+ <slot name="after-options" />
+ </ul>
+ </template>
+ </UPopover>
</div>
</template>
<script>
-import Collapsible from '~/components/global/transitions/Collapsible.vue'
import debounce from 'debounce'
import Fuse from 'fuse.js'
import CachedDefaultTheme from '~/lib/forms/themes/CachedDefaultTheme.js'
export default {
name: 'VSelect',
- components: { Collapsible },
+ components: {},
directives: {},
props: {
data: Array,
@@ -337,12 +346,6 @@ export default {
}
},
methods: {
- onClickAway (event) {
- // Check that event target isn't children of dropdown
- if (this.$refs.select && !this.$refs.select.contains(event.target)) {
- this.isOpen = false
- }
- },
isSelected (value) {
if (!this.modelValue) return false
@@ -370,14 +373,11 @@ export default {
toggleDropdown () {
if (this.disabled) {
this.isOpen = false
- } else {
- this.isOpen = !this.isOpen
- if (this.isOpen) {
- this.onFocus()
- } else {
- this.onBlur()
- }
+ return
}
+
+ this.isOpen = !this.isOpen
+
if (!this.isOpen) {
this.searchTerm = ''
}
diff --git a/client/components/global/transitions/Collapsible.vue b/client/components/global/transitions/Collapsible.vue
deleted file mode 100644
index 57bb5a819..000000000
--- a/client/components/global/transitions/Collapsible.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
- <transition @leave="onLeave">
- <div
- v-if="modelValue"
- ref="collapsible"
- v-on-click-outside.bubble="onClickAway"
- >
- <slot />
- </div>
- </transition>
-</template>
-
-<script setup>
-import { vOnClickOutside } from "@vueuse/components"
-
-const props = defineProps({
- modelValue: { type: Boolean },
- maxHeight: { type: Number, default: 200 },
-})
-const emit = defineEmits(["click-away"])
-
-const motion = ref(null)
-const collapsible = ref(null)
-const variants = {
- initial: {
- opacity: 0,
- y: -10,
- transition: { duration: 75, ease: "easeIn" },
- },
- enter: {
- opacity: 1,
- y: 0,
- transition: { duration: 150, ease: "easeOut" },
- },
-}
-
-watch(
- () => props.modelValue,
- (newValue) => {
- if (newValue) {
- nextTick(() => {
- motion.value = useMotion(collapsible.value, variants)
- })
- }
- },
-)
-
-const onLeave = (el, done) => {
- motion.value.leave(done)
-}
-
-const onClickAway = (event) => {
- emit("click-away", event)
-}
-</script>
diff --git a/client/components/open/forms/components/CustomFieldValidation.vue b/client/components/open/forms/components/CustomFieldValidation.vue
index 2df4d0cac..c4a12c587 100644
--- a/client/components/open/forms/components/CustomFieldValidation.vue
+++ b/client/components/open/forms/components/CustomFieldValidation.vue
@@ -55,7 +55,7 @@
sideOffset: 8
}"
:ui="{
- content: 'w-[650px] overflow-auto'
+ content: 'w-[650px] overflow-hidden'
}"
arrow
>
@@ -72,16 +72,18 @@
<template #content>
<ScrollableContainer
ref="scrollableContainer"
- direction="horizontal"
- max-width-class="max-w-[650px] p-4"
+ direction="both"
+ max-width-class="max-w-[650px]"
+ max-height-class="max-h-96"
:fade-class="'from-white via-white/80 to-transparent'"
- class="rounded-lg"
left-fade-width="w-4"
right-fade-width="w-4"
+ top-fade-height="h-4"
+ bottom-fade-height="h-4"
:scroll-tolerance="5"
>
<condition-editor
- class="w-full"
+ class="w-full p-4"
ref="filter-editor"
v-model="validation.conditions"
:form="form"
diff --git a/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue b/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
index cb6a9a06f..cc2a6ebb9 100644
--- a/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
+++ b/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
@@ -55,7 +55,7 @@
sideOffset: 8
}"
:ui="{
- content: 'w-[650px] overflow-auto'
+ content: 'w-[650px] overflow-hidden'
}"
arrow
>
@@ -72,16 +72,18 @@
<template #content>
<ScrollableContainer
ref="scrollableContainer"
- direction="horizontal"
- max-width-class="max-w-[650px] p-4"
+ direction="both"
+ max-width-class="max-w-[650px]"
+ max-height-class="max-h-96"
:fade-class="'from-white via-white/80 to-transparent'"
- class="rounded-lg"
left-fade-width="w-4"
right-fade-width="w-4"
+ top-fade-height="h-4"
+ bottom-fade-height="h-4"
:scroll-tolerance="5"
>
<condition-editor
- class="w-full"
+ class="w-full p-4"
ref="filter-editor"
v-model="logic.conditions"
:form="form"