@@ -16,6 +16,7 @@ export class PageComments extends Component {
1616 private archivedTab ! : HTMLElement ;
1717 private addButtonContainer ! : HTMLElement ;
1818 private archiveContainer ! : HTMLElement ;
19+ private activeContainer ! : HTMLElement ;
1920 private replyToRow ! : HTMLElement ;
2021 private referenceRow ! : HTMLElement ;
2122 private formContainer ! : HTMLElement ;
@@ -48,6 +49,7 @@ export class PageComments extends Component {
4849 this . archivedTab = this . $refs . archivedTab ;
4950 this . addButtonContainer = this . $refs . addButtonContainer ;
5051 this . archiveContainer = this . $refs . archiveContainer ;
52+ this . activeContainer = this . $refs . activeContainer ;
5153 this . replyToRow = this . $refs . replyToRow ;
5254 this . referenceRow = this . $refs . referenceRow ;
5355 this . formContainer = this . $refs . formContainer ;
@@ -76,8 +78,10 @@ export class PageComments extends Component {
7678
7779 protected setupListeners ( ) : void {
7880 this . elem . addEventListener ( 'page-comment-delete' , ( ) => {
79- setTimeout ( ( ) => this . updateCount ( ) , 1 ) ;
80- this . hideForm ( ) ;
81+ setTimeout ( ( ) => {
82+ this . updateCount ( ) ;
83+ this . hideForm ( ) ;
84+ } , 1 ) ;
8185 } ) ;
8286
8387 this . elem . addEventListener ( 'page-comment-reply' , ( ( event : CustomEvent < PageCommentReplyEventData > ) => {
@@ -154,8 +158,10 @@ export class PageComments extends Component {
154158 protected resetForm ( ) : void {
155159 this . removeEditor ( ) ;
156160 this . formInput . value = '' ;
161+ this . parentId = null ;
162+ this . replyToRow . toggleAttribute ( 'hidden' , true ) ;
163+ this . container . append ( this . formContainer ) ;
157164 this . setContentReference ( '' ) ;
158- this . removeReplyTo ( ) ;
159165 }
160166
161167 protected showForm ( ) : void {
@@ -165,9 +171,9 @@ export class PageComments extends Component {
165171 this . formContainer . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } ) ;
166172 this . loadEditor ( ) ;
167173
168- // Ensure the active comments tab is displaying
174+ // Ensure the active comments tab is displaying if that's where we're showing the form
169175 const tabs = window . $components . firstOnElement ( this . elem , 'tabs' ) ;
170- if ( tabs instanceof Tabs ) {
176+ if ( tabs instanceof Tabs && this . formContainer . closest ( '#comment-tab-panel-active' ) ) {
171177 tabs . show ( 'comment-tab-panel-active' ) ;
172178 }
173179 }
@@ -176,7 +182,7 @@ export class PageComments extends Component {
176182 this . resetForm ( ) ;
177183 this . formContainer . toggleAttribute ( 'hidden' , true ) ;
178184 if ( this . getActiveThreadCount ( ) > 0 ) {
179- this . elem . append ( this . addButtonContainer ) ;
185+ this . activeContainer . append ( this . addButtonContainer ) ;
180186 } else {
181187 this . commentCountBar . append ( this . addButtonContainer ) ;
182188 }
@@ -239,7 +245,8 @@ export class PageComments extends Component {
239245 }
240246
241247 public startNewComment ( contentReference : string ) : void {
242- this . removeReplyTo ( ) ;
248+ this . resetForm ( ) ;
249+ this . showForm ( ) ;
243250 this . setContentReference ( contentReference ) ;
244251 }
245252
0 commit comments