Focus on the rename text area when it becomes visible

This commit is contained in:
oobabooga 2024-01-09 04:00:47 -08:00
parent 6e9d814095
commit 4d730a759a

View File

@ -397,3 +397,31 @@ function updateDocumentWidth() {
updateDocumentWidth();
window.addEventListener("resize", updateDocumentWidth);
//------------------------------------------------
// Focus on the rename text area when it becomes visible
//------------------------------------------------
const renameTextArea = document.getElementById('rename-row').querySelector('textarea');
function respondToVisibility(element, callback) {
var options = {
root: document.documentElement,
};
var observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
callback(entry.intersectionRatio > 0);
});
}, options);
observer.observe(element);
}
function handleVisibilityChange(isVisible) {
if (isVisible) {
renameTextArea.focus();
}
}
respondToVisibility(renameTextArea, handleVisibilityChange);