Skip to content

Commit

Permalink
style: lint 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Todari committed Jan 30, 2025
1 parent 339bea4 commit 25f180b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions client/src/components/Modal/BankSelectModal/BankSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type BankSelectProps = {

const BankSelectModal = ({isBottomSheetOpened, onClose, selectBank}: BankSelectProps) => {
const modalRef = useRef<HTMLDivElement>(null);
const closeButtonRef = useRef<HTMLButtonElement>(null);

const selectBankAndClose = (name: BankName) => {
selectBank(name);
Expand All @@ -29,9 +28,6 @@ const BankSelectModal = ({isBottomSheetOpened, onClose, selectBank}: BankSelectP
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
);
const firstFocusable = focusableElements?.[0] as HTMLElement;
if (document.activeElement !== firstFocusable) {
(focusableElements?.[1] as HTMLElement).focus();
}
const lastFocusable = focusableElements?.[focusableElements.length - 1] as HTMLElement;

const handleTabKey = (e: KeyboardEvent) => {
Expand All @@ -50,11 +46,20 @@ const BankSelectModal = ({isBottomSheetOpened, onClose, selectBank}: BankSelectP
}
};

const handleFocusChange = () => {
const isModalElement = Array.from(focusableElements ?? []).some(element => element === document.activeElement);

if (!isModalElement) {
(focusableElements?.[1] as HTMLElement)?.focus();
}
};

document.addEventListener('keydown', handleTabKey);
closeButtonRef.current?.focus();
document.addEventListener('focusin', handleFocusChange);

return () => {
document.removeEventListener('keydown', handleTabKey);
document.removeEventListener('focusin', handleFocusChange);
};
}, [isBottomSheetOpened]);

Expand Down

0 comments on commit 25f180b

Please sign in to comment.