Skip to content

Commit b226f2f

Browse files
authored
Full-stack UI updates (Components node) 8.0 (#29972)
1 parent 943b63c commit b226f2f

25 files changed

+492
-249
lines changed

aspnetcore/blazor/components/built-in-components.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The following built-in Razor components are provided by the Blazor framework:
1616

1717
:::moniker range=">= aspnetcore-8.0"
1818

19+
<!-- UPDATE 8.0 Confirm/update list -->
20+
1921
* [`App`](xref:blazor/project-structure)
2022
* [`Authentication`](xref:blazor/security/webassembly/index#authentication-component)
2123
* [`AuthorizeView`](xref:blazor/security/index#authorizeview-component)

aspnetcore/blazor/components/cascading-values-and-parameters.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The following `ThemeInfo` C# class is placed in a folder named `UIThemeClasses`
5858

5959
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.
6060

61-
`Shared/MainLayout.razor`:
61+
`MainLayout.razor`:
6262

6363
:::moniker range=">= aspnetcore-7.0"
6464

@@ -90,7 +90,7 @@ To make use of cascading values, descendent components declare cascading paramet
9090

9191
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.
9292

93-
`Pages/ThemedCounter.razor`:
93+
`ThemedCounter.razor`:
9494

9595
:::moniker range=">= aspnetcore-7.0"
9696

@@ -120,7 +120,7 @@ The following component binds the `ThemeInfo` cascading value to a cascading par
120120

121121
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:
122122

123-
`Shared/MainLayout.razor`:
123+
`MainLayout.razor`:
124124

125125
```razor
126126
<main>
@@ -212,7 +212,7 @@ The following `TabSet` component maintains a set of tabs. The tab set's `Tab` co
212212

213213
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.
214214

215-
`Shared/TabSet.razor`:
215+
`TabSet.razor`:
216216

217217
```razor
218218
@using BlazorSample.UIInterfaces
@@ -258,7 +258,7 @@ Child `Tab` components aren't explicitly passed as parameters to the `TabSet`. I
258258

259259
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.
260260

261-
`Shared/Tab.razor`:
261+
`Tab.razor`:
262262

263263
```razor
264264
@using BlazorSample.UIInterfaces
@@ -297,7 +297,7 @@ Descendent `Tab` components capture the containing `TabSet` as a cascading param
297297

298298
The following `ExampleTabSet` component uses the `TabSet` component, which contains three `Tab` components.
299299

300-
`Pages/ExampleTabSet.razor`:
300+
`ExampleTabSet.razor`:
301301

302302
```razor
303303
@page "/example-tab-set"

aspnetcore/blazor/components/class-libraries.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If the **Support pages and views** checkbox is selected to support pages and vie
5555
</ItemGroup>
5656
```
5757

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.
5959

6060
:::moniker-end
6161

@@ -102,7 +102,7 @@ If the **Support pages and views** checkbox is selected to support pages and vie
102102
</ItemGroup>
103103
```
104104

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.
106106

107107
:::moniker-end
108108

@@ -148,7 +148,7 @@ If the `-s|--support-pages-and-views` option is used to support pages and views
148148
</ItemGroup>
149149
```
150150

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.
152152

153153
:::moniker-end
154154

@@ -188,7 +188,7 @@ In the following examples, `ComponentLibrary` is an RCL containing the `Componen
188188

189189
In the app that consumes the RCL, reference the `Component1` component using its namespace, as the following example shows.
190190

191-
`Pages/ConsumeComponent1.razor`:
191+
`ConsumeComponent1.razor`:
192192

193193
```razor
194194
@page "/consume-component-1"
@@ -200,7 +200,7 @@ In the app that consumes the RCL, reference the `Component1` component using its
200200

201201
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.
202202

203-
`Pages/ConsumeComponent2.razor`:
203+
`ConsumeComponent2.razor`:
204204

205205
```razor
206206
@page "/consume-component-2"
@@ -276,7 +276,7 @@ Add a component to the RCL that uses the `extra-style` class.
276276

277277
Add a page to the app that uses the `ExtraStyles` component from the RCL.
278278

279-
`Pages/ConsumeComponent3.razor`:
279+
`ConsumeComponent3.razor`:
280280

281281
```razor
282282
@page "/consume-component-3"
@@ -343,9 +343,7 @@ The following background image and stylesheet are used by the RCL's `Component1`
343343
}
344344
```
345345

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)):
349347

350348
```html
351349
<link href="_content/ComponentLibrary/styles.css" rel="stylesheet" />
@@ -384,7 +382,7 @@ Add the following `Jeep` component to the app that consumes the `ComponentLibrar
384382
* The Jeep YJ&reg; image from the `ComponentLibrary` RCL's `wwwroot` folder.
385383
* The `JeepYJ` component from the RCL.
386384

387-
`Pages/Jeep.razor`:
385+
`Jeep.razor`:
388386

389387
```razor
390388
@page "/jeep"
@@ -422,15 +420,15 @@ For more information, see <xref:razor-pages/ui-class#create-an-rcl-with-static-a
422420

423421
## Supply components and static assets to multiple hosted Blazor apps
424422

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>.
426424

427425
:::moniker range=">= aspnetcore-5.0"
428426

429-
## Browser compatibility analyzer for Blazor WebAssembly
427+
## Client-side browser compatibility analyzer
430428

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.
432430

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:
434432

435433
```xml
436434
<ItemGroup>

aspnetcore/blazor/components/control-head-content.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Specify `<head>` element content with the <xref:Microsoft.AspNetCore.Components.
2222

2323
The following example sets the page's title and description using Razor.
2424

25-
`Pages/ControlHeadContent.razor`:
25+
`ControlHeadContent.razor`:
2626

2727
:::moniker range=">= aspnetcore-7.0"
2828

@@ -42,7 +42,7 @@ The following example sets the page's title and description using Razor.
4242

4343
*This section applies to prerendered Blazor WebAssembly apps and Blazor Server apps.*
4444

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.**
4646

4747
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.
4848

@@ -103,7 +103,7 @@ In Blazor Server apps created from the Blazor Server project template, a [Compon
103103

104104
:::moniker-end
105105

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:
107107

108108
```csharp
109109
builder.RootComponents.Add<HeadOutlet>("head::after");

aspnetcore/blazor/components/css-isolation.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ To define component-specific styles, create a `.razor.css` file matching the nam
2727

2828
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.
2929

30-
`Pages/Example.razor`:
30+
`Example.razor`:
3131

3232
```razor
3333
@page "/example"
3434
3535
<h1>Scoped CSS Example</h1>
3636
```
3737

38-
`Pages/Example.razor.css`:
38+
`Example.razor.css`:
3939

4040
```css
4141
h1 {
@@ -72,7 +72,7 @@ Within the bundled file, each component is associated with a scope identifier. F
7272
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:
7373

7474
```css
75-
/* /Pages/Counter.razor.rz.scp.css */
75+
/* /Components/Pages/Counter.razor.rz.scp.css */
7676
h1[b-3xxtam6d07] {
7777
color: brown;
7878
}
@@ -90,7 +90,7 @@ By default, CSS isolation only applies to the component you associate with the f
9090

9191
The following example shows a parent component called `Parent` with a child component called `Child`.
9292

93-
`Pages/Parent.razor`:
93+
`Parent.razor`:
9494

9595
```razor
9696
@page "/parent"
@@ -102,15 +102,15 @@ The following example shows a parent component called `Parent` with a child comp
102102
</div>
103103
```
104104

105-
`Shared/Child.razor`:
105+
`Child.razor`:
106106

107107
```razor
108108
<h1>Child Component</h1>
109109
```
110110

111111
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.
112112

113-
`Pages/Parent.razor.css`:
113+
`Parent.razor.css`:
114114

115115
```css
116116
::deep h1 {
@@ -122,7 +122,7 @@ The `h1` style now applies to the `Parent` and `Child` components without the ne
122122

123123
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.
124124

125-
`Pages/Parent.razor`:
125+
`Parent.razor`:
126126

127127
```razor
128128
<div>
@@ -134,7 +134,7 @@ The `::deep` pseudo-element only works with descendant elements. The following m
134134

135135
However, excluding the `div` element removes the descendant relationship. In the following example, the style is **not** applied to the child component.
136136

137-
`Pages/Parent.razor`:
137+
`Parent.razor`:
138138

139139
```razor
140140
<h1>Parent</h1>
@@ -161,6 +161,39 @@ CSS isolation is designed to work out-of-the-box but provides configuration for
161161

162162
### Customize scope identifier format
163163

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:
167+
168+
```xml
169+
<ItemGroup>
170+
<None Update="Components/Pages/Example.razor.css" CssScope="custom-scope-identifier" />
171+
</ItemGroup>
172+
```
173+
174+
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.
177+
178+
```xml
179+
<ItemGroup>
180+
<None Update="Components/Pages/BaseComponent.razor.css" CssScope="custom-scope-identifier" />
181+
<None Update="Components/Pages/DerivedComponent.razor.css" CssScope="custom-scope-identifier" />
182+
</ItemGroup>
183+
```
184+
185+
Use the wildcard (`*`) operator to share scope identifiers across multiple files:
186+
187+
```xml
188+
<ItemGroup>
189+
<None Update="Components/Pages/*.razor.css" CssScope="custom-scope-identifier" />
190+
</ItemGroup>
191+
```
192+
193+
:::moniker-end
194+
195+
:::moniker range="< aspnetcore-8.0"
196+
164197
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:
165198

166199
```xml
@@ -188,6 +221,8 @@ Use the wildcard (`*`) operator to share scope identifiers across multiple files
188221
</ItemGroup>
189222
```
190223

224+
:::moniker-end
225+
191226
### Change base path for static web assets
192227

193228
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

Comments
 (0)