Skip to content

Commit

Permalink
Image: Fix shield the page when preview big image (ElemeFE#16796) (El…
Browse files Browse the repository at this point in the history
…emeFE#16997)

* Image: Fix shield the page when preview big image

* refine

* Image:fix page scroll when use image-viewer by keyup and keydown

* add notes
  • Loading branch information
luckyCao authored and lzq4047 committed May 22, 2020
1 parent 71665d2 commit c79b64e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/image/src/image-viewer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<transition name="viewer-fade">
<div class="el-image-viewer__wrapper" :style="{ 'z-index': zIndex }">
<div tabindex="-1" ref="el-image-viewer__wrapper" class="el-image-viewer__wrapper" :style="{ 'z-index': zIndex }">
<div class="el-image-viewer__mask"></div>
<!-- CLOSE -->
<span class="el-image-viewer__btn el-image-viewer__close" @click="hide">
Expand Down Expand Up @@ -294,6 +294,9 @@ export default {
},
mounted() {
this.deviceSupportInstall();
// add tabindex then wrapper can be focusable via Javascript
// focus wrapper so arrow key can't cause inner scroll behavior underneath
this.$refs['el-image-viewer__wrapper'].focus();
}
};
</script>
6 changes: 6 additions & 0 deletions packages/image/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
SCALE_DOWN: 'scale-down'
};
let prevOverflow = '';
export default {
name: 'ElImage',
Expand Down Expand Up @@ -215,9 +217,13 @@
}
},
clickHandler() {
// prevent body scroll
prevOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
this.showViewer = true;
},
closeViewer() {
document.body.style.overflow = prevOverflow;
this.showViewer = false;
}
}
Expand Down

0 comments on commit c79b64e

Please sign in to comment.