diff --git a/src/UiSelect.vue b/src/UiSelect.vue index 5ea85e50..08e9a0b3 100644 --- a/src/UiSelect.vue +++ b/src/UiSelect.vue @@ -23,7 +23,6 @@ :tabindex="disabled ? null : '0'" - @click="toggleDropdown" @focus="onFocus" @keydown.enter.prevent="openDropdown" @keydown.space.prevent="openDropdown" @@ -31,7 +30,9 @@ >
{{ label }} @@ -50,10 +51,19 @@
- +
@@ -129,7 +139,7 @@
-
+
@@ -147,13 +157,16 @@ @@ -711,7 +731,6 @@ export default { margin: 0; outline: none; padding: 0; - position: relative; width: 100%; } @@ -773,9 +792,6 @@ export default { } .ui-select__dropdown { - background-color: white; - box-shadow: 1px 2px 8px $md-grey-600; - color: $primary-text-color; display: block; list-style-type: none; margin: 0; @@ -783,9 +799,11 @@ export default { min-width: rem-calc(180px); outline: none; padding: 0; - position: absolute; width: 100%; - z-index: $z-index-dropdown; +} + +.ui-select__dropdown-content { + outline: none; } .ui-select__search-input { @@ -815,12 +833,15 @@ export default { &:focus + .ui-select__search-icon { color: $ui-input-label-color--active; } + } -.ui-select__search-icon, -.ui-select__search-progress { - position: absolute; - top: rem-calc(8px); +.ui-select__search { + .ui-select__search-icon, + .ui-select__search-progress { + position: absolute; + top: rem-calc(8px); + } } .ui-select__search-icon { @@ -873,18 +894,4 @@ export default { order: 1; } } - -// ================================================ -// Transitions -// ================================================ - -.ui-select--transition-fade-enter-active, -.ui-select--transition-fade-leave-active { - transition: opacity 0.2s ease; -} - -.ui-select--transition-fade-enter, -.ui-select--transition-fade-leave-active { - opacity: 0; -} diff --git a/src/mixins/RespondsToExternalClick.js b/src/mixins/RespondsToExternalClick.js new file mode 100644 index 00000000..54bb08d3 --- /dev/null +++ b/src/mixins/RespondsToExternalClick.js @@ -0,0 +1,28 @@ +export default { + beforeDestroy() { + if (typeof this.externalClickListener === 'function') { + this.removeExternalClickListener(); + } + }, + + methods: { + addExternalClickListener(element = this.$el, callback = null) { + this.externalClickListener = e => { + if (!element.contains(e.target)) { + if (typeof callback === 'function') { + callback(e); + } else { + this.$emit('external-click', e); + } + } + }; + + document.addEventListener('click', this.externalClickListener); + }, + + removeExternalClickListener() { + document.removeEventListener('click', this.externalClickListener); + this.externalClickListener = null; + } + } +};