Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

width style from <img> overrides the style on resized <figure> #17441

Open
Mgsy opened this issue Nov 12, 2024 · 1 comment · May be fixed by #17460
Open

width style from <img> overrides the style on resized <figure> #17441

Mgsy opened this issue Nov 12, 2024 · 1 comment · May be fixed by #17460
Assignees
Labels
package:image support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@Mgsy
Copy link
Member

Mgsy commented Nov 12, 2024

📝 Provide detailed reproduction steps (if any)

  1. Go to https://ckeditor.com/docs/ckeditor5/latest/examples/builds-custom/full-featured-editor.html.
  2. Open source editing
  3. Use the following source:
<figure style="clear: both;margin: 0.9em auto;min-width: 50px;text-align: center;box-sizing: border-box;display: block;max-width: 100%;width: 5.15%;"class="image image_resized">
 <img height="233" width="258" src="https://www.shutterstock.com/image-vector/sample-red-square-grunge-stamp-260nw-338250266.jpg" style="display: block;height: auto;margin: 0px auto;max-width: 100%;min-width: 100%;width: 100%;aspect-ratio: 258/233;" />
</figure>
  1. View the source again.

✔️ Expected result

<figure> preserves the width: 5.15% style.

❌ Actual result

<figure> inherits width: 100% from <img>.


If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@Mgsy Mgsy added support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior. labels Nov 12, 2024
@Mati365 Mati365 self-assigned this Nov 13, 2024
@Mati365
Copy link
Member

Mati365 commented Nov 14, 2024

Adding such upcast seems to bypass the issue:

editor.conversion.for( 'upcast' ).add( dispatcher => {
	dispatcher.on( 'element:figure', ( evt, data, conversionApi ) => {
		const viewFigure = data.viewItem;
		const viewImg = imageUtils.findViewImgElement( viewFigure );

		if ( !viewImg || !viewImg.getStyle( 'width' ) || !imageUtils.isBlockImageView( viewFigure ) ) {
			return;
		}

		const figureWidth = viewFigure.getStyle( 'width' );

		if ( figureWidth ) {
			conversionApi.writer.setAttribute( 'resizedWidth', figureWidth, data.modelRange.start.nodeAfter );
		}
	}, { priority: 'low' } );
} );

But I'm not sure if it's optimal solution. We need to dig more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:image support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants