METADATA ======= Last Updated: 2026-09-19 06:33 UTC Title: BlazorBlueprint - Common Patterns and Conventions Library Version: 4 Most interactive components expose a Value parameter and a ValueChanged callback for standard Blazor two-way binding: This desugars to: Text input components (BbInput, BbTextarea, BbInputGroupInput, BbInputGroupTextarea) implement their own Value/ValueChanged pattern directly on ComponentBase. They do NOT inherit from InputBase. Specialized inputs (BbNumericInput, BbCurrencyInput, BbMaskedInput) also have their own value handling with type-specific parsing. ================================================================================ CONTROLLED VS UNCONTROLLED STATE ================================================================================ Many components support both controlled and uncontrolled modes: Controlled (you manage the state): ... Or with @bind shorthand: ... Uncontrolled (component manages its own state): ... Applies to: Open/DefaultOpen, Value/DefaultValue, and similar parameter pairs. Components with a nullable `Open` (bool?) plus `OpenChanged`: BbAlertDialog, BbContextMenu, BbDialog, BbDrawer, BbDropdownMenu, BbHoverCard, BbPopover, BbSelect, BbSheet, BbTooltip and BbSidebarProvider. Leaving `Open` null keeps the component uncontrolled. BbSidebarProvider has a second pair, `OpenMobile`/`OpenMobileChanged`, for the mobile drawer; binding `Open` on it turns off its cookie persistence. ================================================================================ ONVALUECHANGE CALLBACKS ================================================================================ Some components provide an OnValueChange (or similar On*Change) callback that fires when the value changes but does NOT control the state. This is a one-way notification useful for side effects like logging or analytics: ... The difference from ValueChanged: - ValueChanged: Part of two-way binding. Setting Value + ValueChanged means YOU control the state. - OnValueChange: Notification only. The component still manages its own state internally. ================================================================================ FORM INTEGRATION ================================================================================ For EditForm validation, value components support: - Value / ValueChanged: The bound value - ValueExpression: An Expression> pointing to the bound property, used to identify the field for validation messages `@bind-Value` generates Value, ValueChanged and ValueExpression for you. Do not also set ValueExpression explicitly next to `@bind-Value`; Razor rejects a parameter supplied twice. Example: Set ValueExpression yourself only when binding with separate Value and ValueChanged attributes: Multi-value components bind a collection through `Values`/`ValuesChanged` and use `ValuesExpression` the same way (for example BbTreeSelect in multiple mode, where `@bind-Values` supplies it). When inside an EditForm, components automatically detect the cascaded EditContext and integrate with Blazor's validation system. ================================================================================ OVERLAY / PORTAL PATTERN ================================================================================ Overlay components (BbDialog, BbSheet, BbPopover, BbTooltip, BbDropdownMenu, BbHoverCard, BbContextMenu, BbSelect and the others) render their content through the BbPortalHost component. How it works: 1. BbPortalHost must be placed in your root layout (MainLayout.razor), in the same render-mode scope as the interactive content that opens overlays 2. Overlay components register their content with IPortalService (floating overlays through BbFloatingPortal, dialogs through BbDialogPortal, sheets through BbSheetPortal) 3. BbPortalHost renders the registered content where it is placed in the layout 4. IPositioningService handles floating UI positioning (for BbPopover, BbTooltip, BbDropdownMenu and the other floating overlays) This ensures overlays are not clipped by parent overflow or z-index contexts. Native dialog exception: `` renders the browser's own element in the top layer, with native focus trapping, Escape handling and ::backdrop, and needs no BbPortalHost. In a browser without .showModal() it falls back to the portal path instead, so leave BbPortalHost in the layout. See setup.txt for the app-wide default. Escape key: Escape dismisses only the topmost overlay, one layer per press. A popover opened inside a dialog closes first; the next Escape closes the dialog. Overlays whose content holds focus (BbSelect, BbDropdownMenu, BbContextMenu, BbMenubar) handle Escape on their own container and stop it propagating, so they take precedence over whatever is underneath. Initial focus: BbDialogContent, BbSheetContent and BbDrawerContent accept `InitialFocus` (FocusTrapInitialFocus) and `InitialFocusElement` (ElementReference?). Resolution order: InitialFocusElement, then an element carrying `data-autofocus`, then the InitialFocus mode, then the first tabbable descendant. FocusTrapInitialFocus (namespace BlazorBlueprint.Primitives): FirstFocusable Focus the first tabbable element (default). Container Focus the content panel itself. None Do not move focus. ... ================================================================================ CLASS PARAMETER ================================================================================ All styled components accept a Class parameter for adding custom CSS classes: Submit ... The Class value is merged with the component's default classes through ClassNames.cn (a clsx + tailwind-merge equivalent). When your class targets the same CSS property as a default class, yours wins and the default is removed. The library's own utilities are prefixed `bb:` inside blazorblueprint.css (for example `bb:p-4`). Write Class values WITHOUT the prefix. The merge strips the library prefix before resolving conflicts and puts it back on the library classes that survive: @* renders class="... p-6 ...": the library's bb:p-4 is removed *@ ClassNames.cn("bb:p-4 bb:rounded-md", "p-6") // keeps bb:rounded-md and p-6, drops bb:p-4 ClassNames.cn("bb:p-4", "bb:p-8") // "bb:p-8" Unprefixed classes such as `p-6` are emitted by your application's own Tailwind build; blazorblueprint.css does not contain them. See setup.txt ("TAILWIND AND THE bb: UTILITY PREFIX") for apps without a Tailwind build. group and peer markers are rendered in both forms, so your own `group-*` and `peer-*` variants apply to library markup. Tailwind resolves those variants against a literal marker class and your build never sees the library prefix, so it emits a rule matching `:where(.group)`, never `:where(.bb\:group)`. Every marker the library renders therefore carries the bare class alongside the prefixed one: `class="group bb:group ..."`, and for a named marker `class="peer/menu-button bb:peer/menu-button ..."`. A marker of your own passed through `Class` (`Class="group"`) is kept exactly as you wrote it: @* inside a BbSidebar: its