fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

imageFit.Contain changes picture size when setState is called only when browser window is certain sizes

Open dharnen opened this issue 7 years ago • 10 comments

Environment Information

  • Package version(s): SPFx 1.1.0 react 15.6.2 sp-ui-fabric-core 1.4.0 scaffold for SP onPrem 2016
  • Browser and OS versions: (fill this out if relevant)

Please provide a reproduction of the bug in a codepen:

Actual behavior:

When using the ui-fabric Image component and setting the imageFit to contain. An image placed into a div that is a larger size than the div will be contained correctly upon first render. If setState is invoked at any time after the first render, the picture will grow to its native size. Each time setState is called the picture toggles between the 2 sizes, even if the state being changed is not associated with the image in any way. The width and height is not being set in the Image tag but persists even when they are. Issue exists with and without custom css applied.

Expected behavior:

The setState function should have no effect on how the picture is being displayed. I realize that SPFx 1.1.0 is old so I'm not sure if this has been fixed in a newer version but if there is a know fix for this it would be nice to know.

Priorities and help requested:

Are you willing to submit a PR to fix? (Yes, No)

Requested priority: (Blocking, High, Normal, Low)

Products/sites affected: (if applicable)

dharnen avatar Feb 09 '19 05:02 dharnen

After looking in the issue deeper I was able to find the root cause. Each time the component is rendered a CoverStyle value is chosen (either .landscape or .portrait) which appends a class associated with it to the div causing the image to swap between sizes. Trying to set the CoverStyle in the props of the image, I get an error because CoverStyle doesn't exist on the IImageProps interface. I tried adding it myself but it had no affect. I have a temporary workaround which was to go into the Image.js file and changing the class being appended by using .portrait to the same as .landscape exports.CoverStyleMap = (_a = {}, _a[CoverStyle.landscape] = 'ms-Image-image--landscape', _a[CoverStyle.portrait] = 'ms-Image-image--landscape', _a);

Still looking for a better/more permanent solution.

dharnen avatar Feb 09 '19 07:02 dharnen

Can you check your node_modules/office-ui-fabric-react/package.json to see which version of OUFR you are on and place your examples in a CodePen? That'll help confirm the issue and whether or not it's been resolved.

JasonGore avatar Feb 11 '19 17:02 JasonGore

Hello Jason,

The package.json in the office-ui-fabric-react lists "version": "1.14.3" I'll work on getting an example in codepen.

dharnen avatar Feb 11 '19 18:02 dharnen

@JasonGore Okay so I've gotten a codepen started. Its just a simple div with an Image component in it that will change the picture when one of the buttons on the top is clicked. Please excuse my lack of experience, I haven't really used codepen much so I'm not sure how to pull in the correct version of the office-ui-fabric-react dependency. I have the imageFit property commented out because it causes the img to not render. I apologize for my lack of ability to reproduce the issue I'm seeing. I've included 2 css classes I'm using in my project on the Image component. The second class is commented out because the picture in the codepen renders differently than in my project. Here is my in work codepen If it helps I can include a few snipits of my project code along with screen shots.

Thank you for taking the time to respond to my post!

dharnen avatar Feb 11 '19 19:02 dharnen

I'm working behind the scenes to better understand SPFx scenarios, but the version of office-ui-fabric-react (OUFR) you reported is quite old. We're on v6 now and we consider v5 to be outdated. This is actually the first issue reported against v1 I've seen. 😄

In any case, I consider it a very high chance that the issue you're seeing was resolved some time ago, which is why you can't reproduce it in the codepen.

From what I've been able to gather so far, whatever version of OUFR you're using was specified by you and is under your control. I'd highly recommend switching to v6 and seeing if that helps you.

JasonGore avatar Feb 11 '19 19:02 JasonGore

Makes sense.... I'm pretty new to most of the SPFx world but really like everything it has to offer. That being said, I'm using this version of ui-fabric because that was what was installed using the yeoman generator for a SP OnPrem 2016 webpart. I guess I assumed that the version of ui-fabric I could use was limited because of the solution I am developing for. Not sure if you have any knowledge on what kind of restraints there might be? I'd love to use a version that isn't 2 years old haha

dharnen avatar Feb 11 '19 20:02 dharnen

I'm still trying to determine what your options are, but if you can try a newer version of OUFR in the meantime please let me know your findings. Thanks!

JasonGore avatar Feb 12 '19 01:02 JasonGore

Office UI Fabric React is committed to maintenance of the current release (6.x) and previous major release (5.x). This bug exists within version 1.x which falls outside of our support matrix, but does appear to have been fixed since v1. We recommend contacting your SharePoint support contacts for the on-prem license if you are unable to patch the bug within your instance.

JasonGore avatar Feb 12 '19 01:02 JasonGore

Gotcha. I'll see if updating my version is an option. I appreciate your quick response to my post and the guidance moving forward!

Drake

dharnen avatar Feb 12 '19 01:02 dharnen

This issue has been marked as being beyond the support scope of UI Fabric's issues board. It will now be closed automatically for house-keeping purposes.

msft-github-bot avatar Feb 13 '19 18:02 msft-github-bot