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