Add resize listener to Password

pull/525/head
mertsincan 2020-09-28 14:27:22 +03:00
parent 8f866252dc
commit c9582a42c2
1 changed files with 20 additions and 0 deletions

View File

@ -56,6 +56,7 @@ export default {
},
mediumCheckRegExp: null,
strongCheckRegExp: null,
resizeListener: null,
scrollHandler: null,
overlay: null,
mounted() {
@ -63,6 +64,7 @@ export default {
this.strongCheckRegExp = new RegExp(this.strongRegex);
},
beforeUnmount() {
this.unbindResizeListener();
if (this.scrollHandler) {
this.scrollHandler.destroy();
this.scrollHandler = null;
@ -74,9 +76,11 @@ export default {
this.overlay.style.minWidth = DomHandler.getOuterWidth(this.$refs.input) + 'px';
DomHandler.absolutePosition(this.overlay, this.$refs.input);
this.bindScrollListener();
this.bindResizeListener();
},
onOverlayLeave() {
this.unbindScrollListener();
this.unbindResizeListener();
this.overlay = null;
},
testStrength(str) {
@ -156,6 +160,22 @@ export default {
this.scrollHandler.unbindScrollListener();
}
},
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.overlayVisible = false;
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
overlayRef(el) {
this.overlay = el;
}