Issues with TextField in Menu

I put a TextField in a Menu and it works except 2 issues:

  • when enetering the TextField a submenu from another menu entry doesn’t disappear

  • after closing the menu with the enter-key (cursor is in the TextField), I need 2 right-clicks to show up the menu again

here’s the code from my TextField:

struct TapeNameMenuItem : TextField {
	TapeNameDisplay* tapeNameDisplay;
	Menu* menu;

	void onAction(const event::Action& e) override {
		TextField::onAction(e);
		menu->requestDelete();
	}
	void onChange(const event::Change& e) override {
		TextField::onChange(e);
		tapeNameDisplay->text = text;
	}
};

and here is the code that places the TextField into the menu:

	TapeNameMenuItem* tapeName = new TapeNameMenuItem;
	tapeName->box.size = Vec(120, 20);
	tapeName->multiline = false;
	tapeName->text = tapeNameDisplay->text;
	tapeName->tapeNameDisplay = tapeNameDisplay;
	tapeName->menu = menu;
	menu->addChild(tapeName);

My suggestion is that the TextField is not selected correctly as a menu item. I tried this code I found in ParamField (that derived from TextField too) but it didn’t work:

void step() override {
	// Keep selected
	APP->event->setSelected(this);
	TextField::step();
}

Does anyone have any ideas?

I solved the 2nd problem (after closing the menu with the enter-key when cursor is in the TextField, I need 2 right-clicks to show up the menu again)

by using

getAncestorOfType<ui::MenuOverlay>()->requestDelete();

instead of

menu->requestDelete();