Closing a dialog from code

For my Search in resources plugin I am trying to create a search dialog similar to Joplin's "Goto Anything".
For this I need to be able to close the dialog from JS code. There does not seem to be a way to do this at the moment, can it be added please?

The dialog will already close when pressing ENTER, could that already solve your problem?

There's actually a close method but I thought it didn't need to be exposed since it's a modal dialog, thus it needs user action to close it. But maybe it should be exposed for some cases then.

It doesn't close. Not sure whether it's because I remove the buttons (they don't make sense for such dialog) or because I install a custom keydown event handler (though I do not call preventDefault when handling enter).