File tree Expand file tree Collapse file tree 1 file changed +39
-9
lines changed
Expand file tree Collapse file tree 1 file changed +39
-9
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,44 @@ type Props = {
1313 onDelete : Function
1414} ;
1515
16- const CommentList = ( { comments, onDelete } : Props ) => (
17- < ul className = { CLASS_COMMENT_LIST } >
18- { comments . map ( ( { id, ...rest } ) => (
19- < li className = { CLASS_COMMENT_LIST_ITEM } key = { `annotation_${ id } ` } >
20- < Comment id = { id } onDelete = { onDelete } { ...rest } />
21- </ li >
22- ) ) }
23- </ ul >
24- ) ;
16+ class CommentList extends React . Component < Props > {
17+ commentsContainer : null | HTMLElement ;
18+
19+ componentDidMount ( ) {
20+ this . scrollToBottom ( ) ;
21+ }
22+
23+ componentDidUpdate ( ) {
24+ this . scrollToBottom ( ) ;
25+ }
26+
27+ /**
28+ * Scrolls the container to the bottom
29+ * @return {void }
30+ */
31+ scrollToBottom = ( ) => {
32+ if ( this . commentsContainer ) {
33+ this . commentsContainer . scrollTop = this . commentsContainer . scrollHeight ;
34+ }
35+ } ;
36+
37+ render ( ) {
38+ const { comments, onDelete } = this . props ;
39+ return (
40+ < ul
41+ className = { CLASS_COMMENT_LIST }
42+ ref = { ( ref ) => {
43+ this . commentsContainer = ref ;
44+ } }
45+ >
46+ { comments . map ( ( { id, ...rest } ) => (
47+ < li className = { CLASS_COMMENT_LIST_ITEM } key = { `annotation_${ id } ` } >
48+ < Comment id = { id } onDelete = { onDelete } { ...rest } />
49+ </ li >
50+ ) ) }
51+ </ ul >
52+ ) ;
53+ }
54+ }
2555
2656export default CommentList ;
You can’t perform that action at this time.
0 commit comments