Actively developed · Breaking changes are still expected.

Slint Kit Documentation

Search the documentation

    ↑ ↓ to browse · Enter to open · Escape to close

    Navigation

    Dropdown Menu for Slint

    KitDropdownMenu · Slint Kit 0.9.0

    Trigger button that opens a menu of actions.

    The still preview and demo follow the documentation theme. You can change it before or during the demo.

    Trigger button that opens a menu of actions.
    Slint components with their built-in Tailwind appearance, rendered in the browser.

    This preview runs the actual Slint components and their Rust code compiled to WebAssembly. Slint draws the interface in the browser; the downloadable project compiles the same example into a native application for your platform.

    Try the component

    Download the complete project, extract it and run cargo run --locked in its folder. To add this component to an application, follow Project setup, then copy the two files below.

    The kit supplies the component's behavior and styles; Rust callbacks connect its typed values to your application.

    Open Actions, move with the arrow keys and choose an action. The status displays the chosen label.

    ui/app.slint

    import { KitThemeContext } from "@kit";
    import { InterFont } from "@kit-fonts/inter.slint";
    // SPDX-License-Identifier: GPL-3.0-or-later
    import { KitDropdownMenu, KitTheme, KitThemes } from "@kit";
    
    export component App inherits Window {
        default-font-family: InterFont.family;
        title: "KitDropdownMenu example";
        preferred-width: 480px;
        preferred-height: 320px;
        max-width: 100000px;
        max-height: 100000px;
        background: root.theme.canvas;
        in-out property <KitTheme> theme: KitThemeContext.current;
        in-out property <string> status: "No action yet";
        VerticalLayout {
            padding: 24px;
            spacing: 12px;
            alignment: start;
            KitDropdownMenu {
                theme: root.theme;
                text: "Actions";
                options: [{ token: 11, generation: 1, label: "Rename", description: "Change the project name", disabled: false }, { token: 23, generation: 1, label: "Duplicate", description: "Copy the project", disabled: false }, { token: 38, generation: 1, label: "Archive", description: "Move out of the list", disabled: false }];
                chosen(row) => { root.status = "Chosen: " + row.label; }
            }
            Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; }
        }
    }
    
    

    src/main.rs

    // SPDX-License-Identifier: GPL-3.0-or-later
    slint::include_modules!();
    fn main() -> Result<(), slint::PlatformError> {
        let app = App::new()?;
        slint_kit::install(&app);
        app.run()
    }
    
    

    Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs

    Pass options from Choices<K>::model() and handle chosen(OptionRow); Choices::accept validates the callback and returns its domain key. Call slint_kit::install once per window. Set text for the trigger.

    Placement, dismissal, show(), dismiss(reason), opened() and dismissed(CloseReason) follow KitPopover. Opening focuses the rows; the arrow keys, Home, End, PageUp, PageDown and typeahead move the active row as in KitMenu, Enter or a click chooses it, and the menu then closes, emits chosen and returns focus to the trigger. Disabled rows cannot be chosen. A choice reports programmatic in dismissed. A menu opened by the right button is KitContextMenu; an application sidebar is KitSidebar.

    Control accessibility

    The trigger exposes its expanded state. Rows use the list and list-item roles of KitMenu, because this SDK has no menu roles; Slint 1.18.1 cannot move assistive focus to the active row. Headless tests do not qualify VoiceOver, NVDA or physical IME.

    Visual composition

    The file below describes the captured scene. For controller-driven components, it shows the displayed state without supplying the Rust wiring. Create a project.

    Show the screenshot source
    Trigger button that opens a menu of actions.
    Browser capture of the same Slint example, femtovg renderer.
    import { InterFont } from "@kit-fonts/inter.slint";
    // SPDX-License-Identifier: GPL-3.0-or-later
    import { KitDropdownMenu, KitTheme, KitThemes } from "@kit";
    
    export component Example inherits Window {
        default-font-family: InterFont.family;
        title: "KitDropdownMenu example";
        preferred-width: 480px;
        preferred-height: 320px;
        max-width: 100000px;
        max-height: 100000px;
        background: root.theme.canvas;
        in-out property <KitTheme> theme: KitThemes.light;
        in-out property <string> status: "No action yet";
        VerticalLayout {
            padding: 24px;
            spacing: 12px;
            alignment: start;
            KitDropdownMenu {
                theme: root.theme;
                text: "Actions";
                options: [{ token: 11, generation: 1, label: "Rename", description: "Change the project name", disabled: false }, { token: 23, generation: 1, label: "Duplicate", description: "Copy the project", disabled: false }, { token: 38, generation: 1, label: "Archive", description: "Move out of the list", disabled: false }];
                chosen(row) => { root.status = "Chosen: " + row.label; }
            }
            Text { text: root.status; color: root.theme.text-secondary; font-size: 12px * root.theme.text-scale; }
        }
    }
    
    

    Download this example

    Public API

    Inherits Rectangle.

    Properties

    The "Default" column repeats the initializer declared in the source; "—" is the zero value of the type, and a composite expression points to the source.

    Name Type Direction Default
    modal-layer int in —
    theme KitTheme in KitThemeContext.current
    control-size ControlSize in ControlSize.medium
    intent ButtonIntent in ButtonIntent.secondary
    text string in —
    leading-icon IconGlyph in —
    trailing-icon IconGlyph in root.theme.icons.chevron-down
    accessible-name string in —
    disabled bool in —
    options [OptionRow] in —
    items [MenuItem] in —
    popup-width length in max(root.width, KitMetrics.select-popup-min-width(root.theme))
    open bool out —
    has-focus bool out —

    Property details

    Effect, default, states and constraints of the central properties, with a snippet that uses public mechanisms. Inherited properties carry the explanation of the component that declares them. The complete typed example and the Forms guide wire these properties end to end.

    modal-layer int · in

    The modal layer this component belongs to; 0 is the window. While a KitDialogSurface or KitDrawer with a positive modal-layer is open and topmost, the trigger is inert and show() does nothing. Give a component placed inside a modal that modal's layer number.

    Default
    0 (window).
    KitDropdownMenu {
        modal-layer: 1;
    }

    options [OptionRow] · in

    The rows of the menu, from Choices<K>::model().

    options: root.actions;

    popup-width length · in

    Width of the panel, capped at the window width minus a gap on each side.

    Default
    The larger of the trigger width and the select popup minimum width.
    popup-width: 320px;

    open bool · out

    True while the panel is presented. It turns false when the panel closes for any reason, including a native outside press.

    out property <bool> expanded: control.open;

    has-focus bool · out

    True while the trigger button owns focus.

    out property <bool> trigger-focused: control.has-focus;

    Types and variants

    Type Declaration
    enum ButtonIntent primary, secondary, outline, quiet, destructive, success, warning, information, link
    enum CloseReason escape, outside-press, system-back, trigger-toggle, close-button, programmatic, host-closed
    enum ControlSize compact, medium, comfortable
    struct MenuItem kind: MenuItemKind, leading-icon: IconGlyph, shortcut: string, destructive: bool, checked: bool
    enum MenuItemKind action, checkbox, radio, separator, group
    struct OptionRow token: int, generation: int, label: string, description: string, disabled: bool

    Callbacks

    Functions

    See also