Blazor Dropdown

Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They are toggled by clicking, not by hovering; this is an intentional design decision'by bootstrap.

Single button #

Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropdown button</DropdownToggleButton>
    <DropdownMenu>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>

Color #

Split button #

Sizing #

Razor
<div class="d-flex gap-2 mb-4">
    <Dropdown Color="DropdownColor.Secondary" Size="DropdownSize.Large">
        <DropdownToggleButton>Large button</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>

    <Dropdown Color="DropdownColor.Secondary" Split="true" Size="DropdownSize.Large">
        <DropdownActionButton>Large split button</DropdownActionButton>
        <DropdownToggleButton />
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</div>
Razor
<div class="d-flex gap-2 mb-4">
    <Dropdown Color="DropdownColor.Secondary" Size="DropdownSize.Small">
        <DropdownToggleButton>Small button</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>

    <Dropdown Color="DropdownColor.Secondary" Size="DropdownSize.Small" Split="true">
        <DropdownActionButton>Small split button</DropdownActionButton>
        <DropdownToggleButton />
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</div>

Directions #

Dropup #

To trigger DropdownMenu above elements, add the Direction="DropdownDirection.Dropup" to the Dropdown component.
Razor
<div class="d-flex gap-2">
    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropup">
        <DropdownToggleButton>Dropup button with text</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>

    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropup" Split="true">
        <DropdownActionButton>Dropup split button</DropdownActionButton>
        <DropdownToggleButton />
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</div>

Dropup centered #

To center the DropdownMenu above the toggle, add the Direction="DropdownDirection.DropupCentered" to the Dropdown component.
Razor
<div class="d-flex gap-2">
    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.DropupCentered">
        <DropdownToggleButton>Centered dropup</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</div>

Dropend #

To trigger DropdownMenu at the right of elements, add the Direction="DropdownDirection.Dropend" to the Dropdown component.
Razor
<div class="d-flex gap-2">
    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropend">
        <DropdownToggleButton>Dropend</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>

    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropend" Split="true">
        <DropdownActionButton>Split dropend</DropdownActionButton>
        <DropdownToggleButton />
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
</div>

Dropstart #

To trigger DropdownMenu at the left of elements, you can add the Direction="DropdownDirection.Dropstart" to the Dropdown component.
Razor
<div class="d-flex gap-2">
    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropstart">
        <DropdownToggleButton>Dropstart</DropdownToggleButton>
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
    </Dropdown>
    <Dropdown Color="DropdownColor.Secondary" Direction="DropdownDirection.Dropstart" Split="true">
        <DropdownToggleButton />
        <DropdownMenu>
            <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
            <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        </DropdownMenu>
        <DropdownActionButton>Split dropstart</DropdownActionButton>
    </Dropdown>
</div>

Active #

To style DropdownItem as active, add the Active="true" parameter to the DropdownItem element in the DropdownMenu.
Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropstart</DropdownToggleButton>
    <DropdownMenu>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link" Active="true">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>

Disabled #

To disable the dropdown, set the Disabled parameter to true on the Dropdown component.
Razor
<Dropdown Color="DropdownColor.Secondary" Disabled="@isDropdownDisabled">
    <DropdownToggleButton>Dropstart</DropdownToggleButton>
    <DropdownMenu>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>

<div class="mt-3">
    <Button Color="ButtonColor.Primary" Size="ButtonSize.Small" @onclick="EnableDropdown">Enable</Button>
    <Button Color="ButtonColor.Danger" Size="ButtonSize.Small" @onclick="DisableDropdown">Disable</Button>
</div>
@code
{
    private bool isDropdownDisabled = true;
    private void EnableDropdown() => isDropdownDisabled = false;
    private void DisableDropdown() => isDropdownDisabled = true;
}
To style a dropdown item as disabled, set the Disabled parameter to true on the DropdownItem element in the DropdownMenu component.
Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropstart</DropdownToggleButton>
    <DropdownMenu>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link" Disabled="true">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>

By default, a DropdownMenu is automatically positioned at 100% from the top and along the left side of its parent. You can change this with the Position parameter.

To right-align a DropdownMenu, add the Position="DropdownMenuPosition.End" parameter to the DropdownMenu component. Directions are mirrored when using Bootstrap in RTL.

Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Right-aligned menu example</DropdownToggleButton>
    <DropdownMenu Position="DropdownMenuPosition.End">
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>
Add a header to label sections of actions in any dropdown menu.
Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropdown</DropdownToggleButton>
    <DropdownMenu>
        <DropdownHeader>Dropdown header</DropdownHeader>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
    </DropdownMenu>
</Dropdown>

Dividers #

Separate groups of related menu items with a divider.
Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropdown</DropdownToggleButton>
    <DropdownMenu>
        <DropdownItem To="#" Type="DropdownItemType.Link">Action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Another action</DropdownItem>
        <DropdownItem To="#" Type="DropdownItemType.Link">Something else here</DropdownItem>
        <DropdownDivider>Dropdown header</DropdownDivider>
        <DropdownItem To="#" Type="DropdownItemType.Link">Separated link</DropdownItem>
    </DropdownMenu>
</Dropdown>

Text #

Place any freeform text within a dropdown menu with text and use spacing utilities. Note that youll likely need additional sizing styles to constrain the menu width.
Razor
<Dropdown Color="DropdownColor.Secondary">
    <DropdownToggleButton>Dropdown</DropdownToggleButton>
    <DropdownMenu Class="p-4 text-muted" Style="width: 320px;">
        <p>Some example text that's free-flowing within the dropdown menu.</p>
        <p class="mb-0">And this is more example text.</p>
    </DropdownMenu>
</Dropdown>

Forms #

Put a form within a dropdown menu, or make it into a dropdown menu, and use margin or padding utilities to give it the negative space you require.

Auto close behavior #

By default, the DropdownMenu is closed when clicking either inside or outside the DropdownMenu. You can use the AutoClose and AutoCloseBehavior parameters to change this behavior of the Dropdown.

Methods #

Method Description
HideAsync Hides the dropdown menu of a given navbar or tabbed navigation.
ShowAsync Shows the dropdown menu of a given navbar or tabbed navigation.
ToggleAsync Toggles the dropdown menu of a given navbar or tabbed navigation.
UpdateAsync Updates the position of an element’s dropdown.

Events #

All dropdown events are fired at the toggling element and then bubbled up.
Event type Description
OnHiding This event is fired immediately when the hide method has been called.
OnHidden This event is fired when an dropdown element has been hidden from the user (will wait for CSS transitions to complete).
OnShowing This event fires immediately when the show instance method is called.
OnShown This event is fired when an dropdown element has been made visible to the user (will wait for CSS transitions to complete).