Skip to content

Item Extra outside of bounds when not initially shown #184

Closed
@jtreminio

Description

@jtreminio

Using the example here:

https://github.com/php-school/cli-menu/blob/master/examples/toggle-item-extra.php

but changing the following

->addItem('First Item', $itemCallable, true)
->addItem('Second Item', $itemCallable, true)
->addItem('Third Item', $itemCallable, true)

to

->addItem('First Item', $itemCallable, false)
->addItem('Second Item', $itemCallable, false)
->addItem('Third Item', $itemCallable, false)

creates the item-extra string outside of terminal window:

image

Toggling the items to trigger $item->hideItemExtra() does not hide the item-extra strings.

A workaround is passing true to addItem() then looping through all items and hiding item-extra:

    $itemCallable = function (CliMenu $menu) {
        $item = $menu->getSelectedItem();

        $item->showsItemExtra()
            ? $item->hideItemExtra()
            : $item->showItemExtra();

        $menu->redraw();
    };

    $menu = (new CliMenuBuilder)
        ->setTitle('Basic CLI Menu')
        ->addItem('Option 1', $itemCallable, true)
        ->addItem('Option 2', $itemCallable, true)
        ->addItem('Option 3', $itemCallable, true)
        ->addLineBreak('-')
        ->build();

    foreach ($menu->getItems() as $item) {
        $item->hideItemExtra();
    }

    $menu->open();

This shows an initial list without the item-extra string, allows toggling an item to show item-extra, and allows toggling again to hide the item-extra string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions