Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click on a non-focused Column Menu could not update the menu title #220

Open
benlau opened this issue Dec 10, 2022 · 0 comments
Open

Click on a non-focused Column Menu could not update the menu title #220

benlau opened this issue Dec 10, 2022 · 0 comments

Comments

@benlau
Copy link

benlau commented Dec 10, 2022

Hello,

I would like to update the content of a menu item inside the ColumnMenu on mouse click using the ColumnMenu.setItem function.

However, I find that it doesn't work if the ColumnMenu don't even have a focus. Here is the code:

(Remarks: Terminal-kit version: 3.0.0)

const termkit = require("terminal-kit");
const term = require("terminal-kit").terminal;

const document = term.createDocument();

const items = [
    { content: "Item 1       ", key: "1", value:"1" },
    { content: "Item 2       ", key: "2", value:"2" },
]

const columnMenu = new termkit.ColumnMenu({
    parent: document,
    x: 0,
    y: 0,
    items,
});

columnMenu.on("submit", (key) => {
    columnMenu.setItem(key, {content: "Pressed item"});
});

term.on("key", (key) => {
    if (key === "ESCAPE") {
        process.exit(0);
    }
});

After launched the program, it will show a column menu :

Item 1
Item 2

If you trigger a submit event, it should update the submitted menu item's title to "Pressed item".

However, if I click on the item by mouse just after launched, it will trigger the blink effect and submit event but the menu title won't be updated.

Did I do something wrong or it is a bug?

The problem will gone if I call document.giveFocusTo(columnMenu) but it is not an ideal solution as I have another input component with default focus. Currently, I solve this problem by a dirty hack of switching focus:

document.giveFocusTo(columnMenu);
setTimeout(() => {
   document.giveFocusTo(textInput); // The input component with default focus.
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant