Message: restore focus only when target in viewport

This commit is contained in:
Leopoldthecoder 2017-11-01 17:33:51 +08:00 committed by 杨奕
parent aa09c460ff
commit 194874b3b2

View File

@ -87,7 +87,18 @@
if (typeof this.onClose === 'function') {
this.onClose(this);
}
this.originFocus && this.originFocus.focus(); //
if (!this.originFocus || !this.originFocus.getBoundingClientRect) return;
// restore keyboard focus
const { top, left, bottom, right } = this.originFocus.getBoundingClientRect();
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
if (top >= 0 &&
left >= 0 &&
bottom <= viewportHeight &&
right <= viewportWidth) {
this.originFocus.focus();
}
},
clearTimer() {