Skip to content

Add new Icon parameters to BitNavBar (#12111)#12112

Merged
msynk merged 2 commits intobitfoundation:developfrom
msynk:12111-blazorui-navbar-new-icons
Feb 22, 2026
Merged

Add new Icon parameters to BitNavBar (#12111)#12112
msynk merged 2 commits intobitfoundation:developfrom
msynk:12111-blazorui-navbar-new-icons

Conversation

@msynk
Copy link
Copy Markdown
Member

@msynk msynk commented Feb 22, 2026

closes #12111

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for external icon libraries in NavBar components through a new Icon property
    • NavBar icons can now be sourced from third-party libraries like Font Awesome in addition to built-in icons
    • Structured icon definitions allow customization of icon rendering across components
    • Added demo examples showing Font Awesome integration and icon configuration patterns

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 22, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The pull request adds support for external icon libraries in the BitNavBar component by introducing a new Icon property of type BitIconInfo? to BitNavBarItem, BitNavBarOption, and their corresponding name selectors. The component's rendering logic is updated to resolve icons via a new helper method, and demo files are refactored to showcase external icon usage alongside built-in icons.

Changes

Cohort / File(s) Summary
Core Icon Support
src/BlazorUI/Bit.BlazorUI/Components/Navs/NavBar/BitNavBar.razor, BitNavBar.razor.cs, BitNavBarItem.cs, BitNavBarOption.cs, BitNavBarNameSelectors.cs
Added new Icon property of type BitIconInfo? to BitNavBarItem and BitNavBarOption. Updated BitNavBar component to render icons via new GetIcon() helper method that resolves icon from item or selector. Changed NameSelectors parameter type from BitNavNameSelectors<TItem>? to BitNavBarNameSelectors<TItem>?. Added Icon selector pair to BitNavBarNameSelectors for external icon mapping.
Demo Infrastructure
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/BitNavBarDemo.razor.cs
Extended documentation structure with new BitIconInfo manifest entry and updated BitNavBarItem/BitNavBarOption public API signatures to reflect new Icon property.
MenuItem Model
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/MenuItem.cs
Replaced Icon property with ImageName (string\?) and Image (BitIconInfo\?) to distinguish between built-in icon names and external icon definitions.
Custom Demo
_BitNavBarCustomDemo.razor, _BitNavBarCustomDemo.razor.cs, _BitNavBarCustomDemo.razor.samples.cs
Updated all MenuItem initializations to use ImageName instead of Icon. Added new externalIconCustoms collection with BitIconInfo entries. Updated NameSelectors to reference ImageName for built-in icons and introduced external icon demo block with Font Awesome integration.
Item Demo
_BitNavBarItemDemo.razor, _BitNavBarItemDemo.razor.cs, _BitNavBarItemDemo.razor.samples.cs
Added new "External Icons" demo block before "Style & Class" section. Introduced externalIconItems collection with custom Icon definitions. Reorganized example numbering (example12 now External Icons, example13-14 shifted accordingly). Added Font Awesome stylesheet reference.
Option Demo
_BitNavBarOptionDemo.razor, _BitNavBarOptionDemo.razor.samples.cs
Restructured demo blocks: renamed example12 to "External Icons", introduced new example13 for "Style & Class", moved RTL demo to example14. Added Font Awesome integration for external icon demonstration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A NavBar so fine, now with icons from afar,
External libraries dance, no need for just one jar,
BitIconInfo brings the light, to customize each bar,
The demo hops with Font Awesome, shining like a star!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add new Icon parameters to BitNavBar' clearly and accurately summarizes the main changes across the pull request, which introduce Icon support throughout the NavBar component.
Linked Issues check ✅ Passed The PR successfully implements the objective from #12111 by adding new Icon parameters to BitNavBar, BitNavBarItem, BitNavBarOption, and BitNavBarNameSelectors to enable external icon usage.
Out of Scope Changes check ✅ Passed While the PR includes demo updates and MenuItem property changes (Icon→ImageName/Image), these are necessary refactoring to utilize the new Icon feature and demonstrate its usage in examples.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (4)
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor (1)

389-389: <link> in component body — prefer <HeadContent> in Blazor.

Placing <link rel="stylesheet"> inline in the component body renders the tag into the <body> at the component's location. Blazor provides the <HeadContent> component specifically for injecting <head> content from a component. Using it ensures the stylesheet loads correctly regardless of the rendering model (SSR, WASM, hybrid) and avoids duplicate loads on re-renders.

♻️ Proposed fix
-    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
-
-    <div class="container">
+    <HeadContent>
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
+    </HeadContent>
+    <div class="container">
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor`
at line 389, Move the inline <link rel="stylesheet"> out of the component body
and place it inside a Blazor <HeadContent> block in _BitNavBarOptionDemo.razor
so the Font Awesome stylesheet is injected into the document head (ensuring
correct behavior for SSR/WASM/hybrid and avoiding duplicates); locate the
existing <link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"
/> in the component markup and wrap it with <HeadContent>...</HeadContent> (or
add a single shared HeadContent section if one already exists) so the stylesheet
is added to the head instead of rendered into the body.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/MenuItem.cs (1)

6-7: Minor naming inconsistency: Image vs Icon for BitIconInfo?.

The library uses Icon (BitIconInfo?) in BitNavBarItem and BitNavBarOption, but the demo model calls the equivalent property Image. While demo-only, this divergence could confuse readers comparing the MenuItem-based custom demo against the standard API. Consider renaming ImageIcon and ImageNameIconName to stay aligned with library naming, if there are no naming conflicts with the NameSelectors configuration.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/MenuItem.cs`
around lines 6 - 7, The demo model MenuItem has inconsistent property names
Image and ImageName for a BitIconInfo?, which diverges from the library usage of
Icon/IconName in BitNavBarItem and BitNavBarOption; rename Image → Icon and
ImageName → IconName in the MenuItem class and update any references/usages to
those properties (including serializers, bindings, and NameSelectors if present)
to maintain API naming consistency and avoid conflicts with existing
NameSelectors configuration.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor.samples.cs (1)

301-301: Optional: Consider updating the pinned FontAwesome version to the latest.

Font Awesome 7.2.0 has been released (February 10) and is the current latest version, whereas the demo pins to 7.0.1. The URL is valid, but pinning to the latest avoids users copying the CDN snippet and getting an outdated release.

♻️ Suggested update
-<link rel=""stylesheet"" href=""https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"" />
+<link rel=""stylesheet"" href=""https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css"" />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor.samples.cs`
at line 301, Update the pinned Font Awesome CDN URL in the Bit NavBar demo
sample: find the link element string "<link rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css\"
/>" in _BitNavBarOptionDemo.razor.samples.cs and change the version segment from
7.0.1 to the current latest (e.g., 7.2.0) so the href becomes
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css";
ensure the string is updated wherever that exact snippet is used in the file.
src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarItemDemo.razor (1)

241-241: Use <HeadContent> to inject the stylesheet into <head>

Placing a <link rel="stylesheet"> directly inside a Blazor component's render tree (i.e., in the <body>) is non-standard and can cause issues in interactive render modes: each re-render of the parent may re-insert the <link> node into the DOM, leading to duplicate stylesheet downloads. Blazor's <HeadContent> component handles deduplication and proper <head> injection.

♻️ Proposed fix
 <DemoExample Title="External Icons" RazorCode="@example12RazorCode" CsharpCode="@example12CsharpCode" Id="example12">
     <div>External icon libraries like FontAwesome can be used with the <b>Icon</b> parameter.</div>
     <br />
     <br />
-    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
+    <HeadContent>
+        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css"
+              integrity="sha512-<hash-here>" crossorigin="anonymous" referrerpolicy="no-referrer" />
+    </HeadContent>
     <div class="container">
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarItemDemo.razor`
at line 241, The stylesheet link currently rendered inside the component’s body
in _BitNavBarItemDemo.razor should be moved into a Blazor <HeadContent> block to
avoid duplicate <link> injections on re-renders; locate the inline <link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"
/> in the BitNavBarItemDemo component and replace it by adding the same href
inside a <HeadContent> section so the stylesheet is injected into the document
<head> and deduplicated by Blazor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/BlazorUI/Bit.BlazorUI/Components/Navs/NavBar/BitNavBar.razor.cs`:
- Around line 307-327: GetIcon returns BitIconInfo? but the fallback calls
GetValueFromProperty<string?> causing a type mismatch; update the fallback call
inside GetIcon to use GetValueFromProperty<BitIconInfo?> so it retrieves the
correct type when NameSelectors.Icon.Selector is null—locate the GetIcon method
and replace the generic parameter on the NameSelectors.Icon fallback call to
BitIconInfo? (references: GetIcon, NameSelectors.Icon, GetValueFromProperty).

In `@src/BlazorUI/Bit.BlazorUI/Components/Navs/NavBar/BitNavBarNameSelectors.cs`:
- Around line 15-19: The GetIcon fallback in the BitNavBar partial class uses
the wrong generic for GetValueFromProperty causing a type mismatch: update the
GetValueFromProperty call in BitNavBar.razor.cs (the GetIcon implementation) to
use BitIconInfo? (matching BitNavBarNameSelectors.Icon's generic type) instead
of string? so the name-based lookup returns the correct BitIconInfo? when no
Selector is provided; ensure the call mirrors the selector's declared value type
and compiles against the BitNavBarNameSelectors.Icon definition.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarCustomDemo.razor.samples.cs`:
- Around line 517-540: The sample in example13CsharpCode defines a MenuItem
class with the wrong property name/type; change the MenuItem property "public
BitIconInfo? Icon { get; set; }" to "public string? ImageName { get; set; }" so
it matches the sample instances (basicNavBarCustoms and
basicNavBarCustomsClassStyle) that set ImageName values; ensure the property
name and type align with the actual MenuItem used by the demo.
- Around line 447-466: The Razor sample's NameSelectors uses the wrong key:
change ImageName = { Selector = item => item.Image } to Icon = { Selector = item
=> item.Image } inside the example12RazorCode so it matches the BitIconInfo
usage in example12CsharpCode and the real demo (_BitNavBarCustomDemo.razor),
ensuring external icons bind via the Icon selector rather than ImageName.
- Around line 509-516: Replace the incorrect property name ItemImageName with
the correct ItemIcon on the BitNavBar component instances in the sample; update
both the Styles and Classes anonymous objects (where Styles uses ItemImageName
and Classes uses ItemImageName) to use ItemIcon so they match the
BitNavBarClassStyles API and the NameSelectors usage remains unchanged.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarItemDemo.razor`:
- Line 241: Update the external Font Awesome <link> in _BitNavBarItemDemo.razor
to use the current 7.2.0 CDN URL and add Subresource Integrity and crossorigin
attributes: replace the href version from 7.0.1 to 7.2.0 and add
integrity="sha384-<calculated_hash>" and crossorigin="anonymous"; generate the
SHA-384 hash by fetching the 7.2.0 CSS (e.g., curl -sL
https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css |
openssl dgst -sha384 -binary | openssl base64 -A) and prefixing the result with
"sha384-".

---

Nitpick comments:
In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarItemDemo.razor`:
- Line 241: The stylesheet link currently rendered inside the component’s body
in _BitNavBarItemDemo.razor should be moved into a Blazor <HeadContent> block to
avoid duplicate <link> injections on re-renders; locate the inline <link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"
/> in the BitNavBarItemDemo component and replace it by adding the same href
inside a <HeadContent> section so the stylesheet is injected into the document
<head> and deduplicated by Blazor.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor`:
- Line 389: Move the inline <link rel="stylesheet"> out of the component body
and place it inside a Blazor <HeadContent> block in _BitNavBarOptionDemo.razor
so the Font Awesome stylesheet is injected into the document head (ensuring
correct behavior for SSR/WASM/hybrid and avoiding duplicates); locate the
existing <link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"
/> in the component markup and wrap it with <HeadContent>...</HeadContent> (or
add a single shared HeadContent section if one already exists) so the stylesheet
is added to the head instead of rendered into the body.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/_BitNavBarOptionDemo.razor.samples.cs`:
- Line 301: Update the pinned Font Awesome CDN URL in the Bit NavBar demo
sample: find the link element string "<link rel=\"stylesheet\"
href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css\"
/>" in _BitNavBarOptionDemo.razor.samples.cs and change the version segment from
7.0.1 to the current latest (e.g., 7.2.0) so the href becomes
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.2.0/css/all.min.css";
ensure the string is updated wherever that exact snippet is used in the file.

In
`@src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Navs/NavBar/MenuItem.cs`:
- Around line 6-7: The demo model MenuItem has inconsistent property names Image
and ImageName for a BitIconInfo?, which diverges from the library usage of
Icon/IconName in BitNavBarItem and BitNavBarOption; rename Image → Icon and
ImageName → IconName in the MenuItem class and update any references/usages to
those properties (including serializers, bindings, and NameSelectors if present)
to maintain API naming consistency and avoid conflicts with existing
NameSelectors configuration.

@msynk msynk merged commit 0b657fc into bitfoundation:develop Feb 22, 2026
3 checks passed
@msynk msynk deleted the 12111-blazorui-navbar-new-icons branch February 22, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The new Icon implementation is missing in the BitNavBar component

3 participants