Skip to content

Commit

Permalink
Focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoonDorise committed Nov 19, 2023
1 parent 71ba386 commit c2f5aee
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
2 changes: 1 addition & 1 deletion src/renderer/components
41 changes: 0 additions & 41 deletions src/renderer/pages/WelcomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -681,47 +681,6 @@ function WelcomePage() {
const domElementsCur = domElementsRef.current;
let domElements;

// Keys Movement
const keyFunction = useCallback(
(event) => {
if (dom !== undefined) {
let newFocus = domFocus || 0; // Inicializa en 0 si es undefined

switch (event.key) {
case 'ArrowRight':
case 'ArrowLeft':
case 'ArrowUp':
case 'ArrowDown':
newFocus +=
event.key === 'ArrowDown' || event.key === 'ArrowRight' ? 1 : -1;
break;
default:
break;
}

setStateNavigation({
domFocus: Math.max(0, Math.min(newFocus, dom.length - 1)),
});
}
},
[domFocus, setStateNavigation, dom]
);

useEffect(() => {
if (dom && domFocus) {
console.log({ domFocus });
dom[domFocus].focus();
}
}, [domFocus, dom]);

useEffect(() => {
document.addEventListener('keydown', keyFunction, false);

return () => {
document.removeEventListener('keydown', keyFunction, false);
};
}, [keyFunction]);

useEffect(() => {
if (dom === undefined) {
domElements = document.querySelectorAll('button');
Expand Down

0 comments on commit c2f5aee

Please sign in to comment.