Fix dropdown quirks (#63)

This commit is contained in:
Geometrically
2023-06-06 16:07:58 -07:00
committed by GitHub
parent d98a6adfb3
commit 01304e807a
4 changed files with 17 additions and 12 deletions

View File

@@ -1,8 +1,11 @@
# Dropdown # Dropdown
<script setup> <script setup>
import { ref } from "vue"; import {ref} from "vue";
const value = ref(null) const value = ref(null);
const newValue = ref(null);
const options = ref([{ test: 'hello', display: 'no' }, { test: 'nob', display: 'yes' }, { test: 'ball', display: 'eat' }]);
</script> </script>
<DemoContainer> <DemoContainer>
@@ -24,10 +27,10 @@ const value = ref(null)
disabled disabled
/> />
<DropdownSelect <DropdownSelect
v-model="value" v-model="newValue"
:options="['Daily', 'Weekly', 'Monthly', 'Tomorrow', 'Yesterday', 'Today', 'Biweekly', 'Tuesday', 'January']" :options="options"
placeholder="Choose Frequency" placeholder="Choose Frequency"
:display-name="(name) => name?.toUpperCase()" :display-name="(name) => name?.display"
/> />
</DemoContainer> </DemoContainer>

View File

@@ -238,7 +238,7 @@ onBeforeUnmount(() => {
.options { .options {
z-index: 10; z-index: 10;
max-height: min(12rem); max-height: 18.75remq;
overflow-y: auto; overflow-y: auto;
box-shadow: var(--shadow-inset-sm), 0 0 0 0 transparent; box-shadow: var(--shadow-inset-sm), 0 0 0 0 transparent;

View File

@@ -7,6 +7,7 @@
class="animated-dropdown" class="animated-dropdown"
@focus="onFocus" @focus="onFocus"
@blur="onBlur" @blur="onBlur"
@focusout="onBlur"
@mousedown.prevent @mousedown.prevent
@keydown.enter.prevent="toggleDropdown" @keydown.enter.prevent="toggleDropdown"
@keydown.up.prevent="focusPreviousOption" @keydown.up.prevent="focusPreviousOption"
@@ -72,15 +73,15 @@ const props = defineProps({
required: true, required: true,
}, },
defaultValue: { defaultValue: {
type: String, type: [String, Number, Object],
default: null, default: null,
}, },
placeholder: { placeholder: {
type: String, type: [String, Number],
default: null, default: null,
}, },
modelValue: { modelValue: {
type: String, type: [String, Number, Object],
default: null, default: null,
}, },
renderUp: { renderUp: {
@@ -147,6 +148,7 @@ const onFocus = () => {
} }
const onBlur = (event) => { const onBlur = (event) => {
console.log(event)
if (!isChildOfDropdown(event.relatedTarget)) { if (!isChildOfDropdown(event.relatedTarget)) {
dropdownVisible.value = false dropdownVisible.value = false
} }
@@ -176,7 +178,7 @@ const focusNextOptionOrOpen = () => {
const isChildOfDropdown = (element) => { const isChildOfDropdown = (element) => {
let currentNode = element let currentNode = element
while (currentNode) { while (currentNode) {
if (currentNode === this.$el) { if (currentNode === dropdown.value) {
return true return true
} }
currentNode = currentNode.parentNode currentNode = currentNode.parentNode
@@ -243,7 +245,7 @@ const isChildOfDropdown = (element) => {
.options { .options {
z-index: 10; z-index: 10;
max-height: min(12rem); max-height: 18.75rem;
overflow-y: auto; overflow-y: auto;
box-shadow: var(--shadow-inset-sm), 0 0 0 0 transparent; box-shadow: var(--shadow-inset-sm), 0 0 0 0 transparent;

View File

@@ -1,7 +1,7 @@
{ {
"name": "omorphia", "name": "omorphia",
"type": "module", "type": "module",
"version": "0.4.23", "version": "0.4.24",
"files": [ "files": [
"dist", "dist",
"lib" "lib"