Scroll into view on enter keypress in search bar

This commit is contained in:
Danny Robinson 2022-07-31 04:36:10 +01:00 committed by GitHub
parent c6e85d5cc0
commit 8d9c46bedc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -716,11 +716,18 @@ document.addEventListener('DOMContentLoaded', function () {\n\
option.setAttribute('value', el.id)\n\ option.setAttribute('value', el.id)\n\
datalist.appendChild(option)\n\ datalist.appendChild(option)\n\
})\n\ })\n\
document.getElementById('search').addEventListener('change', function (event) {\n\ function scrollIntoView(event) {\n\
var value = event.target.value\n\ var value = event.target.value\n\
if (document.getElementById(value)) {\n\ var el = document.getElementById(value) \n\
if (el) {\n\
location.hash = value\n\ location.hash = value\n\
el.scrollIntoView()\n\
}\n\ }\n\
}\n\
var search = document.getElementById('search')\n\
search.addEventListener('change', scrollIntoView)\n\
search.addEventListener('keypress', function (event) {\n\
if (event.key === 'Enter') scrollIntoView(event)\n\
})\n\ })\n\
})\n\ })\n\
</script>\n\n"); </script>\n\n");