You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/spfx/office-ui-fabric-integration.md
+60-46Lines changed: 60 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Using Office UI Fabric Core and Fabric React in SharePoint Framework
3
3
description: Information about the Fabric Core and Fabric React packages, and challenges with using CSS.
4
-
ms.date: 05/13/2019
4
+
ms.date: 02/09/2021
5
5
ms.prod: sharepoint
6
6
localization_priority: Priority
7
7
---
@@ -14,36 +14,38 @@ Microsoft uses Fabric Core and Fabric React in SharePoint. Microsoft regularly p
14
14
15
15
The challenge with Global CSS styles is explained in the following presentation within the context of React and JavaScript: [React CSS in JS](https://speakerdeck.com/vjeux/react-css-in-js).
16
16
17
-
To achieve reliability, one of the main problems we need to solve is that of **Global CSS styles**. This accounts to not using global class names in the HTML markup and instead using Fabric Core mixins and variables in the Sass declaration file. This involves importing the Fabric Core's Sass declarations in your Sass file and then consuming the variables and mixins appropriately.
17
+
To achieve reliability, one of the main problems we need to solve is that of **Global CSS styles**. This accounts to not using global class names in the HTML markup and instead using Fabric Core mixins and variables in the Sass declaration file. This involves importing the Fabric Core's Sass declarations in your Sass file and then consuming the variables and mixins appropriately.
18
18
19
19
## Goals
20
20
21
-
The goal of the SharePoint Framework is to allow both Microsoft and customers to build rich, beautiful, and consistent user experiences on top of SharePoint.
21
+
The goal of the SharePoint Framework is to allow both Microsoft and customers to build rich, beautiful, and consistent user experiences on top of SharePoint.
22
22
23
23
In accordance with these goals, following are the key design principles:
24
24
25
-
* Customers should be able to smoothly and reliably consume Fabric Core and Fabric React in their solutions.
26
-
* Microsoft will roll out updated experiences that consume updated versions of Fabric Core and Fabric React in SharePoint without conflicting with customer's solutions.
27
-
* Customers can customize and override the default styles, designs, and components to tailor the solution's needs.
25
+
- Customers should be able to smoothly and reliably consume Fabric Core and Fabric React in their solutions.
26
+
- Microsoft will roll out updated experiences that consume updated versions of Fabric Core and Fabric React in SharePoint without conflicting with customer's solutions.
27
+
- Customers can customize and override the default styles, designs, and components to tailor the solution's needs.
28
28
29
29
There are two parts of the Office UI Fabric that are available for use by developers:
30
30
31
-
*[Office UI Fabric Core](https://developer.microsoft.com/fabric). A set of core styles, typography, a responsive grid, animations, icons, and other fundamental building blocks of the overall design language.
31
+
-[Office UI Fabric Core](https://developer.microsoft.com/fabric). A set of core styles, typography, a responsive grid, animations, icons, and other fundamental building blocks of the overall design language.
32
32
33
-
*[Office UI Fabric React](https://developer.microsoft.com/fabric#/components). A set of React components built on top of the Fabric design language for use in React-based projects.
33
+
-[Office UI Fabric React](https://developer.microsoft.com/fabric#/components). A set of React components built on top of the Fabric design language for use in React-based projects.
34
34
35
35
## Office UI Fabric Core package
36
36
37
-
The SharePoint Framework Fabric Core npm package **([@microsoft/sp-office-ui-fabric-core](https://www.npmjs.com/package/@microsoft/sp-office-ui-fabric-core))** contains a subset of supported Fabric Core styles that can be safely consumed within a SharePoint Framework component.
37
+
The SharePoint Framework Fabric Core npm package **([@microsoft/sp-office-ui-fabric-core](https://www.npmjs.com/package/@microsoft/sp-office-ui-fabric-core))** contains a subset of supported Fabric Core styles that can be safely consumed within a SharePoint Framework component.
38
38
39
39
The following core styles are supported in the package:
40
+
40
41
- Typography
41
42
- Layouts
42
43
- Colors
43
44
- Themes
44
45
- Localization
45
46
46
47
The following are not yet supported in the package:
48
+
47
49
- Animations
48
50
- Icons
49
51
@@ -53,41 +55,39 @@ Starting with the SharePoint Framework Yeoman generator version 1.3.4, the defau
53
55
54
56
To use the Fabric Core package in your existing project, install the package as a dependency:
After it's installed, you can then import the Fabric Core Sass declarations in your Sass definition file and use the mixins and variables as described in the following section.
62
+
After it's installed, you can then import the Fabric Core Sass declarations in your Sass definition file and use the mixins and variables as described in the following section.
61
63
62
64
### Use Fabric Core styles
63
65
64
66
To use the Fabric Core styles, you need to import the `SPFabricCore` declarations into your Sass file.
65
67
66
-
> [!NOTE]
68
+
> [!NOTE]
67
69
> Make sure you have the **\@microsoft/sp-office-ui-fabric-core** npm package installed.
Now you can use the core styles as mixins and variables.
76
76
77
77
```css
78
78
.row {
79
-
@includems-Grid-row;
80
-
@includems-fontColor-white;
81
-
background-color: $ms-color-themeDark;
82
-
padding: 20px;
83
-
}
84
-
```
79
+
@includems-Grid-row;
80
+
@includems-fontColor-white;
81
+
background-color: $ms-color-themeDark;
82
+
padding: 20px;
83
+
}
84
+
```
85
85
86
86
## Office UI Fabric React
87
87
88
88
We recommend that you use the versions of the Office UI Fabric React package included in the project in the SharePoint Framework's Yeoman generator. For instance, the SharePoint Framework v1.7.0 release uses Fabric React v5.131.0
89
89
90
-
> [!NOTE]
90
+
> [!NOTE]
91
91
> Fabric React versions 2.x or older are not supported in SharePoint Framework.
92
92
93
93
After the Fabric React package is installed, you can import the required components from the Fabric React bundle.
@@ -110,7 +110,7 @@ The Fabric React package includes the supported Fabric Core styles used in the F
110
110
111
111
Because the **\@microsoft/sp-office-ui-fabric-core** package is already installed in your solution by the Yeoman generator, we recommend that you uninstall that package if you decide to use Fabric components and reduce your component bundle size.
@@ -124,29 +124,29 @@ You can then import the core styles from the Sass declarations available in the
124
124
125
125
Fabric components in your solution are locked to the specific version of Fabric React that you installed. You need to update the Fabric React package to get any new components if they are available in a newer package version. Because the Fabric components are included in the component bundle, it may increase the size of your component bundle. However, this approach is the only approach that is officially supported when Office UI Fabric React is being used in SharePoint Framework solutions.
126
126
127
-
128
127
## The CSS challenge with Office UI Fabric
129
128
130
-
The following concepts and references provide insights on the challenge with using Office UI Fabric in the context of client-side web parts.
129
+
The following concepts and references provide insights on the challenge with using Office UI Fabric in the context of client-side web parts.
131
130
132
131
### Global CSS styles
133
132
134
133
How to avoid Global CSS styles at all costs is a big problem. Today, both Fabric Core and Fabric React have global styles. A lack of any native solutions from the browser to manage the style scoping makes this a very difficult problem.
135
-
136
-
-[Scope CSS](https://developer.mozilla.org/docs/Web/CSS/:scope) is in early stages of discussion.
137
-
- iframes are not a good option to isolate styles.
138
-
-[Web Components](https://developer.mozilla.org/docs/Web/Web_Components) is another standard that talks about scoped styles but is still in the discussion stage.
139
-
-[The React: CSS in JS](https://speakerdeck.com/vjeux/react-css-in-js) discussion explains the problem well.
140
-
134
+
135
+
-[Scope CSS](https://developer.mozilla.org/docs/Web/CSS/:scope) is in early stages of discussion.
136
+
- iframes are not a good option to isolate styles.
137
+
-[Web Components](https://developer.mozilla.org/docs/Web/Web_Components) is another standard that talks about scoped styles but is still in the discussion stage.
138
+
-[The React: CSS in JS](https://speakerdeck.com/vjeux/react-css-in-js) discussion explains the problem well.
139
+
141
140
There is plenty of other documentation on the web about the solutions to the global namespace menace.
142
141
143
142
### CSS specificity
144
143
145
144
How [CSS specificity](https://developer.mozilla.org/docs/Web/CSS/Specificity) applies to web UI. Higher specificity styles override lower specificity styles, but the key thing to understand is how the specificity rules apply. In general, the precedence order from highest to lowest is as follows:
146
-
- The style attribute (for example, `style="background:red;"`)
147
-
- ID selectors (`#myDiv { }`)
148
-
- Class selectors (`.myCssClass{}`), attribute selectors (`[type="radio"]`), and pseudo-classes (`:hover`)
149
-
- Type selectors (`h1`)
145
+
146
+
- The style attribute (for example, `style="background:red;"`)
147
+
- ID selectors (`#myDiv { }`)
148
+
- Class selectors (`.myCssClass{}`), attribute selectors (`[type="radio"]`), and pseudo-classes (`:hover`)
149
+
- Type selectors (`h1`)
150
150
151
151
**Loading order**. If two classes are applied on an element and have the same specificity, the class that is loaded later takes precedence. As shown in the following code, the button appears red. If the order of the style tags is changed, the button appears green. This is an important concept, and if not used correctly, the user experience can become load order-dependent (that is, inconsistent).
152
152
@@ -176,7 +176,7 @@ The web part div would be assigned this scope, that is `<div data-sp-webpart cla
176
176
177
177
The rest of the page would contain unscoped Office UI Fabric Core styles. This way, as per CSS specificity rules, the scoped CSS would take precedence within the web part div. The web part and its contents would align to the specific version of the Office UI Fabric Core that the developer had chosen.
178
178
179
-
*Overriding* Fabric Core styles would not be supported.
179
+
*Overriding* Fabric Core styles would not be supported.
180
180
181
181
```javascript
182
182
// Sample of how the scoping would work.
@@ -203,7 +203,7 @@ After analyzing this strategy for a while, it was decided that the descendant se
203
203
204
204
#### Lack of reliable nesting support
205
205
206
-
This approach only works if the Microsoft user experience (that is, page and first-party web parts) use an unscoped version of the Office UI Fabric Core such as `ms-Icon--List`, while the third-party web parts only use scoped Office UI Fabric Core CSS as explained earlier.
206
+
This approach only works if the Microsoft user experience (that is, page and first-party web parts) use an unscoped version of the Office UI Fabric Core such as `ms-Icon--List`, while the third-party web parts only use scoped Office UI Fabric Core CSS as explained earlier.
207
207
208
208
The reason being that the specificity of the scoped CSS applied on the web part overrides the unscoped CSS on the page. Keep in mind, as explained earlier, that if CSS specificity of the two classes is the same, their loading order plays a role in how the CSS classes are applied. The class that loads later takes precedence. Hence, the higher specificity of the scoped CSS is important in getting a consistent experience.
209
209
@@ -218,8 +218,6 @@ Furthermore, multiple extensions, one contained in the other, cannot use differe
218
218
</div>
219
219
```
220
220
221
-
<br/>
222
-
223
221
Here's a more simplistic sample demonstrating the challenge:
224
222
225
223
```HTML
@@ -261,7 +259,7 @@ Here's a more simplistic sample demonstrating the challenge:
261
259
<br/>
262
260
<span>This test depicts that a descendant selector with the same specificity does not allow nesting.
263
261
All buttons below do not take the innermost scope (i.e. they should be different colors), but they are all red.
264
-
Further, if you change the ordering of the style tags, the colors will change. (i.e. theUI is load order dependant.)</span>
262
+
Further, if you change the ordering of the style tags, the colors will change. (i.e. theUI is load order dependant.)</span>
265
263
<div class='scope1'>
266
264
<button class='myButton'</button>
267
265
<div class='scope2'>
@@ -279,17 +277,33 @@ Here's a more simplistic sample demonstrating the challenge:
279
277
280
278
#### Leakage from unscoped classes
281
279
282
-
There is another problem with descendant selectors. Note in the previous example that the height and the width styles from the unscoped myButton class are applied to all the buttons. This implies that a change in that style could inadvertently break HTML by using scoped markup.
280
+
There is another problem with descendant selectors. Note in the previous example that the height and the width styles from the unscoped myButton class are applied to all the buttons. This implies that a change in that style could inadvertently break HTML by using scoped markup.
283
281
284
282
Say for example, for some reason at the app level we decide to make height 0 px on the myButton class. That results in all third-party web parts that use the myButton class to have a height of 0 px (that is, a serious regression in the user experience).
> The following guidance applies to SharePoint Framework >= 1.8.2
288
+
289
+
Ensure that the webpart manifest demands legacy Fabric core styles be loaded onto the page. This is done by specifying `loadLegacyFabricCss:true` in the solution manifest.
290
+
291
+
Prior to the release of SPFx v1.8.2, a host page bug was present where legacy Fabric core styles were loaded unscoped. Therefore, if another solution demanded the styles, then all other solutions on the page were able to use them. This led to solutions working "by chance" when not rendered in isolation.
292
+
293
+
To address this bug, the styles were scoped to `.ms-SPLegacyFabricBlock` class and applied to SPFx solutions that demand the Fabric core stylesheet be loaded. To provide a migration path for solutions reliant on the side-effect above, the `.ms-SPLegacyFabricBlock` class is applied to all `<div>`'s exposed to third-party solutions. During that time, modify the solution(s) impacted to declare the dependency on legacy Fabric core styles.
294
+
295
+
> [!IMPORTANT]
296
+
> Eventually the explicit reference to `.ms-SPLegacyFabricBlock` **will be removed** from the DOM for solutions that don't declare their dependency. This change will be broadly communicated via existing channels prior to removing this class.
297
+
298
+
In the event of a solution that is running in DOM elements that are not provided by the SPFx (*which is generally unsupported*), you'll need to apply the `.ms-SPLegacyFabricBlock` class yourself.
299
+
286
300
## Usage of the Office UI Fabric icons in SPFx components
287
301
288
-
There are changes on how to use Office UI Fabric icons in the rendering of the SharePoint Framework solutions starting from the SharePoint Framework version 1.8.2.
302
+
There are changes on how to use Office UI Fabric icons in the rendering of the SharePoint Framework solutions starting from the SharePoint Framework v1.8.2.
Copy file name to clipboardExpand all lines: docs/spfx/release-1.8.2.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: SharePoint Framework v1.8.2 release notes
3
3
description: Release notes for the SharePoint Framework v1.8.2 release
4
-
ms.date: 07/03/2020
4
+
ms.date: 02/09/2021
5
5
ms.prod: sharepoint
6
6
localization_priority: Priority
7
7
---
@@ -42,7 +42,8 @@ This is a minor patch release that mostly focuses on build and tooling issues, w
42
42
- For the React-scaffolded projects, we now explicitly add **office-ui-fabric-react** (OUIFR) v6 to **package.json**. We were finding a common pattern where people weren't adding OUIFR to **package.json**, but were using it.
43
43
- OUIFR would end up in the **node_modules** folder because of downstream dependencies. While the solution would compile, it could cause issues in the future such as when the solution was upgraded to use a different version of the framework. In this case, a different version of OUIFR would get used.
44
44
- In general, using packages in this pattern (*via shadow dependencies*) is a bad thing. You're more than welcome to remove the reference in **package.json** if you aren't using OUIFR in your solution, or change the version if needed. We also updated the type declarations for the React packages to match the versions of React / React DOM referenced in the release.
45
-
- Support for [Node.js 10](https://nodejs.org/). Node.js v8 is still supported, but will be removed in a future release.
45
+
- Added `.ms-SPLegacyFabricBlock` CSS class to SPFx solutions that load the Office UI Fabric core stylesheets on demand (*see [Safely use legacy Office UI Fabric Styles (after SPFx v1.8.2)](office-ui-fabric-integration.md#safely-use-legacy-office-ui-fabric-styles-after-spfx-v182) for more detail*)
46
+
- Support for [Node.js 10](https://nodejs.org/). Node.js v8 is still supported, but will be removed in a future release.
0 commit comments