FIX: keep details open in preview (#26518)
when morphing is enabled, details elements in the preview will be kept open
This commit is contained in:
parent
eaeefb56fc
commit
377d2ca3ad
|
@ -460,7 +460,11 @@ export default Component.extend(TextareaTextManipulation, {
|
||||||
|
|
||||||
resolveCachedShortUrls(this.siteSettings, cookedElement);
|
resolveCachedShortUrls(this.siteSettings, cookedElement);
|
||||||
|
|
||||||
(await import("morphlex")).morph(previewElement, cookedElement);
|
(await import("morphlex")).morph(
|
||||||
|
previewElement,
|
||||||
|
cookedElement,
|
||||||
|
this.morphingOptions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule("afterRender", () => {
|
schedule("afterRender", () => {
|
||||||
|
@ -481,6 +485,13 @@ export default Component.extend(TextareaTextManipulation, {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
morphingOptions: {
|
||||||
|
beforeAttributeUpdated: (element, attributeName) => {
|
||||||
|
// Don't morph the open attribute of <details> elements
|
||||||
|
return !(element.tagName === "DETAILS" && attributeName === "open");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
@observes("ready", "value", "processPreview")
|
@observes("ready", "value", "processPreview")
|
||||||
async _watchForChanges() {
|
async _watchForChanges() {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "Composer Preview", type: :system do
|
||||||
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
||||||
|
let(:composer) { PageObjects::Components::Composer.new }
|
||||||
|
|
||||||
|
before { sign_in user }
|
||||||
|
|
||||||
|
it "keeps details element open when morphing content" do
|
||||||
|
SiteSetting.enable_diffhtml_preview = true
|
||||||
|
|
||||||
|
visit("/new-topic")
|
||||||
|
|
||||||
|
composer.type_content <<~MD
|
||||||
|
[details=Velcro]
|
||||||
|
What a rip-off!
|
||||||
|
[/details]
|
||||||
|
MD
|
||||||
|
|
||||||
|
within(composer.preview) do
|
||||||
|
find("details").click
|
||||||
|
expect(page).to have_css("details[open]")
|
||||||
|
end
|
||||||
|
|
||||||
|
composer.move_cursor_after("rip-off!")
|
||||||
|
composer.type_content(" :person_facepalming:")
|
||||||
|
|
||||||
|
within(composer.preview) { expect(page).to have_css("details[open] img.emoji") }
|
||||||
|
end
|
||||||
|
end
|
|
@ -219,6 +219,7 @@ module PageObjects
|
||||||
const index = composer.value.indexOf(text);
|
const index = composer.value.indexOf(text);
|
||||||
const position = index + text.length;
|
const position = index + text.length;
|
||||||
|
|
||||||
|
composer.focus();
|
||||||
composer.setSelectionRange(position, position);
|
composer.setSelectionRange(position, position);
|
||||||
JS
|
JS
|
||||||
end
|
end
|
||||||
|
@ -226,6 +227,7 @@ module PageObjects
|
||||||
def select_all
|
def select_all
|
||||||
execute_script(<<~JS, text)
|
execute_script(<<~JS, text)
|
||||||
const composer = document.querySelector("#{COMPOSER_ID} .d-editor-input");
|
const composer = document.querySelector("#{COMPOSER_ID} .d-editor-input");
|
||||||
|
composer.focus();
|
||||||
composer.setSelectionRange(0, composer.value.length);
|
composer.setSelectionRange(0, composer.value.length);
|
||||||
JS
|
JS
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue