Initial query for SuggestModal

Sometimes you need to provide an initial query inside SuggestModal or FuzzySuggestModal

Currently I am using the following workaround

class MyModal<T> extends SuggestModal<T> {
    constructor(private initialQuery?: string) {
    }

    onOpen(): {
        if (this.initialQuery) {
            this.inputEl.value = this.initialQuery;
            this.inputEl.dispatchEvent(new InputEvent("input"));
        }
    }
}

But I consider this trick with inputElement as a fragile dirty hack and it would be much better if this is supported by Obsidian API directly such as

export abstract class SuggestModal<T> extends Modal implements ISuggestOwner<T> {
    ...

    /**
     * @public
     */
    getInitialQuery(): string | null;
}

Can this be done using pure Javascript, and not TypeScript?

I found this thread when working with the thread below, almost at the same time I saw the plugin Link with alias. But could this type of modal / class extension be done from within dataviewjs or a javascript block in Templater (or some other javascript block)?

@holroy yes, it can be done using just JavaScript, however it’s a bit tricky because we don’t have an easy access to the obsidian module which we need to get access to SuggestModal base class. It’s easier to access obsidian module from the Templater code because they have tp.obsidian. However from dataviewjs it’s way more difficult.

I have a plugin that addresses this issue: GitHub - mnaoumov/obsidian-fix-require-modules: Obsidian Plugin that fixes `require()` calls for the built-in modules