Skip to content

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

UX: keep rich editor details open but serialize as closed (#38369)

Renato Atiliodde574a623cb
diff --git a/plugins/discourse-details/assets/javascripts/lib/rich-editor-extension.js b/plugins/discourse-details/assets/javascripts/lib/rich-editor-extension.js
index af27f773180..196593c9507 100644
--- a/plugins/discourse-details/assets/javascripts/lib/rich-editor-extension.js
+++ b/plugins/discourse-details/assets/javascripts/lib/rich-editor-extension.js
@@ -20,9 +20,7 @@ const extension = {
parse: {
bbcode_open(state, token) {
if (token.tag === "details") {
- state.openNode(state.schema.nodes.details, {
- open: token.attrGet("open") !== null,
- });
+ state.openNode(state.schema.nodes.details);
return true;
}
@@ -43,7 +41,7 @@ const extension = {
state.renderContent(node);
state.write("[/details]\n\n");
},
- summary(state, node, parent) {
+ summary(state, node) {
let hasSummary = false;
// If the [details] tag has no summary.
if (node.content.childCount === 0) {
@@ -57,7 +55,7 @@ const extension = {
state.text(child.text.replace(/"/g, "“"), state.inAutolink)
);
}
- let finalState = `${parent.attrs.open ? " open" : ""}]\n`;
+ let finalState = "]\n";
if (hasSummary) {
finalState = `"${finalState}`;
}
diff --git a/plugins/discourse-details/spec/system/details_spec.rb b/plugins/discourse-details/spec/system/details_spec.rb
index 9fd27ef9e80..a5cdc029263 100644
--- a/plugins/discourse-details/spec/system/details_spec.rb
+++ b/plugins/discourse-details/spec/system/details_spec.rb
@@ -17,7 +17,6 @@ describe "Details button", type: :system do
composer.fill_content("test :+1:").toggle_rich_editor.select_all
find(".toolbar-menu__options-trigger").click
find("button[title='Hide details']").click
- rich.click(x: 22, y: 30) # hack for pseudo element
expect(rich).to have_css(
"details img.emoji[src=\"/images/emoji/twitter/+1.png?v=#{Emoji::EMOJI_VERSION}\"]",
diff --git a/plugins/discourse-details/test/javascripts/integration/prosemirror-editor/details-test.js b/plugins/discourse-details/test/javascripts/integration/prosemirror-editor/details-test.js
index a67988fe6f0..970f6f7f84f 100644
--- a/plugins/discourse-details/test/javascripts/integration/prosemirror-editor/details-test.js
+++ b/plugins/discourse-details/test/javascripts/integration/prosemirror-editor/details-test.js
@@ -15,7 +15,7 @@ module(
details: [
[
`[details="Summary"]This text will be hidden[/details]`,
- `<details><summary>Summary</summary><p>This text will be hidden</p></details>`,
+ `<details open="true"><summary>Summary</summary><p>This text will be hidden</p></details>`,
`[details="Summary"]\nThis text will be hidden\n\n[/details]\n\n`,
],
],
@@ -23,13 +23,13 @@ module(
[
`[details="Summary" open]This text will be hidden[/details]`,
`<details open="true"><summary>Summary</summary><p>This text will be hidden</p></details>`,
- `[details="Summary" open]\nThis text will be hidden\n\n[/details]\n\n`,
+ `[details="Summary"]\nThis text will be hidden\n\n[/details]\n\n`,
],
],
"details without summary": [
[
`[details]This text will be hidden[/details]`,
- `<details><summary></summary><p>This text will be hidden</p></details>`,
+ `<details open="true"><summary></summary><p>This text will be hidden</p></details>`,
`[details]\nThis text will be hidden\n\n[/details]\n\n`,
],
],
@@ -37,7 +37,7 @@ module(
[
`[details open]This text will be hidden[/details]`,
`<details open="true"><summary></summary><p>This text will be hidden</p></details>`,
- `[details open]\nThis text will be hidden\n\n[/details]\n\n`,
+ `[details]\nThis text will be hidden\n\n[/details]\n\n`,
],
],
};
@@ -59,16 +59,16 @@ module(
const detailsCss = ".d-editor-input details";
const summaryCss = `${detailsCss} summary`;
- assert.dom(detailsCss).doesNotHaveAttribute("open");
+ assert.dom(detailsCss).hasAttribute("open");
await click(summaryCss);
- assert.dom(detailsCss).hasAttribute("open");
+ assert.dom(detailsCss).doesNotHaveAttribute("open");
// click elsewhere first to avoid a double-click being detected
await click(`${detailsCss} p`);
await click(summaryCss);
- assert.dom(detailsCss).doesNotHaveAttribute("open");
+ assert.dom(detailsCss).hasAttribute("open");
});
}
);