Skip to content

Commit

Permalink
Fixed #1041 - Improve the interaction of nested overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Mar 2, 2021
1 parent d51cc96 commit 8c92278
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 39 deletions.
13 changes: 8 additions & 5 deletions src/components/autocomplete/AutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Button ref="dropdownButton" type="button" icon="pi pi-chevron-down" class="p-autocomplete-dropdown" :disabled="$attrs.disabled" @click="onDropdownClick" v-if="dropdown"/>
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="overlayRef" class="p-autocomplete-panel p-component" :style="{'max-height': scrollHeight}" v-if="overlayVisible">
<div :ref="overlayRef" class="p-autocomplete-panel p-component" :style="{'max-height': scrollHeight}" v-if="overlayVisible" @click="onOverlayClick">
<slot name="header" :value="modelValue" :suggestions="suggestions"></slot>
<ul :id="listId" class="p-autocomplete-items" role="listbox">
<template v-if="!optionGroupLabel">
Expand All @@ -43,10 +43,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {UniqueComponentId} from 'primevue/utils';
import {ObjectUtils} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,UniqueComponentId,ObjectUtils,DomHandler,OverlayEventBus} from 'primevue/utils';
import Button from 'primevue/button';
import Ripple from 'primevue/ripple';
Expand Down Expand Up @@ -499,6 +496,12 @@ export default {
},
overlayRef(el) {
this.overlay = el;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
13 changes: 10 additions & 3 deletions src/components/calendar/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CalendarButton v-if="showIcon" :icon="icon" tabindex="-1" class="p-datepicker-trigger" :disabled="$attrs.disabled" @click="onButtonClick" type="button" :aria-label="inputFieldValue"/>
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @leave="onOverlayLeave">
<div :ref="overlayRef" :class="panelStyleClass" v-if="inline ? true : overlayVisible" :role="inline ? null : 'dialog'">
<div :ref="overlayRef" :class="panelStyleClass" v-if="inline ? true : overlayVisible" :role="inline ? null : 'dialog'" @click="onOverlayClick">
<template v-if="!timeOnly">
<div class="p-datepicker-group-container">
<div class="p-datepicker-group" v-for="(month,groupIndex) of months" :key="month.month + month.year">
Expand Down Expand Up @@ -133,10 +133,9 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
import InputText from 'primevue/inputtext';
import Button from 'primevue/button';
import {DomHandler} from 'primevue/utils';
import Ripple from 'primevue/ripple';
export default {
Expand Down Expand Up @@ -1955,6 +1954,14 @@ export default {
},
getMonthName(index) {
return this.$primevue.config.locale.monthNames[index];
},
onOverlayClick(event) {
if (!this.inline) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
}
},
computed: {
Expand Down
12 changes: 8 additions & 4 deletions src/components/cascadeselect/CascadeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="overlayRef" class="p-cascadeselect-panel p-component" v-if="overlayVisible">
<div :ref="overlayRef" class="p-cascadeselect-panel p-component" v-if="overlayVisible" @click="onOverlayClick">
<div class="p-cascadeselect-items-wrapper">
<CascadeSelectSub :options="options" :selectionPath="selectionPath"
:optionLabel="optionLabel" :optionValue="optionValue" :level="0" :templates="$slots"
Expand All @@ -28,9 +28,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {ObjectUtils} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,ObjectUtils,DomHandler,OverlayEventBus} from 'primevue/utils';
import CascadeSelectSub from './CascadeSelectSub.vue';
export default {
Expand Down Expand Up @@ -259,6 +257,12 @@ export default {
this.hide();
break;
}
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
11 changes: 8 additions & 3 deletions src/components/colorpicker/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@click="onInputClick" @keydown="onInputKeydown" v-if="!inline" :aria-labelledby="ariaLabelledBy"/>
<Teleport to="body" :disabled="inline">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="pickerRef" :class="pickerClass" v-if="inline ? true : overlayVisible">
<div :ref="pickerRef" :class="pickerClass" v-if="inline ? true : overlayVisible" @click="onOverlayClick">
<div class="p-colorpicker-content">
<div :ref="colorSelectorRef" class="p-colorpicker-color-selector" @mousedown="onColorMousedown($event)"
@touchstart="onColorDragStart($event)" @touchmove="onDrag($event)" @touchend="onDragEnd()">
Expand All @@ -24,8 +24,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
export default {
emits: ['update:modelValue'],
Expand Down Expand Up @@ -535,6 +534,12 @@ export default {
this.colorHandle = null;
this.hueView = null;
this.hueHandle = null;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
11 changes: 8 additions & 3 deletions src/components/confirmpopup/ConfirmPopup.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Teleport to="body">
<transition name="p-confirm-popup" @enter="onEnter" @leave="onLeave">
<div class="p-confirm-popup p-component" v-if="visible" :ref="containerRef" v-bind="$attrs">
<div class="p-confirm-popup p-component" v-if="visible" :ref="containerRef" v-bind="$attrs" @click="onOverlayClick">
<div class="p-confirm-popup-content">
<i :class="iconClass" />
<span class="p-confirm-popup-message">{{confirmation.message}}</span>
Expand All @@ -17,8 +17,7 @@

<script>
import ConfirmationEventBus from 'primevue/confirmationeventbus';
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
import Button from 'primevue/button';
export default {
Expand Down Expand Up @@ -165,6 +164,12 @@ export default {
},
containerRef(el) {
this.container = el;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.target
});
}
},
computed: {
Expand Down
12 changes: 8 additions & 4 deletions src/components/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="overlayRef" class="p-dropdown-panel p-component" v-if="overlayVisible">
<div :ref="overlayRef" class="p-dropdown-panel p-component" v-if="overlayVisible" @click="onOverlayClick">
<slot name="header" :value="modelValue" :options="visibleOptions"></slot>
<div class="p-dropdown-header" v-if="filter">
<div class="p-dropdown-filter-container">
Expand Down Expand Up @@ -58,9 +58,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {ObjectUtils} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,ObjectUtils,DomHandler,OverlayEventBus} from 'primevue/utils';
import {FilterService} from 'primevue/api';
import Ripple from 'primevue/ripple';
Expand Down Expand Up @@ -564,6 +562,12 @@ export default {
this.itemsWrapper.scrollTop = selectedItem.offsetTop;
}
}
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
11 changes: 8 additions & 3 deletions src/components/menu/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Teleport :to="appendTo" :disabled="!popup">
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave">
<div :ref="containerRef" :class="containerClass" v-if="popup ? overlayVisible : true" v-bind="$attrs">
<div :ref="containerRef" :class="containerClass" v-if="popup ? overlayVisible : true" v-bind="$attrs" @click="onOverlayClick">
<ul class="p-menu-list p-reset" role="menu">
<template v-for="(item, i) of model" :key="item.label + i.toString()">
<template v-if="item.items && visible(item) && !item.separator">
Expand All @@ -21,8 +21,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
import Menuitem from './Menuitem.vue';
export default {
Expand Down Expand Up @@ -176,6 +175,12 @@ export default {
},
containerRef(el) {
this.container = el;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.target
});
}
},
computed: {
Expand Down
12 changes: 8 additions & 4 deletions src/components/multiselect/MultiSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="overlayRef" class="p-multiselect-panel p-component" v-if="overlayVisible">
<div :ref="overlayRef" class="p-multiselect-panel p-component" v-if="overlayVisible" @click="onOverlayClick">
<slot name="header" :value="modelValue" :options="visibleOptions"></slot>
<div class="p-multiselect-header">
<div class="p-checkbox p-component" @click="onToggleAll" role="checkbox" :aria-checked="allSelected">
Expand Down Expand Up @@ -93,9 +93,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {ObjectUtils} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,ObjectUtils,DomHandler,OverlayEventBus} from 'primevue/utils';
import {FilterService} from 'primevue/api';
import Ripple from 'primevue/ripple';
Expand Down Expand Up @@ -473,6 +471,12 @@ export default {
this.$emit('update:modelValue', value);
this.$emit('change', {originalEvent: event, value: value});
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
16 changes: 14 additions & 2 deletions src/components/overlaypanel/OverlayPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Teleport :to="appendTo">
<transition name="p-overlaypanel" @enter="onEnter" @leave="onLeave">
<div class="p-overlaypanel p-component" v-if="visible" :ref="containerRef" v-bind="$attrs">
<div class="p-overlaypanel p-component" v-if="visible" :ref="containerRef" v-bind="$attrs" @click="onOverlayClick">
<div class="p-overlaypanel-content" @click="onContentClick">
<slot></slot>
</div>
Expand All @@ -14,7 +14,7 @@
</template>

<script>
import {UniqueComponentId,DomHandler,ConnectedOverlayScrollHandler} from 'primevue/utils';
import {UniqueComponentId,DomHandler,ConnectedOverlayScrollHandler,OverlayEventBus} from 'primevue/utils';
import Ripple from 'primevue/ripple';
export default {
Expand Down Expand Up @@ -110,11 +110,17 @@ export default {
if (this.autoZIndex) {
this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
}
OverlayEventBus.on('overlay-click', e => {
if (this.container.contains(e.target)) {
this.selfClick = true;
}
});
},
onLeave() {
this.unbindOutsideClickListener();
this.unbindScrollListener();
this.unbindResizeListener();
OverlayEventBus.off('overlay-click');
},
alignOverlay() {
DomHandler.absolutePosition(this.container, this.target);
Expand Down Expand Up @@ -213,6 +219,12 @@ export default {
document.head.removeChild(this.styleElement);
this.styleElement = null;
}
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.target
});
}
},
computed: {
Expand Down
11 changes: 8 additions & 3 deletions src/components/password/Password.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<i v-if="toggleMask" :class="toggleIconClass" @click="onMaskToggle" />
<Teleport :to="appendTo">
<transition name="p-connected-overlay" @enter="onOverlayEnter" @leave="onOverlayLeave">
<div :ref="overlayRef" class="p-password-panel p-component" v-if="overlayVisible">
<div :ref="overlayRef" class="p-password-panel p-component" v-if="overlayVisible" @click="onOverlayClick">
<slot name="header"></slot>
<slot name="content">
<div class="p-password-meter">
Expand All @@ -20,8 +20,7 @@
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
import InputText from 'primevue/inputtext';
export default {
Expand Down Expand Up @@ -221,6 +220,12 @@ export default {
},
onMaskToggle() {
this.unmasked = !this.unmasked;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.$el
});
}
},
computed: {
Expand Down
11 changes: 8 additions & 3 deletions src/components/tieredmenu/TieredMenu.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<template>
<Teleport :to="appendTo" :disabled="!popup">
<transition name="p-connected-overlay" @enter="onEnter" @leave="onLeave">
<div :ref="containerRef" :class="containerClass" v-if="popup ? visible : true" v-bind="$attrs">
<div :ref="containerRef" :class="containerClass" v-if="popup ? visible : true" v-bind="$attrs" @click="onOverlayClick">
<TieredMenuSub :model="model" :root="true" :popup="popup" @leaf-click="onLeafClick"/>
</div>
</transition>
</Teleport>
</template>

<script>
import {ConnectedOverlayScrollHandler} from 'primevue/utils';
import {DomHandler} from 'primevue/utils';
import {ConnectedOverlayScrollHandler,DomHandler,OverlayEventBus} from 'primevue/utils';
import TieredMenuSub from './TieredMenuSub.vue';
export default {
Expand Down Expand Up @@ -157,6 +156,12 @@ export default {
},
containerRef(el) {
this.container = el;
},
onOverlayClick(event) {
OverlayEventBus.emit('overlay-click', {
originalEvent: event,
target: this.target
});
}
},
computed: {
Expand Down
3 changes: 3 additions & 0 deletions src/components/utils/OverlayEventBus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {EventBus} from 'primevue/utils';

export default EventBus();
3 changes: 2 additions & 1 deletion src/components/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import DomHandler from './DomHandler';
import ObjectUtils from './ObjectUtils';
import UniqueComponentId from './UniqueComponentId';
import EventBus from './EventBus';
import OverlayEventBus from './OverlayEventBus';

export {ConnectedOverlayScrollHandler,DomHandler,ObjectUtils,UniqueComponentId,EventBus};
export {ConnectedOverlayScrollHandler,DomHandler,ObjectUtils,UniqueComponentId,EventBus,OverlayEventBus};
Loading

0 comments on commit 8c92278

Please sign in to comment.