feat(blog): 모달 오버레이 배경 격리 — portal + inert (#106)#127
Merged
Conversation
- hooks/use-modal-a11y.ts 신설: 사이드바·검색 모달이 공유하는 배경 격리 훅 - body 스크롤 잠금(useBodyScrollLock 재사용) + 배경 콘텐츠 inert 적용/복구를 일원화 - 여러 모달 동시 오픈(예: 사이드바 연 채 Cmd+K)에도 안전하도록 참조 카운트로 추적 - createPortal용 mounted 가드 제공(SSR엔 document 없음) - mobile-sidebar.tsx / search-modal.tsx: 패널을 document.body에 직접 포털 렌더 + useModalA11y로 전환, aria-modal="true" (재)부여 — 이제 배경이 실제로 격리되어 스크린리더 가상 커서/스와이프가 배경으로 새지 않음 - 기존 테스트: 포털 렌더로 container 스코프 밖으로 나간 부분을 document 쿼리로 수정 - 신규 테스트: 배경 inert 적용/해제(사이드바+검색 모달), search-modal 컴포넌트 테스트 신설 (테스트 작성 중 mounted 커밋과 open 변경이 겹치는 경우 inert 적용이 누락되는 실제 버그를 발견해 함께 수정 — effect 의존성에 mounted 추가) - 실제 브라우저(프로덕션 빌드)에서 배경 27개 요소(script 포함)가 정상적으로 inert 처리됨을 확인 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Owner
Author
🔍 코드 리뷰 (self-review)검증한 것 — 동시 모달(사이드바 + 검색) 시나리오설계 시 고려했던 엣지 케이스(사이드바가 열린 채 Cmd+K로 검색을 여는 경우)를 실제 브라우저에서 확인했습니다:
참조 카운트 설계가 실전에서도 정확히 동작함을 확인했습니다(로직상 추론에서 그치지 않고 실측). 테스트가 실제 버그를 잡음
검토했지만 변경하지 않은 것
수정할 미흡사항은 없습니다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#87에서 물리적 Tab 트랩까지는 처리했지만, 완전한 모달 배경 격리(스크린리더 가상 커서/스와이프가 배경으로 새는 것 차단)는 범위 밖으로 남겨졌던 것을 마무리합니다.
구현
hooks/use-modal-a11y.ts(신설): 사이드바·검색 모달이 공유하는 배경 격리 훅useBodyScrollLock재사용) + 배경 콘텐츠inert적용/복구 일원화createPortal로document.body에 렌더하기 위한mounted가드 제공(SSR엔document가 없음)mobile-sidebar.tsx/search-modal.tsx: 패널을document.body에 직접 포털 렌더 +useModalA11y로 전환,aria-modal="true"(재)부여 — 이제 실제로 배경이 격리되어 있으니 정확한 선언테스트에서 발견한 실제 버그
search-modal.test.tsx작성 중, 모달이isOpen=true로 첫 렌더될 때 inert가 적용 안 되는 버그를 발견했습니다.mounted(포털 렌더 가능 시점)가false→true로 바뀌는 커밋에서dialogRef.current가 처음 채워지는데, effect 의존성이[open]뿐이라open값 자체가 안 바뀌면 재실행되지 않았습니다.mounted를 의존성에 추가해 수정했습니다.검증
search-modal.test.tsx, 사이드바/검색모달 배경 inert 케이스)container스코프 밖으로 나간 쿼리를document기준으로 수정🤖 Generated with Claude Code