Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Prompt input is not focused on mobile

Open mihaiconstantin opened this issue 2 years ago • 6 comments

Please consider the following template:

<%-*
let textPromise = tp.system.prompt("Type something...", multiline = true)
let textValue = await textPromise
_%>

<% textValue %>

Upon inspecting the HTML it seems that the input in the modal is lacking the autofocus attribute, as seen below:

Input lacking autofocus attribute

Because of this, when the template is triggered on mobile, the input is not focused, i.e.:

Input out of focus on mobile

I can work around this, by focusing the element programmatically, i.e.:

<%-*
let textPromise = tp.system.prompt("Type something...", multiline = true)

// Focus the input element programmatically.
document.getElementsByClassName("templater-prompt-input")[0].focus()

let textValue = await textPromise
_%>

<% textValue %>

But I think it would be helpful, and unobtrusive if you add the autofocus attribute on the prompt element. This way, the prompt input will also behave in line with its suggester counterpart.

Also, thanks a lot for the awesome plugin!

mihaiconstantin avatar Jun 03 '23 11:06 mihaiconstantin

Hello @mihaiconstantin !!!

I can work around this, by focusing the element programmatically, i.e.:

I just wanna say thank for sharing this script 🙏

I have been struggling with focus on prompt on Mobile for a long time and your script saved me on this issue.

I hope we can get a fix for this on a future release 🙏

Again, thank you very much for sharing this script, you have no idea how happy I am to finally be able to get the focus on my prompts :)

I wish you a fantastic day ☀️

FelipeRearden avatar Jun 03 '23 13:06 FelipeRearden

@FelipeRearden, I'm glad to hear it helps. If you need to apply the above to more complex scenarios than maybe these scripts will help as well. For example, check out the prompt user scrip.

mihaiconstantin avatar Jun 03 '23 18:06 mihaiconstantin

Woowww @mihaiconstantin this is amazing, thank you very much for sharing and creating this amazing site.

I am gonna read the scripts and I am sure that I will improve my workflow using your scripts !

Have a great day!

FelipeRearden avatar Jun 03 '23 19:06 FelipeRearden

Hey Mihai, want to push a PR that adds this?

AB1908 avatar Jun 04 '23 22:06 AB1908

Hey @AB1908, sure thing, will submit a PR.

mihaiconstantin avatar Jun 05 '23 05:06 mihaiconstantin

Unfortunately, adding the autofocus attribute on the input element doesn't appear to resolve the issue on mobile. I've tried a few other options like running the .focus() method on the input element and even using document.getElementsByClassName("templater-prompt-input")[0].focus(), but no dice. Only works if I add it to the template, not in the Templater code.

I'm sure there's something simple I'm missing.

Zachatoo avatar Oct 04 '23 04:10 Zachatoo