MCPcopy
hub / github.com/callumalpass/tasknotes / TextInputModal

Class TextInputModal

src/modals/TextInputModal.ts:15–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 * Generic text input modal
14 */
15export class TextInputModal extends Modal {
16 private options: TextInputModalOptions;
17 private resolve: (value: string | null) => void;
18 private inputEl: HTMLInputElement;
19
20 constructor(app: App, options: TextInputModalOptions) {
21 super(app);
22 this.options = {
23 confirmText: "Confirm",
24 cancelText: "Cancel",
25 ...options,
26 };
27 }
28
29 public show(): Promise<string | null> {
30 return new Promise((resolve) => {
31 this.resolve = resolve;
32 this.open();
33 });
34 }
35
36 onOpen() {
37 const { contentEl } = this;
38 contentEl.empty();
39
40 new Setting(contentEl).setName(this.options.title).setHeading();
41
42 new Setting(contentEl).addText((text) => {
43 this.inputEl = text.inputEl;
44 text.setPlaceholder(this.options.placeholder || "")
45 .setValue(this.options.initialValue || "")
46 .onChange(() => {
47 // Optional: real-time validation could go here
48 });
49
50 // Focus the input
51 window.setTimeout(() => {
52 this.inputEl.focus();
53 this.inputEl.select();
54 }, 100);
55
56 this.options.onInputReady?.(this.inputEl);
57 });
58
59 const buttonContainer = contentEl.createEl("div", { cls: "modal-button-container" });
60 buttonContainer.classList.remove(
61 "tn-static-display-block-2a1b75c9",
62 "tn-static-display-flex-4d51fc62",
63 "tn-static-display-flex-8bb39979",
64 "tn-static-display-inline-block-60e32dcb",
65 "tn-static-display-inline-cccfa456",
66 "tn-static-display-inline-flex-f984c520",
67 "tn-static-display-none-6b99de8b",
68 "tn-static-min-height-800px-997b4c8c"
69 );
70 buttonContainer.classList.add("tn-static-display-flex-75816cae");
71 buttonContainer.classList.remove(
72 "tn-static-display-flex-8bb39979",

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected