feat: preventDefault on Enter

This commit is contained in:
neoapps-dev
2026-09-03 12:31:03 +03:00
parent 1311a55932
commit f92e1e77de
14 changed files with 27 additions and 3 deletions
+1
View File
@@ -523,6 +523,7 @@ const SkinViewer = memo(function SkinViewer({
} else if (e.key === "ArrowUp") { } else if (e.key === "ArrowUp") {
setFocusIndex((prev) => (prev > 0 ? prev - 1 : prev)); setFocusIndex((prev) => (prev > 0 ? prev - 1 : prev));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === 0) { if (focusIndex === 0) {
( (
containerRef.current?.querySelector("input") as HTMLElement containerRef.current?.querySelector("input") as HTMLElement
@@ -119,6 +119,7 @@ export default function ChooseInstanceModal({
const max = 1 + (validInstances.length > 0 ? 1 : 0) + 1; const max = 1 + (validInstances.length > 0 ? 1 : 0) + 1;
setFocusIndex((prev) => (prev - 1 + max) % max); setFocusIndex((prev) => (prev - 1 + max) % max);
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === 0 && validInstances.length > 0) { if (focusIndex === 0 && validInstances.length > 0) {
const currentIdx = validInstances.findIndex( const currentIdx = validInstances.findIndex(
(i: Edition) => i.instanceId === selectedInstance, (i: Edition) => i.instanceId === selectedInstance,
+1
View File
@@ -86,6 +86,7 @@ export default function CustomTUModal({
playBackSound("close_click.wav"); playBackSound("close_click.wav");
onClose(); onClose();
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === 3) { if (focusIndex === 3) {
playBackSound("close_click.wav"); playBackSound("close_click.wav");
onClose(); onClose();
+1
View File
@@ -58,6 +58,7 @@ export default function CustomizeModal({
playBackSound("close_click.wav"); playBackSound("close_click.wav");
onClose(); onClose();
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === 4) { if (focusIndex === 4) {
playBackSound("close_click.wav"); playBackSound("close_click.wav");
onClose(); onClose();
+1
View File
@@ -103,6 +103,7 @@ export default function SetUidModal({
e.preventDefault(); e.preventDefault();
setFocusIndex((prev) => (prev - 1 + 5) % 5); setFocusIndex((prev) => (prev - 1 + 5) % 5);
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === 0) { if (focusIndex === 0) {
playPressSound(); playPressSound();
setMode("manual"); setMode("manual");
+1
View File
@@ -72,6 +72,7 @@ export default function DevtoolsView() {
setFocusIndex(0); setFocusIndex(0);
} }
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === BACK_BUTTON_INDEX) { if (focusIndex === BACK_BUTTON_INDEX) {
playBackSound(); playBackSound();
setActiveView("main"); setActiveView("main");
+1
View File
@@ -100,6 +100,7 @@ export default function GuidesView() {
} else if (e.key === "ArrowUp") { } else if (e.key === "ArrowUp") {
setFocusIndex((p) => (p <= 0 ? BACK_BUTTON_INDEX : p - 1)); setFocusIndex((p) => (p <= 0 ? BACK_BUTTON_INDEX : p - 1));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === BACK_BUTTON_INDEX) { if (focusIndex === BACK_BUTTON_INDEX) {
goBack(); goBack();
} else { } else {
+3 -1
View File
@@ -135,8 +135,10 @@ const HomeView = memo(function HomeView() {
prev === null ? buttonsVal.length - 1 : prev > 0 ? prev - 1 : prev, prev === null ? buttonsVal.length - 1 : prev > 0 ? prev - 1 : prev,
); );
if (e.key === "ArrowLeft") onNavigateToSkin(); if (e.key === "ArrowLeft") onNavigateToSkin();
if (e.key === "Enter" && menuFocus !== null) if (e.key === "Enter" && menuFocus !== null) {
e.preventDefault();
buttonsVal[menuFocus].action(); buttonsVal[menuFocus].action();
}
}; };
window.addEventListener("keydown", handleKey); window.addEventListener("keydown", handleKey);
return () => window.removeEventListener("keydown", handleKey); return () => window.removeEventListener("keydown", handleKey);
+1
View File
@@ -348,6 +348,7 @@ const LceOnlineView = memo(function LceOnlineView({
prev === null || prev <= 0 ? itemCount - 1 : prev - 1, prev === null || prev <= 0 ? itemCount - 1 : prev - 1,
); );
} else if (e.key === "Enter" && focusIndex !== null) { } else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
menuItems[focusIndex]?.onClick(); menuItems[focusIndex]?.onClick();
} }
} }
+3
View File
@@ -73,6 +73,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
playPressSound(); playPressSound();
setDeleteConfirmFocusIndex((prev) => (prev === 0 ? 1 : 0)); setDeleteConfirmFocusIndex((prev) => (prev === 0 ? 1 : 0));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (deleteConfirmFocusIndex === 1) confirmDelete(); if (deleteConfirmFocusIndex === 1) confirmDelete();
else { else {
playBackSound(); playBackSound();
@@ -94,6 +95,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
playPressSound(); playPressSound();
setModalFocusIndex((prev) => (prev < 2 ? prev + 1 : 0)); setModalFocusIndex((prev) => (prev < 2 ? prev + 1 : 0));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (modalFocusIndex === 0) handleOpenFolder(selectedScreenshot); if (modalFocusIndex === 0) handleOpenFolder(selectedScreenshot);
else if (modalFocusIndex === 1) { else if (modalFocusIndex === 1) {
playPressSound(); playPressSound();
@@ -124,6 +126,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
prev <= screenshots.length - 1 - cols ? prev + cols : prev, prev <= screenshots.length - 1 - cols ? prev + cols : prev,
); );
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (screenshots[gridFocusIndex]) { if (screenshots[gridFocusIndex]) {
playPressSound(); playPressSound();
setModalFocusIndex(2); setModalFocusIndex(2);
+1
View File
@@ -775,6 +775,7 @@ const SettingsView = memo(function SettingsView() {
item.onChange(newVal); item.onChange(newVal);
} }
} else if (e.key === "Enter" && focusIndex !== null) { } else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
const item = settingsItems[focusIndex]; const item = settingsItems[focusIndex];
if (item.type === "button") { if (item.type === "button") {
item.onClick(); item.onClick();
+1
View File
@@ -127,6 +127,7 @@ const SetupView: React.FC<SetupViewProps> = ({ onComplete }) => {
e.preventDefault(); e.preventDefault();
setFocusIndex((prev) => (prev - 1 + count) % count); setFocusIndex((prev) => (prev - 1 + count) % count);
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (currentStep === 0) { if (currentStep === 0) {
if (focusIndex === 0) handleNext(); if (focusIndex === 0) handleNext();
else if (focusIndex === 1) handleNext(); else if (focusIndex === 1) handleNext();
+1
View File
@@ -366,6 +366,7 @@ const SkinsView = memo(function SkinsView() {
setFocusIndex(next < SKINS_START_INDEX ? 0 : next); setFocusIndex(next < SKINS_START_INDEX ? 0 : next);
} }
} else if (e.key === "Enter" && focusIndex !== null) { } else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
if (focusIndex === 0) { if (focusIndex === 0) {
if (viewMode === "skin") handleImportClick(); if (viewMode === "skin") handleImportClick();
else capeFileInputRef.current?.click(); else capeFileInputRef.current?.click();
+10 -2
View File
@@ -688,6 +688,7 @@ const WorkshopView = memo(function WorkshopView({
setFocusedIdx((p) => Math.max((p ?? 1) - (isPluginTab ? 1 : COLS), 0)); setFocusedIdx((p) => Math.max((p ?? 1) - (isPluginTab ? 1 : COLS), 0));
playPressSound(); playPressSound();
} else if (e.key === "Enter" && focusedIdx !== null) { } else if (e.key === "Enter" && focusedIdx !== null) {
e.preventDefault();
const pkg = filteredItems[focusedIdx]; const pkg = filteredItems[focusedIdx];
if (pkg) openModal(pkg); if (pkg) openModal(pkg);
} }
@@ -1402,6 +1403,7 @@ function PackageModal({
return focusOptions[(idx + 1) % focusOptions.length]; return focusOptions[(idx + 1) % focusOptions.length];
}); });
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (modalFocus === "close") onClose(); if (modalFocus === "close") onClose();
else if (modalFocus === "install") handleAction(); else if (modalFocus === "install") handleAction();
else if (modalFocus === "uninstall") setShowUninstall(true); else if (modalFocus === "uninstall") setShowUninstall(true);
@@ -2171,8 +2173,10 @@ function InstallModal({
e.stopPropagation(); e.stopPropagation();
if (status === "installing") return; if (status === "installing") return;
if (status === "success") { if (status === "success") {
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") {
e.preventDefault();
onClose(); onClose();
}
return; return;
} }
@@ -2187,6 +2191,7 @@ function InstallModal({
playPressSound(); playPressSound();
setFocusedIdx((p) => Math.min(p + 1, editionOptions.length - 1)); setFocusedIdx((p) => Math.min(p + 1, editionOptions.length - 1));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (editionOptions.length > 0) { if (editionOptions.length > 0) {
installTo(editionOptions[focusedIdx].instanceId); installTo(editionOptions[focusedIdx].instanceId);
} }
@@ -2480,8 +2485,10 @@ function UninstallModal({
e.stopPropagation(); e.stopPropagation();
if (status === "removing") return; if (status === "removing") return;
if (status === "success") { if (status === "success") {
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") {
e.preventDefault();
onClose(); onClose();
}
return; return;
} }
@@ -2496,6 +2503,7 @@ function UninstallModal({
playPressSound(); playPressSound();
setFocusedIdx((p) => Math.min(p + 1, installedEntries.length - 1)); setFocusedIdx((p) => Math.min(p + 1, installedEntries.length - 1));
} else if (e.key === "Enter") { } else if (e.key === "Enter") {
e.preventDefault();
if (installedEntries.length > 0) { if (installedEntries.length > 0) {
uninstallFrom(installedEntries[focusedIdx].instanceId); uninstallFrom(installedEntries[focusedIdx].instanceId);
} }