Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20340 Close decision dropdowns when an option is selected #1446

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion components/ListSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<div class="relative w-full">
<ListboxButton
ref="listboxButton"
class="relative w-full rounded border border-gray-300 bg-white py-1.5 pl-3 pr-10 text-left transition sm:text-sm"
:class="{
'hover:bg-gray-100': !disabled,
Expand Down Expand Up @@ -87,11 +88,13 @@ import {
import { ChevronDownIcon, CheckIcon } from '@heroicons/vue/24/outline'

type ModelValueType = any
defineProps<{
const props = defineProps<{
modelValue: ModelValueType | Array<ModelValueType>
options: Array<any>
/** Whether multiple options can be selected */
multiple?: boolean
/** Only applies if `multiple` prop is also passed in. Close the `ListSelect` when an option is [de]selected.*/
closeOnSelect?: boolean
/** Whether the component is disabled (can't be clicked, grayed out) */
disabled?: boolean
optionsStyle?: string
Expand All @@ -106,8 +109,14 @@ const emit = defineEmits<{
(e: 'update:modelValue', newValue: any): void
}>()

const listboxButton = ref<InstanceType<typeof ListboxButton>>()

const updateModelValue = (newValue: any) => {
emit('update:modelValue', newValue)
emit('change', newValue)
// close the listbox when an option is selected/deselected even when multiple options can be selected
if (props.multiple && props.closeOnSelect) {
listboxButton.value?.$el.click()
}
}
</script>
1 change: 1 addition & 0 deletions components/examine/decision/select/Conditions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
options-style="!max-h-48"
:disabled="examine.decisionSelectionsDisabled"
multiple
close-on-select
>
<Chips
v-if="examine.selectedConditions.length > 0"
Expand Down
3 changes: 2 additions & 1 deletion components/examine/decision/select/Conflicts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
<ListSelect
v-model="conflicts.selectedConflicts"
:options="options"
multiple
options-style="!max-h-48 !max-w-md"
:options-display="(option: ConflictListItem) => option.text"
:disabled="examine.decisionSelectionsDisabled"
@change="(_) => conflicts.syncSelectedAndComparedConflicts()"
multiple
close-on-select
>
<Chips
v-if="conflicts.selectedConflicts.length > 0"
Expand Down
3 changes: 2 additions & 1 deletion components/examine/decision/select/Macros.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<div>
<h3 class="font-semibold">Macros</h3>
<ListSelect
multiple
v-model="examine.selectedMacros"
:disabled="examine.decisionSelectionsDisabled"
:options="examine.macros"
:options-display="(option: Macro) => option.name"
options-style="!max-h-48"
multiple
close-on-select
>
<Chips
v-if="examine.selectedMacros.length > 0"
Expand Down
3 changes: 2 additions & 1 deletion components/examine/decision/select/Trademarks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<h3 class="font-semibold">Trademarks</h3>
<ListSelect
v-model="examine.selectedTrademarks"
multiple
:options="examine.trademarks"
options-style="!max-h-40"
:options-display="displayTrademark"
:disabled="examine.decisionSelectionsDisabled"
multiple
close-on-select
>
<Chips
v-if="examine.selectedTrademarks.length > 0"
Expand Down
Loading
Loading