fix(useButtonNavigation): wrong click navigation
This commit is contained in:
@@ -9,7 +9,7 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
|
|||||||
buttons: T;
|
buttons: T;
|
||||||
initialButton: keyof T;
|
initialButton: keyof T;
|
||||||
onButtonClick?: (buttonName: keyof T) => void;
|
onButtonClick?: (buttonName: keyof T) => void;
|
||||||
navigation?: Record<
|
navigation: Record<
|
||||||
keyof T,
|
keyof T,
|
||||||
{
|
{
|
||||||
up?: keyof T;
|
up?: keyof T;
|
||||||
@@ -35,6 +35,13 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
|
|||||||
if (selectedButton.value === buttonName) {
|
if (selectedButton.value === buttonName) {
|
||||||
onButtonClick?.(buttonName);
|
onButtonClick?.(buttonName);
|
||||||
} else {
|
} else {
|
||||||
|
if (
|
||||||
|
navigation[buttonName].down === "last" &&
|
||||||
|
navigation[selectedButton.value]!.up === buttonName
|
||||||
|
) {
|
||||||
|
nextButton.value = selectedButton.value;
|
||||||
|
}
|
||||||
|
|
||||||
selectedButton.value = buttonName;
|
selectedButton.value = buttonName;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -42,7 +49,6 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (navigation) {
|
|
||||||
const handleKeyPress = (event: KeyboardEvent) => {
|
const handleKeyPress = (event: KeyboardEvent) => {
|
||||||
const currentButton = selectedButton.value as keyof T;
|
const currentButton = selectedButton.value as keyof T;
|
||||||
const currentNav = navigation[currentButton];
|
const currentNav = navigation[currentButton];
|
||||||
@@ -100,6 +106,9 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
|
|||||||
case " ":
|
case " ":
|
||||||
onButtonClick?.(selectedButton.value);
|
onButtonClick?.(selectedButton.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -112,7 +121,6 @@ export const useButtonNavigation = <T extends Record<string, ButtonConfig>>({
|
|||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener("keydown", handleKeyPress);
|
window.removeEventListener("keydown", handleKeyPress);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedButton,
|
selectedButton,
|
||||||
|
|||||||
Reference in New Issue
Block a user