Tabs: remove box shadow when browser hidden / blur (#10503)

pull/10511/head
杨奕 2018-04-02 13:12:03 +08:00 committed by GitHub
parent 528bce4479
commit 464f81886f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 2 deletions

View File

@ -35,7 +35,8 @@
return { return {
scrollable: false, scrollable: false,
navOffset: 0, navOffset: 0,
isFocus: false isFocus: false,
focusable: true
}; };
}, },
@ -150,10 +151,28 @@
this.setFocus(); this.setFocus();
}, },
setFocus() { setFocus() {
if (this.focusable) {
this.isFocus = true; this.isFocus = true;
}
}, },
removeFocus() { removeFocus() {
this.isFocus = false; this.isFocus = false;
},
visibilityChangeHandler() {
const visibility = document.visibilityState;
if (visibility === 'hidden') {
this.focusable = false;
} else if (visibility === 'visible') {
this.focusable = true;
}
},
windowBlurHandler() {
this.focusable = false;
},
windowFocusHandler() {
setTimeout(() => {
this.focusable = true;
}, 50);
} }
}, },
@ -236,10 +255,16 @@
mounted() { mounted() {
addResizeListener(this.$el, this.update); addResizeListener(this.$el, this.update);
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
window.addEventListener('blur', this.windowBlurHandler);
window.addEventListener('focus', this.windowFocusHandler);
}, },
beforeDestroy() { beforeDestroy() {
if (this.$el && this.update) removeResizeListener(this.$el, this.update); if (this.$el && this.update) removeResizeListener(this.$el, this.update);
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
window.removeEventListener('blur', this.windowBlurHandler);
window.removeEventListener('focus', this.windowFocusHandler);
} }
}; };
</script> </script>