Attempt to fix column focus bug

This commit is contained in:
Lim Chee Aun 2024-11-14 19:22:26 +08:00
parent c9295ba48e
commit 6a4e14267a
2 changed files with 31 additions and 2 deletions

View file

@ -107,6 +107,18 @@ function Columns() {
states.showShortcutsSettings = true; states.showShortcutsSettings = true;
} }
}} }}
onFocus={() => {
// Get current focused column
const currentFocusedColumn =
document.activeElement.closest('#columns > *');
if (currentFocusedColumn) {
// Remove focus classes from all columns
// Add focus class to current focused column
document.querySelectorAll('#columns > *').forEach((column) => {
column.classList.toggle('focus', column === currentFocusedColumn);
});
}
}}
> >
{components} {components}
</div> </div>

View file

@ -2,8 +2,25 @@ const focusDeck = () => {
let timer = setTimeout(() => { let timer = setTimeout(() => {
const columns = document.getElementById('columns'); const columns = document.getElementById('columns');
if (columns) { if (columns) {
// Focus focused column
const focusedColumn = columns.querySelector('.deck-container.focus');
if (focusedColumn) {
focusedColumn.focus();
} else {
// Focus first column within viewport
const firstVisibleColumn = columns
.querySelectorAll('.deck-container')
.find((column) => {
const columnRect = column.getBoundingClientRect();
return columnRect.left >= 0;
});
if (firstVisibleColumn) {
firstVisibleColumn.focus();
} else {
// Focus first column // Focus first column
columns.querySelector('.deck-container')?.focus?.(); columns.querySelector('.deck-container')?.focus?.();
}
}
} else { } else {
const modals = document.querySelectorAll('#modal-container > *'); const modals = document.querySelectorAll('#modal-container > *');
if (modals?.length) { if (modals?.length) {