Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Ability to collapse posts with no children in nested (#40376)

Mark VanLandingham947c99ef0633
diff --git a/app/assets/stylesheets/common/nested-view.scss b/app/assets/stylesheets/common/nested-view.scss
index 88852d62c89..1c6afb424a9 100644
--- a/app/assets/stylesheets/common/nested-view.scss
+++ b/app/assets/stylesheets/common/nested-view.scss
@@ -489,6 +489,33 @@
}
}
+ &--leaf {
+ &::after {
+ opacity: 0.18;
+ transition:
+ background-color 0.15s ease,
+ opacity 0.15s ease;
+ }
+
+ .nested-post__depth-line-icon .d-icon {
+ opacity: 0.45;
+ transition:
+ color 0.15s ease,
+ opacity 0.15s ease;
+ }
+
+ &:focus-visible,
+ &.nested-post__depth-line--highlighted {
+ &::after {
+ opacity: 1;
+ }
+
+ .nested-post__depth-line-icon .d-icon {
+ opacity: 1;
+ }
+ }
+ }
+
// When children are collapsed, turn the vertical line into an L-shape
// that bends toward the "N replies" expand button
&--collapsed {
@@ -524,6 +551,18 @@
}
}
+ @media (hover: hover) {
+ &:hover > .nested-post__gutter .nested-post__depth-line--leaf {
+ &::after {
+ opacity: 1;
+ }
+
+ .nested-post__depth-line-icon .d-icon {
+ opacity: 1;
+ }
+ }
+ }
+
&__depth-line-icon {
position: absolute;
bottom: 0;
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index ed1068f2565..6cb9a2f3f77 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4027,6 +4027,7 @@ en:
collapsed_replies:
one: "%{count} reply"
other: "%{count} replies"
+ collapsed_post: "Collapsed post"
collapse: "Collapse"
collapse_parent: "Collapse parent thread"
focused_path: "Focused reply path"
diff --git a/frontend/discourse/app/components/nested/post.gjs b/frontend/discourse/app/components/nested/post.gjs
index 9102c103e19..10819610f18 100644
--- a/frontend/discourse/app/components/nested/post.gjs
+++ b/frontend/discourse/app/components/nested/post.gjs
@@ -194,7 +194,15 @@ export default class NestedPost extends Component {
}
get showDepthLine() {
- return this.hasReplies && (!this.atMaxDepth || this.showContinueThread);
+ return !this.hasReplies || !this.atMaxDepth || this.showContinueThread;
+ }
+
+ get depthLineCollapsed() {
+ return this.hasReplies && !this.expanded;
+ }
+
+ get showDepthLineIcon() {
+ return !this.hasReplies || this.expanded;
}
get showExpandRepliesButton() {
@@ -236,8 +244,32 @@ export default class NestedPost extends Component {
});
}
+ get collapsedBarLabel() {
+ return this.hasReplies
+ ? this.expandLabel
+ : i18n("nested_replies.collapsed_post");
+ }
+
+ get depthLineLabel() {
+ if (this.depthLineCollapsed) {
+ return this.expandLabel;
+ }
+
+ return i18n("nested_replies.collapse");
+ }
+
@action
toggleExpanded() {
+ if (!this.hasReplies) {
+ this.collapsed = !this.collapsed;
+ this.lineHighlighted = false;
+ this.args.expansionState?.set(this.args.post.post_number, {
+ expanded: this.expanded,
+ collapsed: this.collapsed,
+ });
+ return;
+ }
+
if (this.expanded) {
this.expanded = false;
this.collapsed = true;
@@ -422,18 +454,17 @@ export default class NestedPost extends Component {
class={{dConcatClass
"nested-post__depth-line"
(if this.lineHighlighted "nested-post__depth-line--highlighted")
- (unless this.expanded "nested-post__depth-line--collapsed")
+ (unless this.hasReplies "nested-post__depth-line--leaf")
+ (if
+ this.depthLineCollapsed "nested-post__depth-line--collapsed"
+ )
}}
{{on "click" this.toggleExpanded}}
{{on "mouseenter" this.highlightLine}}
{{on "mouseleave" this.unhighlightLine}}
- aria-label={{if
- this.expanded
- (i18n "nested_replies.collapse")
- this.expandLabel
- }}
+ aria-label={{this.depthLineLabel}}
>
- {{#if this.expanded}}
+ {{#if this.showDepthLineIcon}}
<span class="nested-post__depth-line-icon">
{{dIcon "discourse-circle-minus"}}
</span>
@@ -469,7 +500,7 @@ export default class NestedPost extends Component {
>&middot;</span>
<span
class="nested-post__collapsed-reply-count"
- >{{this.expandLabel}}</span>
+ >{{this.collapsedBarLabel}}</span>
</button>
{{else if this.isDeletedPlaceholder}}
<div
diff --git a/frontend/discourse/tests/integration/components/nested/post-test.gjs b/frontend/discourse/tests/integration/components/nested/post-test.gjs
new file mode 100644
index 00000000000..578bae41e8f
--- /dev/null
+++ b/frontend/discourse/tests/integration/components/nested/post-test.gjs
@@ -0,0 +1,124 @@
+import { getOwner } from "@ember/owner";
+import { click, render } from "@ember/test-helpers";
+import { modifier } from "ember-modifier";
+import { module, test } from "qunit";
+import NestedPost from "discourse/components/nested/post";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import { i18n } from "discourse-i18n";
+
+const noop = () => {};
+const registerPost = modifier(() => {});
+
+function renderComponent(context) {
+ return render(
+ <template>
+ <NestedPost
+ @post={{context.post}}
+ @children={{context.children}}
+ @topic={{context.topic}}
+ @depth={{0}}
+ @path={{context.path}}
+ @sort="top"
+ @replyToPost={{noop}}
+ @editPost={{noop}}
+ @deletePost={{noop}}
+ @recoverPost={{noop}}
+ @showFlags={{noop}}
+ @showHistory={{noop}}
+ @changeNotice={{noop}}
+ @changePostOwner={{noop}}
+ @grantBadge={{noop}}
+ @lockPost={{noop}}
+ @unlockPost={{noop}}
+ @permanentlyDeletePost={{noop}}
+ @rebakePost={{noop}}
+ @showPagePublish={{noop}}
+ @togglePostType={{noop}}
+ @toggleWiki={{noop}}
+ @unhidePost={{noop}}
+ @expansionState={{context.expansionState}}
+ @fetchedChildrenCache={{context.fetchedChildrenCache}}
+ @registerPost={{registerPost}}
+ />
+ </template>
+ );
+}
+
+module("Integration | Component | Nested | Post", function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.siteSettings.nested_replies_max_depth = 6;
+ this.store = getOwner(this).lookup("service:store");
+ this.topic = this.store.createRecord("topic", {
+ id: 1,
+ slug: "nested-topic",
+ user_id: 1,
+ });
+ this.path = [];
+ this.children = [];
+ this.expansionState = new Map();
+ this.fetchedChildrenCache = new Map();
+ this.post = this.store.createRecord("post", {
+ id: 2,
+ post_number: 2,
+ topic: this.topic,
+ user_id: 2,
+ username: "leaf-user",
+ avatar_template: "/letter_avatar_proxy/v4/letter/l/25/48.png",
+ cooked: "<p>Leaf post</p>",
+ created_at: "2026-01-01T00:00:00.000Z",
+ actions_summary: [],
+ direct_reply_count: 0,
+ total_descendant_count: 0,
+ });
+ });
+
+ test("leaf posts can be collapsed from the depth line", async function (assert) {
+ await renderComponent(this);
+
+ assert
+ .dom(".nested-post__depth-line")
+ .exists("renders a depth-line for a post without replies");
+ assert
+ .dom(".nested-post__depth-line-icon")
+ .exists("renders the collapse affordance");
+ assert
+ .dom(".nested-post__depth-line")
+ .hasClass(
+ "nested-post__depth-line--leaf",
+ "uses the low-emphasis leaf depth-line"
+ );
+ assert
+ .dom(".nested-post__depth-line")
+ .doesNotHaveClass(
+ "nested-post__depth-line--collapsed",
+ "does not use the replies-hidden line state"
+ );
+
+ await click(".nested-post__depth-line");
+
+ assert.dom(".nested-post__article").doesNotExist("collapses the post body");
+ assert.dom(".nested-post__collapsed-bar").exists("shows the collapsed bar");
+ assert
+ .dom(".nested-post__collapsed-reply-count")
+ .hasText(i18n("nested_replies.collapsed_post"));
+ assert.deepEqual(
+ this.expansionState.get(2),
+ { expanded: false, collapsed: true },
+ "stores the collapsed leaf state"
+ );
+
+ await click(".nested-post__collapsed-bar");
+
+ assert.dom(".nested-post__article").exists("expands the post body again");
+ assert
+ .dom(".nested-post__depth-line")
+ .exists("restores the depth-line affordance");
+ assert.deepEqual(
+ this.expansionState.get(2),
+ { expanded: false, collapsed: false },
+ "stores the expanded leaf state"
+ );
+ });
+});
diff --git a/spec/system/nested_replying_spec.rb b/spec/system/nested_replying_spec.rb
index 4f88c1e70af..fe1c0f72575 100644
--- a/spec/system/nested_replying_spec.rb
+++ b/spec/system/nested_replying_spec.rb
@@ -131,7 +131,7 @@ RSpec.describe "Nested view replying" do
it "shows the depth line on the parent without refresh" do
nested_view.visit_nested(topic)
- expect(nested_view).to have_no_depth_line_for(root_reply)
+ expect(nested_view).to have_leaf_depth_line_for(root_reply)
nested_view.click_reply_on_post(root_reply)
composer.fill_content("First child reply")
@@ -139,6 +139,7 @@ RSpec.describe "Nested view replying" do
expect(composer).to be_closed
expect(nested_view).to have_depth_line_for(root_reply)
+ expect(nested_view).to have_no_leaf_depth_line_for(root_reply)
end
end
diff --git a/spec/system/page_objects/pages/nested_view.rb b/spec/system/page_objects/pages/nested_view.rb
index bb17375ded5..d22cbfe38e6 100644
--- a/spec/system/page_objects/pages/nested_view.rb
+++ b/spec/system/page_objects/pages/nested_view.rb
@@ -158,35 +158,43 @@ module PageObjects
end
def has_depth_line_for?(post)
- has_css?(wrapper_selector(post, ".nested-post__gutter .nested-post__depth-line"))
+ has_css?(depth_line_selector(post))
end
def has_no_depth_line_for?(post)
- has_no_css?(wrapper_selector(post, ".nested-post__gutter .nested-post__depth-line"))
+ has_no_css?(depth_line_selector(post))
+ end
+
+ def has_leaf_depth_line_for?(post)
+ has_css?(leaf_depth_line_selector(post))
+ end
+
+ def has_no_leaf_depth_line_for?(post)
+ has_no_css?(leaf_depth_line_selector(post))
end
def has_children_visible_for?(post)
- has_css?(wrapper_selector(post, ".nested-post-children"))
+ has_css?(wrapper_selector(post, "> .nested-post__main > .nested-post-children"))
end
def has_no_children_visible_for?(post)
- has_no_css?(wrapper_selector(post, ".nested-post-children"))
+ has_no_css?(wrapper_selector(post, "> .nested-post__main > .nested-post-children"))
end
def has_collapsed_bar_for?(post)
- has_css?(wrapper_selector(post, ".nested-post__collapsed-bar"))
+ has_css?(wrapper_selector(post, "> .nested-post__main > .nested-post__collapsed-bar"))
end
def has_no_collapsed_bar_for?(post)
- has_no_css?(wrapper_selector(post, ".nested-post__collapsed-bar"))
+ has_no_css?(wrapper_selector(post, "> .nested-post__main > .nested-post__collapsed-bar"))
end
def has_post_content_visible_for?(post)
- has_css?(wrapper_selector(post, ".nested-post__article"))
+ has_css?(wrapper_selector(post, "> .nested-post__main > .nested-post__article"))
end
def has_no_post_content_visible_for?(post)
- has_no_css?(wrapper_selector(post, ".nested-post__article"))
+ has_no_css?(wrapper_selector(post, "> .nested-post__main > .nested-post__article"))
end
def has_sort_active?(sort)
@@ -350,12 +358,12 @@ module PageObjects
end
def click_depth_line(post)
- find(wrapper_selector(post, ".nested-post__depth-line")).click
+ find(depth_line_selector(post)).click
self
end
def click_collapsed_bar(post)
- find(wrapper_selector(post, ".nested-post__collapsed-bar")).click
+ find(wrapper_selector(post, "> .nested-post__main > .nested-post__collapsed-bar")).click
self
end
@@ -573,6 +581,14 @@ module PageObjects
base = ".nested-post:has(> .nested-post__main > [data-post-number='#{post.post_number}'])"
child_selector ? "#{base} #{child_selector}" : base
end
+
+ def depth_line_selector(post)
+ wrapper_selector(post, "> .nested-post__gutter .nested-post__depth-line")
+ end
+
+ def leaf_depth_line_selector(post)
+ wrapper_selector(post, "> .nested-post__gutter .nested-post__depth-line--leaf")
+ end
end
end
end