File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ class="comments-list tab-container"
2424
aria-selected="false">{{ trans_choice('entities.comment_archived_count', count($commentTree->getArchived())) }}</button>
2525
</div>
2626
@if ($commentTree->empty() && userCan('comment-create-all'))
27-
<div class="ml-m" refs="page-comments@add-button-container">
27+
<div refs="page-comments@add-button-container" class="ml-m flex-container-row" >
2828
<button type="button"
2929
refs="page-comments@add-comment-button"
30-
class="button outline mb-m">{{ trans('entities.comment_add') }}</button>
30+
class="button outline mb-m ml-auto">{{ trans('entities.comment_add') }}</button>
3131
</div>
3232
@endif
3333
</div>
3434

3535
<div id="comment-tab-panel-active"
36+
refs="page-comments@active-container"
3637
tabindex="0"
3738
role="tabpanel"
3839
aria-labelledby="comment-tab-active"
@@ -48,10 +49,10 @@ class="comment-container no-outline">
4849
@if(userCan('comment-create-all'))
4950
@include('comments.create')
5051
@if (!$commentTree->empty())
51-
<div refs="page-comments@addButtonContainer" class="flex-container-row">
52+
<div refs="page-comments@addButtonContainer" class="ml-m flex-container-row">
5253
<button type="button"
5354
refs="page-comments@add-comment-button"
54-
class="button outline ml-auto">{{ trans('entities.comment_add') }}</button>
55+
class="button outline mb-m ml-auto">{{ trans('entities.comment_add') }}</button>
5556
</div>
5657
@endif
5758
@endif

0 commit comments

Comments
 (0)