Skip to content

SWF(refactor): ハンバーガーメニューの状態変更とイベント処理を分ける - #820

Open
suree33 wants to merge 2 commits into
mainfrom
devin/1795146166-menu-state-refactor
Open

suree33 wants to merge 2 commits into
mainfrom
devin/1795146166-menu-state-refactor

Conversation

@suree33

@suree33 suree33 commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

ハンバーガーメニューの状態を変える処理を openMenu() / closeMenu() にまとめ、イベント処理からはこの2つを呼ぶだけにしました。動作は変えていません。

  • 状態を変える処理(data-active、aria-expanded、document.body.style.overflow、keydown リスナーの登録と解除、初回の start クラスの削除)は openMenu() / closeMenu() だけで行います。
  • click、keydown(Escape と Tab のフォーカストラップ)、matchMedia('(min-width: 640px)') のハンドラは、開くか閉じるかを決めて上の2つを呼びます。
  • if (hamburger) { ... } で包んでいた処理を if (!hamburger) return; の早期リターンにし、ネストを1段減らしました。
  • 古い JSDoc を直しました。存在しない ./hamburgerMenu.js からの import 例を @scripts/menu にし、「をを」の誤字と、現在の動作と合わない説明を修正しています。
// before: click で data-active をトグルしてから、属性を見て開閉の処理を分岐
hamburger.addEventListener('click', () => {
  if (hamburger.classList.contains('start')) { /* start を外して data-active を付ける */ }
  else hamburger.toggleAttribute('data-active');
  if (hamburger.hasAttribute('data-active')) { /* aria, menu, scroll, keydown */ }
  else closeMenu();
});

// after
hamburger.addEventListener('click', () => {
  if (hamburger.hasAttribute('data-active')) closeMenu();
  else openMenu();
});

実行結果

メニューに関わる Chromium の E2E を、main とこのブランチの両方で pnpm run build:e2e の後に実行し、同じ結果になりました(skip の1件は mobile プロジェクト専用のテストです)。

main このブランチ
navigation / reduced-motion / theme / accessibility / visual 21 passed, 1 skipped 21 passed, 1 skipped
$ pnpm exec playwright test tests/e2e/specs/navigation.spec.ts tests/e2e/specs/reduced-motion.spec.ts tests/e2e/specs/theme.spec.ts tests/e2e/specs/accessibility.spec.ts tests/e2e/specs/visual.spec.ts --project=chromium
  ✓  14 [chromium] › tests/e2e/specs/reduced-motion.spec.ts:20:5 › no-preference › scroll and mobile menu respect the motion preference (2.5s)
  ...
  1 skipped
  21 passed (16.5s)

pnpm run lint は 0 errors、0 warnings です(hint 2件は既存の eslint.config.js の includeIgnoreFile の非推奨警告)。

試すコマンド: pnpm run build:e2e && pnpm exec playwright test tests/e2e/specs/navigation.spec.ts --project=chromium

未確認

  • 実機のブラウザでの手動確認はしていません。QA Engineer の確認を通します。
  • docs/layouts.md の古い記述はメニューと関係しないため、この PR では直していません。

Software Factory opened this PR for Daiki
Implemented in session Separate menu state from event handling
Review with Devin · Open in Devin Desktop


devin-ai-integration Bot and others added 2 commits November 20, 2026 03:43
Co-Authored-By: Daiki Sato <d@sur33.com>
Co-Authored-By: Daiki Sato <d@sur33.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 839e1aa8-f39f-4ef7-8883-9d3f300485ca
Commits

Reviewing files that changed from the base of the PR and between e693614 and bc3644b.

Files selected for processing: 1

  • src/scripts/menu.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
blog bc3644b Commit Preview URL

Branch Preview URL
Nov 20 2026, 03:50 AM

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant