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: aspnetcore/blazor/components/cascading-values-and-parameters.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ The following `ThemeInfo` C# class is placed in a folder named `UIThemeClasses`
58
58
59
59
The following [layout component](xref:blazor/components/layouts) specifies theme information (`ThemeInfo`) as a cascading value for all components that make up the layout body of the <xref:Microsoft.AspNetCore.Components.LayoutComponentBase.Body> property. `ButtonClass` is assigned a value of [`btn-success`](https://getbootstrap.com/docs/5.0/components/buttons/), which is a Bootstrap button style. Any descendent component in the component hierarchy can use the `ButtonClass` property through the `ThemeInfo` cascading value.
60
60
61
-
`Shared/MainLayout.razor`:
61
+
`MainLayout.razor`:
62
62
63
63
:::moniker range=">= aspnetcore-7.0"
64
64
@@ -90,7 +90,7 @@ To make use of cascading values, descendent components declare cascading paramet
90
90
91
91
The following component binds the `ThemeInfo` cascading value to a cascading parameter, optionally using the same name of `ThemeInfo`. The parameter is used to set the CSS class for the **`Increment Counter (Themed)`** button.
92
92
93
-
`Pages/ThemedCounter.razor`:
93
+
`ThemedCounter.razor`:
94
94
95
95
:::moniker range=">= aspnetcore-7.0"
96
96
@@ -120,7 +120,7 @@ The following component binds the `ThemeInfo` cascading value to a cascading par
120
120
121
121
Similar to a regular component parameter, components accepting a cascading parameter are rerendered when the cascading value is changed. For instance, configuring a different theme instance causes the `ThemedCounter` component from the [`CascadingValue` component](#cascadingvalue-component) section to rerender:
122
122
123
-
`Shared/MainLayout.razor`:
123
+
`MainLayout.razor`:
124
124
125
125
```razor
126
126
<main>
@@ -212,7 +212,7 @@ The following `TabSet` component maintains a set of tabs. The tab set's `Tab` co
212
212
213
213
Child `Tab` components aren't explicitly passed as parameters to the `TabSet`. Instead, the child `Tab` components are part of the child content of the `TabSet`. However, the `TabSet` still needs a reference each `Tab` component so that it can render the headers and the active tab. To enable this coordination without requiring additional code, the `TabSet` component *can provide itself as a cascading value* that is then picked up by the descendent `Tab` components.
214
214
215
-
`Shared/TabSet.razor`:
215
+
`TabSet.razor`:
216
216
217
217
```razor
218
218
@using BlazorSample.UIInterfaces
@@ -258,7 +258,7 @@ Child `Tab` components aren't explicitly passed as parameters to the `TabSet`. I
258
258
259
259
Descendent `Tab` components capture the containing `TabSet` as a cascading parameter. The `Tab` components add themselves to the `TabSet` and coordinate to set the active tab.
260
260
261
-
`Shared/Tab.razor`:
261
+
`Tab.razor`:
262
262
263
263
```razor
264
264
@using BlazorSample.UIInterfaces
@@ -297,7 +297,7 @@ Descendent `Tab` components capture the containing `TabSet` as a cascading param
297
297
298
298
The following `ExampleTabSet` component uses the `TabSet` component, which contains three `Tab` components.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/class-libraries.md
+12-14Lines changed: 12 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ If the **Support pages and views** checkbox is selected to support pages and vie
55
55
</ItemGroup>
56
56
```
57
57
58
-
For more information on the `SupportedPlatform` item, see the [Browser compatibility analyzer for Blazor WebAssembly](#browser-compatibility-analyzer-for-blazor-webassembly) section.
58
+
For more information on the `SupportedPlatform` item, see the [client-side browser compatibility analyzer](#client-side-browser-compatibility-analyzer) section.
59
59
60
60
:::moniker-end
61
61
@@ -102,7 +102,7 @@ If the **Support pages and views** checkbox is selected to support pages and vie
102
102
</ItemGroup>
103
103
```
104
104
105
-
For more information on the `SupportedPlatform` item, see the [Browser compatibility analyzer for Blazor WebAssembly](#browser-compatibility-analyzer-for-blazor-webassembly) section.
105
+
For more information on the `SupportedPlatform` item, see the [client-side browser compatibility analyzer](#client-side-browser-compatibility-analyzer) section.
106
106
107
107
:::moniker-end
108
108
@@ -148,7 +148,7 @@ If the `-s|--support-pages-and-views` option is used to support pages and views
148
148
</ItemGroup>
149
149
```
150
150
151
-
For more information on the `SupportedPlatform` item, see the [Browser compatibility analyzer for Blazor WebAssembly](#browser-compatibility-analyzer-for-blazor-webassembly) section.
151
+
For more information on the `SupportedPlatform` item, see the [client-side browser compatibility analyzer](#client-side-browser-compatibility-analyzer) section.
152
152
153
153
:::moniker-end
154
154
@@ -188,7 +188,7 @@ In the following examples, `ComponentLibrary` is an RCL containing the `Componen
188
188
189
189
In the app that consumes the RCL, reference the `Component1` component using its namespace, as the following example shows.
190
190
191
-
`Pages/ConsumeComponent1.razor`:
191
+
`ConsumeComponent1.razor`:
192
192
193
193
```razor
194
194
@page "/consume-component-1"
@@ -200,7 +200,7 @@ In the app that consumes the RCL, reference the `Component1` component using its
200
200
201
201
Alternatively, add a [`@using`](xref:mvc/views/razor#using) directive and use the component without its namespace. The following `@using` directive can also appear in any `_Imports.razor` file in or above the current folder.
202
202
203
-
`Pages/ConsumeComponent2.razor`:
203
+
`ConsumeComponent2.razor`:
204
204
205
205
```razor
206
206
@page "/consume-component-2"
@@ -276,7 +276,7 @@ Add a component to the RCL that uses the `extra-style` class.
276
276
277
277
Add a page to the app that uses the `ExtraStyles` component from the RCL.
278
278
279
-
`Pages/ConsumeComponent3.razor`:
279
+
`ConsumeComponent3.razor`:
280
280
281
281
```razor
282
282
@page "/consume-component-3"
@@ -343,9 +343,7 @@ The following background image and stylesheet are used by the RCL's `Component1`
343
343
}
344
344
```
345
345
346
-
To provide `Component1`'s `my-component` CSS class, link to the library's stylesheet in the app's `<head>` markup.
347
-
348
-
`wwwroot/index.html` file (Blazor WebAssembly) or `Pages/_Host.cshtml` file (Blazor Server):
346
+
To provide `Component1`'s `my-component` CSS class, link to the library's stylesheet in the app's `<head>` markup ([location of `<head>` content](xref:blazor/project-structure#location-of-head-content)):
@@ -384,7 +382,7 @@ Add the following `Jeep` component to the app that consumes the `ComponentLibrar
384
382
* The Jeep YJ® image from the `ComponentLibrary` RCL's `wwwroot` folder.
385
383
* The `JeepYJ` component from the RCL.
386
384
387
-
`Pages/Jeep.razor`:
385
+
`Jeep.razor`:
388
386
389
387
```razor
390
388
@page "/jeep"
@@ -422,15 +420,15 @@ For more information, see <xref:razor-pages/ui-class#create-an-rcl-with-static-a
422
420
423
421
## Supply components and static assets to multiple hosted Blazor apps
424
422
425
-
For more information, see <xref:blazor/host-and-deploy/webassembly#static-assets-and-class-libraries-for-multiple-blazor-webassembly-apps>.
423
+
For more information, see <xref:blazor/host-and-deploy/multiple-hosted-webassembly>.
426
424
427
425
:::moniker range=">= aspnetcore-5.0"
428
426
429
-
## Browser compatibility analyzer for Blazor WebAssembly
427
+
## Client-side browser compatibility analyzer
430
428
431
-
Blazor WebAssembly apps target the full .NET API surface area, but not all .NET APIs are supported on WebAssembly due to browser sandbox constraints. Unsupported APIs throw <xref:System.PlatformNotSupportedException> when running on WebAssembly. A platform compatibility analyzer warns the developer when the app uses APIs that aren't supported by the app's target platforms. For Blazor WebAssembly apps, this means checking that APIs are supported in browsers. Annotating .NET framework APIs for the compatibility analyzer is an on-going process, so not all .NET framework API is currently annotated.
429
+
Client-side apps target the full .NET API surface area, but not all .NET APIs are supported on WebAssembly due to browser sandbox constraints. Unsupported APIs throw <xref:System.PlatformNotSupportedException> when running on WebAssembly. A platform compatibility analyzer warns the developer when the app uses APIs that aren't supported by the app's target platforms. For client-side apps, this means checking that APIs are supported in browsers. Annotating .NET framework APIs for the compatibility analyzer is an on-going process, so not all .NET framework API is currently annotated.
432
430
433
-
Blazor WebAssembly and RCL projects *automatically* enable browser compatibility checks by adding `browser` as a supported platform with the `SupportedPlatform` MSBuild item. Library developers can manually add the `SupportedPlatform` item to a library's project file to enable the feature:
431
+
Blazor Web Apps that enable interactive WebAssembly components, Blazor WebAssembly apps, and RCL projects *automatically* enable browser compatibility checks by adding `browser` as a supported platform with the `SupportedPlatform` MSBuild item. Library developers can manually add the `SupportedPlatform` item to a library's project file to enable the feature:
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/control-head-content.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Specify `<head>` element content with the <xref:Microsoft.AspNetCore.Components.
22
22
23
23
The following example sets the page's title and description using Razor.
24
24
25
-
`Pages/ControlHeadContent.razor`:
25
+
`ControlHeadContent.razor`:
26
26
27
27
:::moniker range=">= aspnetcore-7.0"
28
28
@@ -42,7 +42,7 @@ The following example sets the page's title and description using Razor.
42
42
43
43
*This section applies to prerendered Blazor WebAssembly apps and Blazor Server apps.*
44
44
45
-
When [Razor components are prerendered](xref:blazor/components/prerendering-and-integration), the use of a layout page (`_Layout.cshtml`) is required to control `<head>` content with the <xref:Microsoft.AspNetCore.Components.Web.PageTitle> and <xref:Microsoft.AspNetCore.Components.Web.HeadContent> components. The reason for this requirement is that components that control `<head>` content must be rendered before the layout with the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component. **This order of rendering is required to control head content.**
45
+
When Razor components are prerendered, the use of a layout page (`_Layout.cshtml`) is required to control `<head>` content with the <xref:Microsoft.AspNetCore.Components.Web.PageTitle> and <xref:Microsoft.AspNetCore.Components.Web.HeadContent> components. The reason for this requirement is that components that control `<head>` content must be rendered before the layout with the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component. **This order of rendering is required to control head content.**
46
46
47
47
If the shared `_Layout.cshtml` file doesn't have a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) for a <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component, add it to the `<head>` elements.
48
48
@@ -103,7 +103,7 @@ In Blazor Server apps created from the Blazor Server project template, a [Compon
103
103
104
104
:::moniker-end
105
105
106
-
In an app created from the Blazor WebAssembly project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component is added to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> collection of the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder> in `Program.cs`:
106
+
In an app created from the Blazor WebAssembly project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component is added to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> collection of the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder> in the client-side `Program` file:
Copy file name to clipboardExpand all lines: aspnetcore/blazor/components/css-isolation.md
+43-8Lines changed: 43 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -27,15 +27,15 @@ To define component-specific styles, create a `.razor.css` file matching the nam
27
27
28
28
For an `Example` component in an `Example.razor` file, create a file alongside the component named `Example.razor.css`. The `Example.razor.css` file must reside in the same folder as the `Example` component (`Example.razor`). The "`Example`" base name of the file is **not** case-sensitive.
29
29
30
-
`Pages/Example.razor`:
30
+
`Example.razor`:
31
31
32
32
```razor
33
33
@page "/example"
34
34
35
35
<h1>Scoped CSS Example</h1>
36
36
```
37
37
38
-
`Pages/Example.razor.css`:
38
+
`Example.razor.css`:
39
39
40
40
```css
41
41
h1 {
@@ -72,7 +72,7 @@ Within the bundled file, each component is associated with a scope identifier. F
72
72
The `{ASSEMBLY NAME}.styles.css` file uses the scope identifier to group a style declaration with its component. The following example provides the style for the preceding `<h1>` element:
73
73
74
74
```css
75
-
/* /Pages/Counter.razor.rz.scp.css */
75
+
/* /Components/Pages/Counter.razor.rz.scp.css */
76
76
h1[b-3xxtam6d07] {
77
77
color: brown;
78
78
}
@@ -90,7 +90,7 @@ By default, CSS isolation only applies to the component you associate with the f
90
90
91
91
The following example shows a parent component called `Parent` with a child component called `Child`.
92
92
93
-
`Pages/Parent.razor`:
93
+
`Parent.razor`:
94
94
95
95
```razor
96
96
@page "/parent"
@@ -102,15 +102,15 @@ The following example shows a parent component called `Parent` with a child comp
102
102
</div>
103
103
```
104
104
105
-
`Shared/Child.razor`:
105
+
`Child.razor`:
106
106
107
107
```razor
108
108
<h1>Child Component</h1>
109
109
```
110
110
111
111
Update the `h1` declaration in `Parent.razor.css` with the `::deep` pseudo-element to signify the `h1` style declaration must apply to the parent component and its children.
112
112
113
-
`Pages/Parent.razor.css`:
113
+
`Parent.razor.css`:
114
114
115
115
```css
116
116
::deep h1 {
@@ -122,7 +122,7 @@ The `h1` style now applies to the `Parent` and `Child` components without the ne
122
122
123
123
The `::deep` pseudo-element only works with descendant elements. The following markup applies the `h1` styles to components as expected. The parent component's scope identifier is applied to the `div` element, so the browser knows to inherit styles from the parent component.
124
124
125
-
`Pages/Parent.razor`:
125
+
`Parent.razor`:
126
126
127
127
```razor
128
128
<div>
@@ -134,7 +134,7 @@ The `::deep` pseudo-element only works with descendant elements. The following m
134
134
135
135
However, excluding the `div` element removes the descendant relationship. In the following example, the style is **not** applied to the child component.
136
136
137
-
`Pages/Parent.razor`:
137
+
`Parent.razor`:
138
138
139
139
```razor
140
140
<h1>Parent</h1>
@@ -161,6 +161,39 @@ CSS isolation is designed to work out-of-the-box but provides configuration for
161
161
162
162
### Customize scope identifier format
163
163
164
+
:::moniker range=">= aspnetcore-8.0"
165
+
166
+
By default, scope identifiers use the format `b-{STRING}`, where the `{STRING}` placeholder is a ten-character string generated by the framework. To customize the scope identifier format, update the project file to a desired pattern:
In the preceding example, the CSS generated for `Example.razor.css` changes its scope identifier from `b-{STRING}` to `custom-scope-identifier`.
175
+
176
+
Use scope identifiers to achieve inheritance with scoped CSS files. In the following project file example, a `BaseComponent.razor.css` file contains common styles across components. A `DerivedComponent.razor.css` file inherits these styles.
By default, scope identifiers use the format `b-{STRING}`, where the `{STRING}` placeholder is a ten-character string generated by the framework. To customize the scope identifier format, update the project file to a desired pattern:
165
198
166
199
```xml
@@ -188,6 +221,8 @@ Use the wildcard (`*`) operator to share scope identifiers across multiple files
188
221
</ItemGroup>
189
222
```
190
223
224
+
:::moniker-end
225
+
191
226
### Change base path for static web assets
192
227
193
228
The `scoped.styles.css` file is generated at the root of the app. In the project file, use the [`<StaticWebAssetBasePath>` property](xref:blazor/fundamentals/static-files#static-web-asset-base-path) to change the default path. The following example places the `scoped.styles.css` file, and the rest of the app's assets, at the `_content` path:
0 commit comments