Instead of anti-autofocusing, use a pageload that calls focus().

This commit is contained in:
voussoir 2020-09-17 18:17:08 -07:00
parent f9e4bac186
commit 4c9668c920

View file

@ -123,11 +123,6 @@
} }
#left #left
{ {
/*
Display: none will be returned back to flex as soon as the page detects
that the screen is in narrow mode and turns off the tag box's autofocus.
*/
display: none;
width: initial; width: initial;
max-width: none; max-width: none;
} }
@ -157,7 +152,7 @@
<h4>Tags</h4> <h4>Tags</h4>
<ul id="this_tags"> <ul id="this_tags">
<li> <li>
<input type="text" id="add_tag_textbox" class="entry_with_history entry_with_tagname_replacements" list="tag_autocomplete_datalist" autofocus> <input type="text" id="add_tag_textbox" class="entry_with_history entry_with_tagname_replacements" list="tag_autocomplete_datalist">
<button id="add_tag_button" class="green_button" onclick="return add_photo_tag_form();">add</button> <button id="add_tag_button" class="green_button" onclick="return add_photo_tag_form();">add</button>
</li> </li>
{% set tags = photo.get_tags()|sort_tags %} {% set tags = photo.get_tags()|sort_tags %}
@ -563,22 +558,25 @@ function move_hoverzoom(event)
tag_autocomplete.init_datalist(); tag_autocomplete.init_datalist();
setTimeout( function autofocus_add_tag_box()
{
/* /*
When the screen is in column mode, the autofocusing of the tag box snaps the If the add_tag_box has autofocus set by the HTML, then when the screen is
screen down to it, which is annoying. By starting the #left hidden, we have in narrow mode, the autofocusing of the tag box snaps the screen down to it,
an opportunity to unset the autofocus before showing it. which is annoying. So, this function focuses the box manually as long as
we're not narrow.
*/ */
function()
{
const content_body = document.getElementById("content_body"); const content_body = document.getElementById("content_body");
if (getComputedStyle(content_body).getPropertyValue("--narrow") == 1) if (getComputedStyle(content_body).getPropertyValue("--narrow") == 0)
{ {
add_tag_box.autofocus = false; add_tag_box.focus();
} }
document.getElementById("left").style.display = "flex"; }
},
0 function on_pageload()
); {
autofocus_add_tag_box();
}
document.addEventListener("DOMContentLoaded", on_pageload);
</script> </script>
</html> </html>