DwsSwitch
API ReferenceColors
Color sets the track color of the switched-on state through the theme's CSS variables. The default is Success.
Show Code
Switch.razor
<DwsSwitch Name='SwitchDemo_Color_Success' Label='Success' Value='true' />
<DwsSwitch Name='SwitchDemo_Color_Primary' Label='Primary' Value='true' Color='DwsColor.Primary' />
<DwsSwitch Name='SwitchDemo_Color_Info' Label='Info' Value='true' Color='DwsColor.Info' />
<DwsSwitch Name='SwitchDemo_Color_Warning' Label='Warning' Value='true' Color='DwsColor.Warning' />
<DwsSwitch Name='SwitchDemo_Color_Error' Label='Error' Value='true' Color='DwsColor.Error' />
<DwsSwitch Name='SwitchDemo_Color_Light' Label='Light' Value='true' Color='DwsColor.Light' />Disabled
A disabled switch keeps its value but cannot be toggled by pointer or keyboard.
Show Code
Switch.razor
<DwsSwitch Name='SwitchDemo_Disabled_On' Label='Disabled (on)' Value='true' Disabled='true' />
<DwsSwitch Name='SwitchDemo_Disabled_Off' Label='Disabled (off)' Value='false' Disabled='true' />Responsive label
LabelVisibilityBreakpoint hides the visible label on viewports at or below the given breakpoint - here 768px and narrower (MD); the label shows from 769px. It is still announced to screen readers through aria-label.
Show Code
Switch.razor
<DwsSwitch Name='SwitchDemo_Responsive_Md' Label='Hidden at MD and below' Value='true'
LabelVisibilityBreakpoint='DwsVisibilityBreakpoint.MD' />
<DwsSwitch Name='SwitchDemo_Responsive_Always' Label='Always visible' Value='true' />Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| IsPending | bool | false | Whether a handler of a toggle is still running. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Value | bool | false | Whether the switch is on. Supports two-way binding via @bind-Value. Setting it from code never raises ValueChanged. With ValueChanged bound, the switch shows the value the parent passes back, so a handler that keeps its value refuses the toggle. |
| Label | string | string.Empty | Label text rendered next to the switch. Clicking it toggles the switch. |
| LabelVisibilityBreakpoint | DwsVisibilityBreakpoint | DwsVisibilityBreakpoint.XS | Hides the label text on viewports at or below this breakpoint's width (SM 576px, MD 768px, LG 992px, XL 1200px, XXL 1400px). There only the toggle renders, and the label is exposed as aria-label instead. |
| Color | DwsColor | DwsColor.Success | Track color of the switched-on state, resolved through the theme's CSS variables. |
| ToggleOnEnter | bool | true | Whether Enter toggles the focused switch, as Space always does. While it does, the switch consumes the key (keydown and keyup): a surrounding form is not submitted and ancestor key handlers never see it. A container can hand Enter back for every switch inside it with data-dws-enter-toggle="false". Handled by dws.js, so other keys cost no server round trip. |
| ShowPendingState | bool | true | Shows that a toggle is still being processed: while an asynchronous ValueChanged or OnValueChanged handler runs, the switch pulses, shows a progress cursor and carries aria-busy. Handlers that complete synchronously never show it. The state is also reported through OnIsComponentLoadingChanged. |
| LockWhilePending | bool | false | Refuses further toggles while a handler of the previous one is still running, so a slow save cannot be overtaken by the next click. The switch stays focusable; a refused click puts it back. |
| Tooltip | string | string.Empty | Tooltip text shown on hover. |
| Haptic | DwsHapticFeedback | DwsHapticFeedback.Selection | Tactile feedback played inside the tap when the user toggles the switch (pointer, Space or Enter), while the app has haptics switched on. Not played while disabled or armed for permission selection. |
| CheckedTooltip | string? | null | Tooltip shown while the switch is on. Falls back to Tooltip when empty. |
| UncheckedTooltip | string? | null | Tooltip shown while the switch is off. Falls back to Tooltip when empty. |
| TooltipPosition | DwsTooltipPosition | DwsTooltipPosition.Top | Kept so existing markup still compiles: the tooltip is the browser's native title, which has no position. |
| ValueExpression | Expression<Func<bool>>? | null | The bound field, set by @bind-Value. Names the switch (Model.Newsletter, value=true) for a statically rendered form. |
| Name | Typ | Description |
|---|---|---|
| ValueChanged | EventCallback<bool> | Raised with the requested value when the user toggles the switch. Used by @bind-Value. |
| OnValueChanged | EventCallback<bool> | Raised after every user toggle (pointer, label, Space or Enter) with the value the user asked for - the same value ValueChanged receives. It reports the request, not the outcome: with ValueChanged bound it is raised even when the parent refuses the toggle. Stays available when @bind-Value is used. |
| OnClick | EventCallback<MouseEventArgs> | Raised when the switch input is clicked - by pointer, through its label, or by the Space or Enter key, which both reach the switch as a click. |
| OnFocus | EventCallback<FocusEventArgs> | Raised when the switch input receives focus. |
| OnBlur | EventCallback<FocusEventArgs> | Raised when the switch input loses focus. |
| 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 switch's <input> element (e.g. aria-describedby or data-testid). id, type, role, class, checked and disabled are controlled by the switch. | |
| 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. |
