Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions frontend/src/components/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const ConfirmModal: React.FC<ConfirmModalProps> = ({
const confirmButtonRef = useRef<HTMLButtonElement>(null);
const previousFocusRef = useRef<HTMLElement | null>(null);

// Focus trap and keyboard handling
useEffect(() => {
if (!isOpen) return;

Expand All @@ -40,6 +41,8 @@ export const ConfirmModal: React.FC<ConfirmModalProps> = ({
if (e.key === 'Escape') {
onCancel();
} else if (e.key === 'Enter' && !e.shiftKey) {
// Only trigger onConfirm if the active element is NOT a button
// (buttons already handle Enter via their onClick)
const activeElement = document.activeElement;
if (activeElement?.tagName !== 'BUTTON') {
e.preventDefault();
Expand Down Expand Up @@ -73,6 +76,23 @@ export const ConfirmModal: React.FC<ConfirmModalProps> = ({
};
}, [isOpen, onConfirm, onCancel]);

// Lock body scroll when modal opens
useEffect(() => {
if (!isOpen) return;

const originalOverflow = document.body.style.overflow;
const originalPaddingRight = document.body.style.paddingRight;
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;

document.body.style.overflow = 'hidden';
document.body.style.paddingRight = `${scrollbarWidth}px`;

return () => {
document.body.style.overflow = originalOverflow;
document.body.style.paddingRight = originalPaddingRight;
};
}, [isOpen]);

if (!isOpen) return null;

const getButtonStyle = () => {
Expand Down
Loading