DwsSpacer
Adds empty space between two elements. The spacers below are tinted with Class="bg-info" so the space they take is visible.
API ReferenceHorizontal and vertical
A plain number is a length in pixels. Horizontal spacers take it as their width, vertical ones as their height.
Show Code
Spacer.razor
<div class='d-flex'>
<span class='border rounded px-2'>A</span>
<DwsSpacer Name='SpacerDemo_Basic_Horizontal20' Size='20' Class='bg-info' />
<span class='border rounded px-2'>B</span>
<DwsSpacer Name='SpacerDemo_Basic_Horizontal80' Size='80' Class='bg-info' />
<span class='border rounded px-2'>C</span>
</div>
<div class='mt-3'>
<div class='border rounded px-2'>Row 1</div>
<DwsSpacer Name='SpacerDemo_Basic_Vertical20' Orientation='DwsLayoutOrientation.Vertical' Size='20' Class='bg-info' />
<div class='border rounded px-2'>Row 2</div>
<DwsSpacer Name='SpacerDemo_Basic_Vertical40' Orientation='DwsLayoutOrientation.Vertical' Size='40' Class='bg-info' />
<div class='border rounded px-2'>Row 3</div>
</div>Percentages and viewport units
Size also takes a CSS length: a percentage of the parent, a viewport unit (vw, vh, ...) or rem / em. Values are validated; anything else is ignored with a warning. Resize the window to see the percentage, vw and vh spacers change.
Show Code
Spacer.razor
<div class='d-flex'>
<span class='border rounded px-2'>25%</span>
<DwsSpacer Name='SpacerDemo_Units_Percent' Size='25%' Class='bg-info' />
<span class='border rounded px-2'>10vw</span>
<DwsSpacer Name='SpacerDemo_Units_Viewport' Size='10vw' Class='bg-info' />
<span class='border rounded px-2'>3rem</span>
<DwsSpacer Name='SpacerDemo_Units_Rem' Size='3rem' Class='bg-info' />
<span class='border rounded px-2'>End</span>
</div>
<div class='mt-3'>
<div class='border rounded px-2'>Above</div>
<DwsSpacer Name='SpacerDemo_Units_VerticalViewport' Orientation='DwsLayoutOrientation.Vertical' Size='5vh' Class='bg-info' />
<div class='border rounded px-2'>Below (5vh)</div>
</div>calc(), min(), max() and clamp()
Size takes CSS math over such lengths. It is type-checked: a length plus a plain number is rejected with a warning. Resize the window to see the clamp spacer change between its limits.
Show Code
Spacer.razor
<div class='d-flex overflow-x-auto'>
<span class='border rounded px-2'>calc(50% - 4rem)</span>
<DwsSpacer Name='SpacerDemo_Units_Calc' Size='calc(50% - 4rem)' Class='bg-info' />
<span class='border rounded px-2'>clamp(8px, 4vw, 48px)</span>
<DwsSpacer Name='SpacerDemo_Units_Clamp' Size='clamp(8px, 4vw, 48px)' Class='bg-info' />
<span class='border rounded px-2'>End</span>
</div>Breakpoint sizes
SizeSm, SizeMd, SizeLg, SizeXl and SizeXxl apply from 576px, 768px, 992px, 1200px and 1400px up. An unset one falls back to the next smaller size. Resize the window to see the space grow.
Show Code
Spacer.razor
<div class='d-flex'>
<span class='border rounded px-2'>A</span>
<DwsSpacer Name='SpacerDemo_BreakpointSizes_Spacer' Size='8' SizeMd='40' SizeLg='120' SizeXxl='240' Class='bg-info' />
<span class='border rounded px-2'>B</span>
</div>Adaptive breakpoints (container queries)
Adaptive sizes the spacer by its parent instead of the viewport. The parent becomes a CSS size container, so the breakpoint sizes and orientations apply at the parent's width. Narrow the box to see the spacer shrink on any screen size.
Show Code
Spacer.razor
<div class='d-flex gap-2'>
<DwsButton Name='SpacerDemo_Adaptive_Narrow' OnClick='() => SetAdaptiveWidth(AdaptiveNarrowWidth)'>Narrow (@AdaptiveNarrowWidth)</DwsButton>
<DwsButton Name='SpacerDemo_Adaptive_Wide' OnClick='() => SetAdaptiveWidth(AdaptiveWideWidth)'>Wide (@AdaptiveWideWidth)</DwsButton>
</div>
<div class='d-flex border rounded p-1 mt-3' style='@AdaptiveBoxStyle'>
<span class='px-2'>A</span>
<DwsSpacer Name='SpacerDemo_Adaptive_Breakpoints' Adaptive='true' Size='8' SizeSm='32' SizeMd='96' Class='bg-info' />
<span class='px-2'>B</span>
</div>Spacer.razor.cs
private const string AdaptiveNarrowWidth = "320px";
private const string AdaptiveWideWidth = "100%";
private string _adaptiveWidth = AdaptiveWideWidth;
private string AdaptiveBoxStyle => $"width: {_adaptiveWidth}; max-width: 100%;";
private void SetAdaptiveWidth(string width) => _adaptiveWidth = width;Container units
With Adaptive, container units such as cqi are a share of the parent's width - which also works for vertical spacers, where a percentage height would not. Narrow the box to see the spacer shrink.
Show Code
Spacer.razor
<div class='d-flex gap-2'>
<DwsButton Name='SpacerDemo_ContainerUnits_Narrow' OnClick='() => SetContainerUnitsWidth(AdaptiveNarrowWidth)'>Narrow (@AdaptiveNarrowWidth)</DwsButton>
<DwsButton Name='SpacerDemo_ContainerUnits_Wide' OnClick='() => SetContainerUnitsWidth(AdaptiveWideWidth)'>Wide (@AdaptiveWideWidth)</DwsButton>
</div>
<div class='border rounded p-1 mt-3' style='@ContainerUnitsBoxStyle'>
<div class='px-2'>Above</div>
<DwsSpacer Name='SpacerDemo_Adaptive_ContainerUnits' Adaptive='true' Orientation='DwsLayoutOrientation.Vertical' Size='calc(5cqi + 4px)' Class='bg-info' />
<div class='px-2'>Below (5% of the box width + 4px)</div>
</div>Spacer.razor.cs
private const string AdaptiveNarrowWidth = "320px";
private const string AdaptiveWideWidth = "100%";
private string _containerUnitsWidth = AdaptiveWideWidth;
private string ContainerUnitsBoxStyle => $"width: {_containerUnitsWidth}; max-width: 100%;";
private void SetContainerUnitsWidth(string width) => _containerUnitsWidth = width;Orientation switching
OrientationSm to OrientationXxl change the orientation per breakpoint. Here the parent stacks its items below 768px and puts them in a row above, and the spacer follows: vertical on small screens, horizontal from 768px up.
Show Code
Spacer.razor
<div class='d-flex flex-column flex-md-row'>
<span class='border rounded px-2'>Navigation</span>
<DwsSpacer Name='SpacerDemo_OrientationSwitch_Spacer' Size='24'
Orientation='DwsLayoutOrientation.Vertical'
OrientationMd='DwsLayoutOrientation.Horizontal'
Class='bg-info' />
<span class='border rounded px-2'>Content</span>
</div>Flex grow
UseFlexGrow fills the free space of a flex parent, e.g. to push toolbar actions to the end.
Show Code
Spacer.razor
<div class='d-flex border rounded p-1'>
<span class='px-2'>Title</span>
<DwsSpacer Name='SpacerDemo_Grow_Push' UseFlexGrow='true' Class='bg-info' />
<span class='px-2'>Action 1</span>
<span class='px-2'>Action 2</span>
</div>Proportional spacing
GrowFactor shares the free space between several growing spacers (1 : 2 here), and Size becomes the minimum.
Show Code
Spacer.razor
<div class='d-flex border rounded p-1'>
<span class='px-2'>A</span>
<DwsSpacer Name='SpacerDemo_Grow_One' UseFlexGrow='true' GrowFactor='1' Size='16' Class='bg-info' />
<span class='px-2'>B</span>
<DwsSpacer Name='SpacerDemo_Grow_Two' UseFlexGrow='true' GrowFactor='2' Size='16' Class='bg-info' />
<span class='px-2'>C</span>
</div>Static rendering
Static renders the spacer as a plain element: it does not register with the page, skips the permission checks (only Visible is honoured) and never calls JS. Useful for many spacers in a long list, where the checks buy nothing.
Show Code
Spacer.razor
<div class='d-flex'>
@foreach (string item in _staticItems)
{
<span class='border rounded px-2'>@item</span>
@if (item != _staticItems[^1])
{
<DwsSpacer Name='@($"SpacerDemo_Static_{item}")' Size='12' Static='true' Class='bg-info' />
}
}
</div>Spacer.razor.cs
private readonly string[] _staticItems = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"];Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| Orientation | DwsLayoutOrientation | DwsLayoutOrientation.Horizontal | Whether Size is a width (Horizontal) or a height (Vertical). With breakpoint orientations it is the orientation on the smallest screens. |
| OrientationSm | DwsLayoutOrientation? | null | Orientation on viewports 576px wide and up. Falls back to Orientation when null. With Adaptive the width is the parent's. |
| OrientationMd | DwsLayoutOrientation? | null | Orientation on viewports 768px wide and up. Falls back to the next smaller breakpoint orientation when null. With Adaptive the width is the parent's. |
| OrientationLg | DwsLayoutOrientation? | null | Orientation on viewports 992px wide and up. Falls back to the next smaller breakpoint orientation when null. With Adaptive the width is the parent's. |
| OrientationXl | DwsLayoutOrientation? | null | Orientation on viewports 1200px wide and up. Falls back to the next smaller breakpoint orientation when null. With Adaptive the width is the parent's. |
| OrientationXxl | DwsLayoutOrientation? | null | Orientation on viewports 1400px wide and up. Falls back to the next smaller breakpoint orientation when null. With Adaptive the width is the parent's. |
| AutoOrientation | bool | false | Takes the orientation from the parent's layout: horizontal in a flex row or a column-flow grid, vertical anywhere else. The parent is watched, so a container that changes direction at a breakpoint is followed. Orientation and the breakpoint orientations are the fallback until the parent has been read (prerendering, Static); in a flex parent the spacer is right even then. |
| Size | string? | null (1rem) | Length as a CSS length. A plain number is pixels ("20"); otherwise a number with px, %, vw, vh, vmin, vmax, dvw, dvh, svw, svh, lvw, lvh, rem, em, ch, cqw, cqh, cqi, cqb, cqmin or cqmax ("50%", "10vw", "2rem"), or calc(), min(), max() or clamp() over such values ("calc(100% - 2rem)", "clamp(8px, 2vw, 32px)"). Math is type-checked: a length plus a number, or a length times a length, is rejected. A percentage is relative to the parent; container units are relative to the parent with Adaptive. Anything else is ignored and logged as a warning. |
| SizeSm | string? | null | Size on viewports 576px wide and up. Falls back to Size when null. With Adaptive the width is the parent's. |
| SizeMd | string? | null | Size on viewports 768px wide and up. Falls back to the next smaller breakpoint size when null. With Adaptive the width is the parent's. |
| SizeLg | string? | null | Size on viewports 992px wide and up. Falls back to the next smaller breakpoint size when null. With Adaptive the width is the parent's. |
| SizeXl | string? | null | Size on viewports 1200px wide and up. Falls back to the next smaller breakpoint size when null. With Adaptive the width is the parent's. |
| SizeXxl | string? | null | Size on viewports 1400px wide and up. Falls back to the next smaller breakpoint size when null. With Adaptive the width is the parent's. |
| Adaptive | bool | false | Sizes the spacer by its parent instead of the viewport: the parent becomes a CSS size container, so the breakpoint sizes and orientations apply at the parent's width and container units (cqi, ...) in Size are a share of the parent's width - which also works for vertical spacers. The parent needs a width of its own (a block element, a stretched flex or grid item); a shrink-to-fit parent such as inline-flex collapses. A parent that declares its own container-type keeps it. No JS. |
| UseFlexGrow | bool | false | Fills the free space along a flex parent's main axis. Size, when set, becomes the minimum. |
| GrowFactor | double | 1 | With UseFlexGrow: this spacer's share of the free space relative to other growing spacers (factors 1 and 2 split it one third to two thirds). Must be positive; anything else falls back to 1 and is logged. |
| Static | bool | false | Renders the spacer as a plain element: no page registration, no permission checks (only Visible is honoured) and no JS interop, so AutoOrientation is limited to its CSS fallback. Read once, when the spacer initializes. |
| 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. |
