Skip to content

Commit b048847

Browse files
committed
Add the Modal/Cart Dismissal Interaction for the Esc key
1 parent 87ea5e1 commit b048847

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/components/bucket-modal.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useStore } from '@/lib/store';
44
import { X, Trash2, Package } from 'lucide-react';
55
import { VersionNote } from './version-note';
6+
import { useEffect } from 'react';
67

78
interface BucketModalProps {
89
onClose: () => void;
@@ -16,11 +17,19 @@ export function BucketModal({ onClose }: BucketModalProps) {
1617
setCurrentStep('output');
1718
};
1819

20+
useEffect(() => {
21+
const handleKey = (e: KeyboardEvent) => {
22+
if (e.key === 'Escape') onClose();
23+
};
24+
window.addEventListener('keydown', handleKey);
25+
return () => window.removeEventListener('keydown', handleKey);
26+
}, [onClose]);
27+
1928
return (
2029
<>
2130
{/* Backdrop */}
2231
<div
23-
className="fixed inset-0 z-40"
32+
className="fixed inset-0 z-40 bg-black/40 backdrop-blur-[2px]"
2433
onClick={onClose}
2534
/>
2635

src/components/presets-modal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useStore } from '@/lib/store';
44
import { presets } from '@/lib/presets';
55
import { appCatalog } from '@/lib/apps';
66
import { X, Clock, Layers, Check } from 'lucide-react';
7-
import { useState } from 'react';
7+
import { useState, useEffect } from 'react';
88
import { estimateInstallTime } from '@/lib/script-generator';
99
import { Package } from '@/types';
1010

@@ -16,6 +16,14 @@ export function PresetsModal({ onClose }: PresetsModalProps) {
1616
const { loadPreset, bucket, os } = useStore();
1717
const [applied, setApplied] = useState<string | null>(null);
1818

19+
useEffect(() => {
20+
const handleKey = (e: KeyboardEvent) => {
21+
if (e.key === 'Escape') onClose();
22+
};
23+
window.addEventListener('keydown', handleKey);
24+
return () => window.removeEventListener('keydown', handleKey);
25+
}, [onClose]);
26+
1927
const handleApply = (presetId: string, packageIds: string[]) => {
2028
loadPreset(packageIds);
2129
setApplied(presetId);

0 commit comments

Comments
 (0)