Originally for v8, our IE11 plan was to use a polyfill for supporting CSS variables. Initial testing (with internal fixes) with static css files showed it working well. However after more testing, and afterswitching to using dynamically created styles, and updating to the latest version, numerous problems have been revealed.
::before
and ::after
pseudo selectors.So, we will use an alternative approach:
We will provide a way to "inject" an IE11-specific implementation to makeVariantClasses. This version will on-the-fly replace variable values with resolved variables, allowing us to leverage
There are two ways we can allow the polyfill to be injected: global state and context. Global state is better for browser scenarios, because we can avoid any risk of impacting bundle size. Context is better for encapsulation, but risks penalizing bundle size if async imports aren't leveraged.
Through global state:
App developers should inject the Fluent UI polyfills script:
This will place a an alternative implementation of makeVariantClasses
on the window.__fui__overrides
global, which the utility will use as an alternative implementation for resolving classes. This ensures that non-ie11 users will be unaffected in runtime performance and bundle size, while IE11 will still enable variants work to ship.
For more details on polyfill work, see issue:
https://github.com/microsoft/fluentui/issues/15591
f
makeVariantClasses
take in as input styles (css rules) and variants (tokens):
We produce the following:
Using css variables, the primary class can be 1 single class which defines many values. Those values can be referenced from within any selector, which in turn can target any sub element in the component.
In IE11, because we don't have variables support, we will need to re-evaluate the styles not just on unique window/theme/direction, but also each unique variant permutation we encounter.
Pre-requisites:
Instead of this:
This:
processVariants
.primary
is variant; is state.primary
truthy, or does state.variant
equal primary
?)styles
and replace var(...)
matches with values from the list. Take fallbacks into consideration.https://codesandbox.io/s/replace-css-variables-x6v4q?file=/src/replaceCSSVariables.ts
replaceCSSVariables(inputCSS, variableMap)
replaces variable values in the input css with the values defined in the map.
resolveCSSVariableValue(value, variableMap
returns the css property value based on if the value contains var(...)
references, and if thos values are available in the given map.