fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Dialog containerClassName does not work due to async css loading

Open rickyp-ms opened this issue 9 years ago • 2 comments

I'm having a seriously hard time overriding some css in the Dialog class

Basically, the dialog from fabric takes up the least amount of space it needs. We would prefer it to take up 50% of the screen at max. To do this I've created a css class and added it to the dialog like so:

<Dialog
   isBlocking={ false }
   isOpen={ true }
   title={ dialogTitle }
   subText={ dialogDescription }
   type={ FabricDialogType.close }
   onDismiss={ this.dialogActionCreator.close.bind(this.dialogActionCreator) }
   className={ themeClass }
   containerClassName={ "plannerAppDialog" }
   >

At the top of the file I've added the following code to load the Dialog component along with my customized css

import { Dialog, DialogType as FabricDialogType } from "office-ui-fabric-react/lib/components/Dialog/index";
import './PlannerAppDialog.css';

And this gets compiled out to the following

<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="office-ui-fabric-react/lib/components/Dialog/index" src="./office-ui-fabric-react/lib/components/Dialog/index.js"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="planner/controls/smart/plannerApp/PlannerAppDialog.css" src="./planner/controls/smart/plannerApp/PlannerAppDialog.css.js"></script>

The issue is when it gets executed, the order of the style tags get switched and .ms-dialog comes after the customizations meaning the custom class will never win.

<style type="text/css">.plannerAppDialog{width:50%;max-width:50%}</style>
<style type="text/css">.ms-dialog {...}</style>

Any advice on how to resolve this issue?

rickyp-ms avatar Jan 18 '17 00:01 rickyp-ms

Have you tried making your selectors more specific?

.ms-Dialog.plannerAppDialog

is more specific than:

.plannerAppDialog

dzearing avatar Jan 18 '17 02:01 dzearing

It didn't occur to me to increase the specificity ranking of the selector (I've never had to personally use it)! Thanks!

Documentation: http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascade http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#specificity

rickyp-ms avatar Jan 18 '17 22:01 rickyp-ms