Skip to content

Commit 17f3fce

Browse files
authored
Scroll the selected image to view in Gallery (#3530)
1 parent 338fb8b commit 17f3fce

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/components/GalleryViewThumbnail.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ export class GalleryViewThumbnail extends Component {
1919
constructor(props) {
2020
super(props);
2121

22+
this.myRef = React.createRef();
2223
this.state = { requestedAnnotations: false };
2324

2425
this.handleSelect = this.handleSelect.bind(this);
2526
this.handleKey = this.handleKey.bind(this);
2627
this.handleIntersection = this.handleIntersection.bind(this);
2728
}
2829

30+
// eslint-disable-next-line require-jsdoc
31+
componentDidMount() {
32+
const { selected } = this.props;
33+
if (selected) {
34+
this.myRef.current?.scrollIntoView(true);
35+
}
36+
}
37+
2938
/** @private */
3039
handleSelect() {
3140
const {
@@ -112,6 +121,7 @@ export class GalleryViewThumbnail extends Component {
112121
}
113122
onClick={this.handleSelect}
114123
onKeyUp={this.handleKey}
124+
ref={this.myRef}
115125
role="button"
116126
tabIndex={0}
117127
>

0 commit comments

Comments
 (0)