Skip to content

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

UX: avoid small viewport squishing rich editor image (#33567)

Renato Atiliofa1ec71526f8
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/components/image-node-view.gjs b/app/assets/javascripts/discourse/app/static/prosemirror/components/image-node-view.gjs
index 3cd7ec05c73..3eca9748fe3 100644
--- a/app/assets/javascripts/discourse/app/static/prosemirror/components/image-node-view.gjs
+++ b/app/assets/javascripts/discourse/app/static/prosemirror/components/image-node-view.gjs
@@ -271,23 +271,14 @@ export default class ImageNodeView extends Component {
}
get imageStyle() {
- let width = this.args.node.attrs.width;
- let height = this.args.node.attrs.height;
-
- if (!width || !height) {
- const dimensions = this.maxDimensions;
-
- if (!dimensions) {
- return null;
- }
-
- width = dimensions.width;
- height = dimensions.height;
+ const width = this.args.node.attrs.width ?? this.maxDimensions?.width;
+ if (!width) {
+ return null;
}
const scale = (this.args.node.attrs.scale || 100) / 100;
- return htmlSafe(`width: ${width * scale}px; height: ${height * scale}px;`);
+ return htmlSafe(`width: ${width * scale}px`);
}
@action
diff --git a/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/image-test.js b/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/image-test.js
index d2fbfcfa87a..ef3420d6649 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/image-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/image-test.js
@@ -74,11 +74,6 @@ module(
"50px",
"Image width style should be 50px"
);
- assert.strictEqual(
- img.style.height,
- "100px",
- "Image height style should be 100px"
- );
}
)
);
@@ -105,11 +100,6 @@ module(
"50px",
"Image width style should be 50px"
);
- assert.strictEqual(
- img.style.height,
- "100px",
- "Image height style should be 100px"
- );
}
)
);
diff --git a/app/assets/stylesheets/common/rich-editor/rich-editor.scss b/app/assets/stylesheets/common/rich-editor/rich-editor.scss
index 5fe036c2b78..7606b31cbcc 100644
--- a/app/assets/stylesheets/common/rich-editor/rich-editor.scss
+++ b/app/assets/stylesheets/common/rich-editor/rich-editor.scss
@@ -49,31 +49,20 @@
font-size: var(--font-up-1-rem);
}
- img {
- display: inline-block;
- height: auto;
- max-width: 100%;
- border-radius: var(--d-border-radius);
-
- &.emoji {
- border-radius: 0;
- }
+ img[data-placeholder="true"] {
+ animation: placeholder 1.5s infinite;
- &[data-placeholder="true"] {
- animation: placeholder 1.5s infinite;
-
- @keyframes placeholder {
- 0% {
- opacity: 0.6;
- }
+ @keyframes placeholder {
+ 0% {
+ opacity: 0.6;
+ }
- 50% {
- opacity: 0.4;
- }
+ 50% {
+ opacity: 0.4;
+ }
- 100% {
- opacity: 0.6;
- }
+ 100% {
+ opacity: 0.6;
}
}
}
@@ -315,6 +304,10 @@
padding: 2px 1px;
img {
+ display: inline-block;
+ height: auto;
+ max-width: 100%;
+ border-radius: var(--d-border-radius);
transition:
width 0.2s ease,
height 0.2s ease;