DeepWorks Studios Blazor Component Library

Demo user Administrator · Blazor Server Library 20261206222504-6e8ff32.dirty

DwsHorizontal

Lays its child items out in a row. Spacing, alignment and wrapping are parameters, can change per screen size, and the container can render as any layout element.

API Reference

Basic

Space is the gap between the items, Padding and Margin the space inside and around the container, all in pixels.

A B C

A B C
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Basic_Plain'>
    <span class='border rounded px-2'>A</span>
    <span class='border rounded px-2'>B</span>
    <span class='border rounded px-2'>C</span>
</DwsHorizontal>

<DwsHorizontal Name='HorizontalDemo_Basic_Spaced' Space='16' Padding='12' Margin='8' BorderColor='DwsColor.Secondary'>
    <span class='border rounded px-2'>A</span>
    <span class='border rounded px-2'>B</span>
    <span class='border rounded px-2'>C</span>
</DwsHorizontal>

Vertical alignment

VerticalAlignment places items of different heights within the row (align-items). None stretches them to the row's height.

None
A B C
Top
A B C
Center
A B C
Bottom
A B C
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Vertical_Rows' Space='16'>
    @foreach (DwsVerticalAlignment verticalAlignment in Enum.GetValues<DwsVerticalAlignment>())
    {
        <div>
            <small class='d-block'>@verticalAlignment</small>
            <DwsHorizontal Name='@($"HorizontalDemo_Vertical_{verticalAlignment}")' VerticalAlignment='verticalAlignment' Height='90' Space='6' Padding='6' BorderColor='DwsColor.Secondary'>
                <span class='border rounded px-2'>A</span>
                <span class='border rounded px-2 py-3'>B</span>
                <span class='border rounded px-2 py-1'>C</span>
            </DwsHorizontal>
        </div>
    }
</DwsHorizontal>

Wrapping and overflow

By default items that do not fit wrap onto a new line. With Wrap='DwsFlexWrap.NoWrap' they stay on one line, and Overflow decides what happens to the part that does not fit: scroll it sideways (Auto) or cut it off (Hidden).

Wrap (default)
Item 1Item 2Item 3Item 4Item 5Item 6Item 7Item 8

NoWrap + Overflow Auto (scrolls)
Item 1Item 2Item 3Item 4Item 5Item 6Item 7Item 8

NoWrap + Overflow Hidden (cut off)
Item 1Item 2Item 3Item 4Item 5Item 6Item 7Item 8
Show Code
Horizontal.razor

<!-- Wrap (default) -->
<small class='d-block'>Wrap (default)</small>
<DwsHorizontal Name='HorizontalDemo_Overflow_Wrap' Width='260' Space='6' Padding='6' BorderColor='DwsColor.Secondary' Class='mb-3'>
    @for (int i = 1; i <= 8; i++)
    {
        <span class='border rounded px-2'>Item @i</span>
    }
</DwsHorizontal>

<!-- One line, scrolls sideways -->
<small class='d-block'>NoWrap + Overflow Auto (scrolls)</small>
<DwsHorizontal Name='HorizontalDemo_Overflow_Scroll' Width='260' Space='6' Padding='6' BorderColor='DwsColor.Secondary'
               Wrap='DwsFlexWrap.NoWrap' Overflow='DwsOverflow.Auto' Class='mb-3'>
    @for (int i = 1; i <= 8; i++)
    {
        <span class='border rounded px-2 text-nowrap flex-shrink-0'>Item @i</span>
    }
</DwsHorizontal>

<!-- One line, cut off -->
<small class='d-block'>NoWrap + Overflow Hidden (cut off)</small>
<DwsHorizontal Name='HorizontalDemo_Overflow_Hidden' Width='260' Space='6' Padding='6' BorderColor='DwsColor.Secondary'
               Wrap='DwsFlexWrap.NoWrap' Overflow='DwsOverflow.Hidden'>
    @for (int i = 1; i <= 8; i++)
    {
        <span class='border rounded px-2 text-nowrap flex-shrink-0'>Item @i</span>
    }
</DwsHorizontal>

Background

BackgroundColor takes a theme color, so it follows the active theme; BorderRadius rounds the corners.

Primary background · rounded
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Appearance_Primary' BackgroundColor='DwsColor.Primary' Space='8' Padding='12' BorderRadius='8'>
    <span>Primary background</span>
    <span>·</span>
    <span>rounded</span>
</DwsHorizontal>

Border

BorderColor takes a theme color. A BorderColor or BorderWidth alone draws a solid border; BorderStyle picks another style.

Dashed success border
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Appearance_Border' BorderColor='DwsColor.Success' BorderWidth='2' BorderStyle='DwsBorderStyle.Dashed' BorderRadius='8' Space='8' Padding='12'>
    <span>Dashed success border</span>
</DwsHorizontal>

Responsive layout

Breakpoints switch spacing, alignment and wrapping from a screen width up (mobile first), and StackBelow turns the row into a column on small screens. Resize the window: stacked below 576px, a 12px gap from there, centred with a 32px gap from 992px.

Card 1 Card 2 Card 3
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Responsive_Row' Stretch='true' Space='12' Padding='8' BorderColor='DwsColor.Secondary'
               StackBelow='DwsVisibilityBreakpoint.SM' Breakpoints='_responsiveBreakpoints'>
    <span class='border rounded px-3 py-2'>Card 1</span>
    <span class='border rounded px-3 py-2'>Card 2</span>
    <span class='border rounded px-3 py-2'>Card 3</span>
</DwsHorizontal>
Horizontal.razor.cs

// From 992px up: a 32px gap and centred cards. Values left null keep the smaller breakpoint's value.
private static readonly IReadOnlyList<DwsHorizontalBreakpoint> _responsiveBreakpoints =
[
    new DwsHorizontalBreakpoint { Breakpoint = DwsVisibilityBreakpoint.LG, Space = 32, Alignment = DwsHorizontalAlignment.Center },
];

Adaptive to the parent

With Adaptive the breakpoints and StackBelow follow the width of the parent instead of the window. Both rows below are the same component with the same parameters: the one in the 280px wide sidebar stacks, the one in the wider area stays a centred row with a larger gap (from 576px of parent width). The parent needs a width of its own (here a block element).

Sidebar (280px)
Card 1 Card 2 Card 3
Main area
Card 1 Card 2 Card 3
Show Code
Horizontal.razor

<div class='d-flex flex-wrap gap-3'>
    <div class='border rounded p-2' style='width: 280px;'>
        <small class='d-block mb-1'>Sidebar (280px)</small>
        <div>
            <DwsHorizontal Name='HorizontalDemo_Adaptive_Sidebar' Adaptive='true' Stretch='true' Space='12' StackBelow='DwsVisibilityBreakpoint.SM' Breakpoints='_adaptiveBreakpoints'>
                <span class='border rounded px-3 py-2'>Card 1</span>
                <span class='border rounded px-3 py-2'>Card 2</span>
                <span class='border rounded px-3 py-2'>Card 3</span>
            </DwsHorizontal>
        </div>
    </div>
    <div class='border rounded p-2 flex-grow-1' style='min-width: min(320px, 100%);'>
        <small class='d-block mb-1'>Main area</small>
        <div>
            <DwsHorizontal Name='HorizontalDemo_Adaptive_Main' Adaptive='true' Stretch='true' Space='12' StackBelow='DwsVisibilityBreakpoint.SM' Breakpoints='_adaptiveBreakpoints'>
                <span class='border rounded px-3 py-2'>Card 1</span>
                <span class='border rounded px-3 py-2'>Card 2</span>
                <span class='border rounded px-3 py-2'>Card 3</span>
            </DwsHorizontal>
        </div>
    </div>
</div>
Horizontal.razor.cs

// From 576px of parent width up: a 32px gap and centred cards.
private static readonly IReadOnlyList<DwsHorizontalBreakpoint> _adaptiveBreakpoints =
[
    new DwsHorizontalBreakpoint { Breakpoint = DwsVisibilityBreakpoint.SM, Space = 32, Alignment = DwsHorizontalAlignment.Center },
];

Custom element

HtmlTag renders the container as another layout element, e.g. nav for a link bar or ul for a list whose items sit in a row. The list's default indent and bullets are reset.


  • First
  • Second
  • Third
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Tag_Nav' HtmlTag='nav' Space='16'>
    <DwsAnchorLink Name='HorizontalDemo_Tag_ApiLink' href='#apiReference' Color='DwsColor.Link'>API</DwsAnchorLink>
    <DwsLink Name='HorizontalDemo_Tag_VerticalLink' Href='vertical' Color='DwsColor.Link'>DwsVertical</DwsLink>
    <DwsLink Name='HorizontalDemo_Tag_SpacerLink' Href='spacer' Color='DwsColor.Link'>DwsSpacer</DwsLink>
</DwsHorizontal>

<DwsHorizontal Name='HorizontalDemo_Tag_List' HtmlTag='ul' Space='8' Class='list-unstyled'>
    <li class='border rounded px-2'>First</li>
    <li class='border rounded px-2'>Second</li>
    <li class='border rounded px-2'>Third</li>
</DwsHorizontal>

Nested containers

A DwsHorizontal can hold other DwsHorizontals. Grow lets a nested one take the free space next to fixed-width siblings and shrink so that its own items wrap.

Logo
Home Products Services About
Login Cart
Show Code
Horizontal.razor

<DwsHorizontal Name='HorizontalDemo_Nested_Outer' Stretch='true' Space='12' Padding='8' VerticalAlignment='DwsVerticalAlignment.Center' BorderColor='DwsColor.Secondary'>
    <span class='border rounded px-2 py-3'>Logo</span>
    <DwsHorizontal Name='HorizontalDemo_Nested_Menu' Grow='true' Space='8' BorderColor='DwsColor.Primary' Padding='6'>
        <span class='border rounded px-2'>Home</span>
        <span class='border rounded px-2'>Products</span>
        <span class='border rounded px-2'>Services</span>
        <span class='border rounded px-2'>About</span>
    </DwsHorizontal>
    <DwsHorizontal Name='HorizontalDemo_Nested_Actions' Space='4' BorderColor='DwsColor.Success' Padding='6'>
        <span class='border rounded px-2'>Login</span>
        <span class='border rounded px-2'>Cart</span>
    </DwsHorizontal>
</DwsHorizontal>

Debug

Debug outlines the container and its direct children, tints the padding (darker) and the content box (lighter, the gaps show through), labels the container with its Name and tag and logs the resolved layout once. Use it while building a page and remove it afterwards.


Start
A B
End
Show Code
Horizontal.razor

<DwsButton Name='HorizontalDemo_Debug_Toggle' Appearance='DwsAppearance.Outline' ButtonSize='DwsSize.Small' OnClick='ToggleDebug'>Debug: @(_debug ? "on" : "off")</DwsButton>

<DwsHorizontal Name='HorizontalDemo_Debug_Outer' Debug='_debug' Stretch='true' Space='16' Padding='20' Alignment='DwsHorizontalAlignment.SpaceBetween'>
    <span class='px-2'>Start</span>
    <DwsHorizontal Name='HorizontalDemo_Debug_Inner' HtmlTag='section' Debug='_debug' Space='8' Padding='16'>
        <span class='px-2'>A</span>
        <span class='px-2'>B</span>
    </DwsHorizontal>
    <span class='px-2'>End</span>
</DwsHorizontal>
Horizontal.razor.cs

private bool _debug = true;

private void ToggleDebug() => _debug = !_debug;

Interface-Description

Name Typ Default Description
ChildContent RenderFragment? null The child items laid out in the row.
HtmlTag string "div" Element the container renders as: div, section, article, aside, nav, header, footer, main, form, fieldset, figure, ul, ol, li, menu, p, span, label or address. Anything else falls back to div and is logged as a warning.
Alignment DwsHorizontalAlignment DwsHorizontalAlignment.Left Horizontal distribution of the items (justify-content): Left, Center, Right, SpaceBetween, SpaceAround, SpaceEvenly. None leaves it to the stylesheet.
VerticalAlignment DwsVerticalAlignment DwsVerticalAlignment.None Vertical alignment of the items within the row (align-items): Top, Center, Bottom. None stretches them to the row's height.
Wrap DwsFlexWrap DwsFlexWrap.Wrap Whether items that exceed the container's width wrap onto a new line (Wrap, WrapReverse) or stay on one line (NoWrap).
Overflow DwsOverflow? null How content that does not fit is handled: Visible, Hidden, Clip, Scroll or Auto. Pair with Wrap=NoWrap for a row that scrolls or clips sideways. Null keeps the CSS default (visible).
Space int? null Gap between the items in pixels. Negative values are ignored with a warning.
Padding int? null Inner padding in pixels. Negative values are ignored with a warning.
Margin int? null Outer margin in pixels.
Breakpoints IReadOnlyList<DwsHorizontalBreakpoint>? null Layout values (Space, Padding, Margin, Alignment, VerticalAlignment, Wrap) that apply from a viewport width up: SM 576px, MD 768px, LG 992px, XL 1200px, XXL 1400px. Mobile first; values left null are inherited from the smaller breakpoint. An XS entry replaces the component's own parameters; the last entry wins when a breakpoint is listed twice.
StackBelow DwsVisibilityBreakpoint? null Below this viewport breakpoint (the parent's width with Adaptive) the items stack in a column, each filling the container's width. XS never stacks.
Adaptive bool false Applies Breakpoints and StackBelow at the width of the parent element instead of the viewport. The parent becomes a CSS size container, so it needs a width of its own (a block element, a stretched flex or grid item); a shrink-to-fit parent collapses. A parent that declares its own container-type keeps it.
Stretch bool false Takes the full width of the parent (width: 100%). Width is ignored while it is set.
Grow bool false Fills the free space along a flex parent's main axis and may shrink below its content, for a nested DwsHorizontal next to fixed-width siblings.
Width int? null Width in pixels.
MinWidth int? null Minimum width in pixels.
MaxWidth int? null Maximum width in pixels.
Height int? null Height in pixels.
MinHeight int? null Minimum height in pixels.
MaxHeight int? null Maximum height in pixels.
BackgroundColor DwsColor DwsColor.Undefined Theme color of the background.
BorderColor DwsColor DwsColor.Undefined Theme color of the border. On its own it draws a solid 1px border.
BorderWidth int? null Border width in pixels. Draws a solid border when no BorderStyle is set.
BorderStyle DwsBorderStyle DwsBorderStyle.None Border style (Solid, Dashed, Dotted, ...). None with a BorderColor or BorderWidth means solid.
BorderRadius int? null Corner radius in pixels.
Debug bool false Outlines the container and its direct children, tints the padding and content box, labels the container with its Name and tag, and logs the resolved layout once.
OnClickPropagation bool true Whether a click bubbles on to the parent elements. Turn it off so a clickable nested DwsHorizontal does not click its parent as well.
Name Typ Description
OnClick EventCallback<MouseEventArgs> Raised on click. Not raised while disabled or in permission register mode, where a click selects the container instead.
OnDoubleClick EventCallback<MouseEventArgs> Raised on double click. Not raised while disabled or in permission register mode.
OnMouseEnter EventCallback<MouseEventArgs> Raised when the pointer enters the container. Not raised while disabled or in permission register mode.
OnMouseLeave EventCallback<MouseEventArgs> Raised when the pointer leaves the container. Not raised while disabled or in permission register mode.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.