Skip to content

Commit

Permalink
Image: Fix shield the page when preview big image (#16796) (#16997)
Browse files Browse the repository at this point in the history
* 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 island205 committed Oct 31, 2019
1 parent 6ff305c commit fcaec91
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 comment has been minimized.

Copy link
@DevBrent

DevBrent Dec 19, 2019

This is breaking MANY websites that do not even use image-viewer for their el-image components.

Please wrap this breaking change in a check to confirm if the el-image actually has previewSrcList.length first!!!

#18234

this.showViewer = true;
},
closeViewer() {
document.body.style.overflow = prevOverflow;
this.showViewer = false;
}
}
Expand Down

0 comments on commit fcaec91

Please sign in to comment.