# Add Indeterminate Switch State

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>Switch for Blazor</td>
        </tr>
    </tbody>
</table>

## Description

This KB answers the following questions:

* How to implement an indeterminate state feature for the Switch component with CSS?
* How to use a Switch component with an undetermined state for nullable boolean values?
* How to enable inteterminate Switch state when the value is null?

## Solution

1. Use a specific `Class` parameter value to toggle the indeterminate UI state of the Switch.
2. [Apply custom CSS styles to override](https://www.telerik.com/blazor-ui/documentation/styling-and-themes/override-theme-styles) the default Switch appearance.

> Indeterminate Switches are uncommon and users may not identify or distinguish them easily. Also evaluate other options, such as [indeterminate checkboxes](https://www.telerik.com/blazor-ui/documentation/components/checkbox/indeterminate-state) or a [RadioGroup](https://www.telerik.com/blazor-ui/documentation/components/radiogroup/overview) with three visible options.

> caption Switch with indeterminate state for null values

```RAZOR
<p>Switch <code>Value</code>: <code>@( SwitchValue?.ToString().ToLowerInvariant() ?? "null" )</code></p>

<TelerikSwitch @bind-Value="@SwitchValue"
               Class="@( SwitchValue.HasValue ? string.Empty : IndeterminateClass )" />

<TelerikButton OnClick="@( () => SwitchValue = default )">Reset Switch</TelerikButton>

<style>
    /* Set a custom Switch background in indeterminate state. */
    span.switch-indeterminate .k-switch-track {
        background-color: var(--kendo-color-warning);
    }

    /* Hide Switch labels */
    span.switch-indeterminate .k-switch-label-on,
    span.switch-indeterminate .k-switch-label-off {
        display: none;
    }

        /* Center the Switch thumb */
        span.switch-indeterminate .k-switch-thumb {
            transform: translate(0, -50%);
        }
</style>

@code {
    private bool? SwitchValue { get; set; }

    private const string IndeterminateClass = "switch-indeterminate";
}
```

## See Also

* [CheckBox Indeterminate State](https://www.telerik.com/blazor-ui/documentation/components/checkbox/indeterminate-state)
