Skip to content

Cooperation between focus components #6390

Open
@FloVanGH

Description

@FloVanGH

Currently it is really hard to implement something like an autocomplete box. Where you need an element e.g. LineEdit to enter text to filter your list and to check for down arrow and up arrow key events to navigate between the items in your list.

Example

import { LineEdit, StandardListView, VerticalBox } from "std-widgets.slint";

export component Demo {
    forward-focus: search;

    in property <[StandardListViewItem]> model: [
        { text: "Item 1" },
        { text: "Item 2" },
        { text: "Item 3" },
    ];

    callback filter_model(/* filter_text */ string);

    FocusScope {
        VerticalBox {
            search := LineEdit {
                placeholder-text: "search";

                edited(text) => {
                    root.filter_model(text);
                }
            }

            list := StandardListView {
                current-item: 0;
                model: root.model;
            }
        }

        key-pressed(event) => {
            if event.text == Key.UpArrow {
                list.current-item = max(list.current-item - 1, 0);
                return accept;
            }
            if event.text == Key.DownArrow {
                list.current-item = min(list.current-item + 1, list.model.length - 1);
                return accept;
            }
            reject
        }
    }

The problem is if LineEdit has focus then FocuScope does not have focus and you cannot check if the arrow keys are pressed.

We should start to think and define how a solution for this problem could looks like.

One thing that could be possible is something like Routed Events in WPF, with bubbling events from source to leafs and after that from the leafs back to source. An eventhandler that is part of this path can decided if it wants to handle (accept) the event or to reject it, what means the next event handler has the opportunity to handle the event instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rfcRequest for comments: proposals for changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions