{"summary":"オーバーレイの回避は、まず使える範囲を決め、その中で位置を動的に計算するのが基本。メニューの反転と高さ制限、ダイアログのヘッダーとフッターの固定、ツールチップの8方向の配置切り替えと追従チップの戻りの余裕、固定ヘッダーと下部固定バーの回避という4つの原則を、操作できるデモとともに解説します。","notes":"<p>ツールチップやメニュー、ダイアログといったオーバーレイは、中身の長さが一定ではなく、アプリのウィンドウやブラウザのビューポートの大きさも決まっていません。AI が画面を生成するとき、とても見落とされやすい点です。決まった一方向にしか開かないオーバーレイは、トリガーがビューポートの端に近いとき、長いリストの一番下にあるとき、スクロールで固定ヘッダーの下に入ったときに、ビューポートで切れたり、大事な操作を覆ったりします。確実なのは、まずオーバーレイの「使える範囲」を決めることです。ビューポートの四辺からそれぞれ 16px 内側とし、ページ内の非モーダルなオーバーレイではさらに固定ヘッダーと下部の固定バーを除きます。あわせて Portal で最上位に描画して親コンテナに切り取られないようにし、開いたとき、スクロールしたとき、ウィンドウサイズが変わったとき、自身のサイズが変わったときのたびに位置を計算し直します。</p>\n        <h2>収まらなければ反転、長すぎれば高さを制限</h2>\n        <p>メニューは既定ではトリガーの 8px 下に開きます。下の余白が足りず、上に十分な余白があれば、自動で反転して上に開きます。カスケードのサブメニューも、右側に収まらなければ同じように左側へ反転し、開くアニメーションの起点（transform-origin）もトリガーに近い側へ合わせて切り替えます。反転しても横にはみ出すなら、ビューポートの端に沿ってずらし、安全な範囲に戻します。それでもメニュー全体の高さがその側で使える高さを超えるなら、コンテナの最大高さを使える範囲に収めて内部をスクロールさせ、切れ目にフェードをかけて続きがあることを示します。また、メニューを開いたあと、カーソルがメニューの外にある状態でページをスクロールしたら、ユーザーの視線はすでにメイン画面に戻っています。メニューはすぐにフェードアウトして閉じます。</p>\n        <ul>\n        <li><strong>適用シーン：</strong>ドロップダウンメニュー、右クリックメニュー、カスケードのサブメニュー、セレクト（Select）</li>\n        <li><strong>設定値：</strong>ビューポートの端から 16px、トリガーから 8px、「反転 → ずらし → 高さを制限してスクロール」の順に処理、メニューの外でスクロールしたらすぐフェードアウト</li>\n        </ul>\n        <h2>ダイアログのヘッダーとフッターを固定</h2>\n        <p>ダイアログに長い内容を載せるとき、内容の高さのまま中央に広げると、タイトル行と下部の操作ボタンがビューポートの外へ押し出されます。ユーザーはいま何をしているのかも見えず、確定ボタンも見つけられません。ダイアログの最大高さはビューポートの安全な高さに収め、タイトルバーと下部のボタンバーを固定して、中央のコンテンツ領域だけをスクロールさせます。コンテンツがタイトルの下に入ったら、1px の区切り線を浮かび上がらせます。内容が長くなりがちな場面では、ダイアログの代わりにドロワーを使うのがおすすめです。デスクトップでは横から引き出すサイドドロワー、モバイルでは下から伸びる画面幅いっぱいのボトムシートを使います。</p>\n        <ul>\n        <li><strong>適用シーン：</strong>長いリストのダイアログ、設定パネル、フォームのダイアログ、規約への同意</li>\n        <li><strong>設定値：</strong>上下に 16px ずつ余白、タイトル行と下部のボタン行は固定、スクロール後はタイトルの下に 1px の区切り線、内容が長くなりがちならサイドドロワーかモバイルの全幅ボトムシートに切り替え</li>\n        </ul>\n        <h2>ツールチップの向き替えと追従チップの戻りの余裕</h2>\n        <p>ツールチップがビューポートの端からはみ出すときは、反対の向きへ反転します。端に近く一部だけがはみ出す程度なら、端に沿ってずらして範囲内に戻してもかまいません。そのときも矢印は常にトリガーの中心を指すようにします。矢印付きのツールチップには上・下・左・右と四隅の計 8 つの位置を用意し、各辺までの残りの余白に応じて最適なものを動的に選びます。チャートでカーソルに追従するチップは、既定ではカーソルの右下に置き、カーソル自体には重ねません。右端に近づいたらカーソルの左側へ移し、戻るときは切り替わった位置よりさらに 24px 内側に入ってから右側へ戻します。この「戻りの余裕（ヒステリシス）」によって、カーソルが境目付近で止まってもチップが行ったり来たりしません。ツールチップ、追従チップ、ドロワーの使い分けは <a href=\"/ja/009-overlays/\">009 ツールチップ・ポップオーバー・ドロワー・ダイアログの使い分け</a> を参照してください。</p>\n        <ul>\n        <li><strong>適用シーン：</strong>アイコンボタンやアバターのツールチップ、チャートの値を示すチップ、カーソルに追従する情報カード</li>\n        <li><strong>設定値：</strong>矢印付きは 8 方向から動的に選択、ずらすときも矢印はトリガーの中心へ、追従チップはカーソルを避ける、戻りの余裕 24px</li>\n        </ul>\n        <h2>固定ヘッダーと下部固定バーを避ける</h2>\n        <p>非モーダルなオーバーレイは、とくにツールチップ、ドロップダウンメニュー、Toast はどれも、上下に固定された要素（上部のナビゲーションバー、下部の再生バー、タブバー、チャットの入力欄など）を避けます。使える範囲を計算するときは、まずこれらの固定バーが占める高さを差し引きます。Toast は下部の固定バーの上に表示し、再生コントロールやメインのナビゲーションを覆わないようにします。スクロールしても自動では閉じないオーバーレイは、トリガーがページと一緒に固定ヘッダーの下に入ったら、あわせて非表示にします。ナビゲーションバーの上に浮いたまま残してはいけません。モーダルなダイアログは背景のマスクで画面全体の操作を引き受けるため、上下の固定バーを覆ってかまいません。その使える範囲はビューポート全体です。</p>\n        <ul>\n        <li><strong>適用シーン：</strong>固定ヘッダーや下部バーの近くに出るツールチップとドロップダウンメニュー、下部の再生バー／タブバー／入力欄の上に出る Toast</li>\n        <li><strong>設定値：</strong>使える範囲から上下の固定バーを除く、Toast は下部バーから 16px、トリガーが固定ヘッダーに隠れたらオーバーレイも非表示</li>\n        </ul>\n        <h2>AI に任せる</h2>\n        <p>下の Prompt を Claude Code、Codex、Cursor、WorkBuddy などの AI ツールに渡してください。まずプロジェクトにあるメニュー、ポップオーバー、ツールチップ、Toast、ダイアログのコンポーネントを洗い出し、端で切れる箇所や固定バーに隠れる箇所を表にまとめます。確認が済んだら、コンポーネント側で反転、ずらし、高さ制限、回避の処理を補います。</p>","prompt":"Check the overlay components my product already has (menus and dropdowns, popovers, tooltips, toasts and dialogs), find where each one breaks at the extremes (by an edge of the window, low on a long page, under a sticky header, above a fixed bottom bar, with long content), and fix the cause in the component, so every place that uses it gets the fix. Diagnose first, and change only what I approve. Work inside my code and components, and do not add a dependency without asking. Every value below is a default to start from.\n\n0. Diagnose\n- List each overlay component, where it is defined (my own, or a library: Floating UI, Radix, MUI, Ant Design), and how it is placed today: preferred side, offset, whether it flips, shifts or caps its height, what it measures against, whether it is rendered in a portal, and when it places itself again.\n- Find what stays fixed on screen (sticky headers, bottom bars) and any clipping or scrolling container between an overlay and the window.\n- Find the places where each one fails: the last rows of a long list, the right end of a header, inside a scrolling panel, a dialog with its longest content. Trace each failure to its cause in the component, not to the page it shows up on.\n\n1. The room\n- Every overlay stays inside the window less 16px on each side. In the page, also less the sticky header and any fixed bottom bar; modal layers cover the bars. Render overlays in a portal.\n- Place it again on open, on scroll, on resize and when its own size changes, not once only.\n\n2. Menus and dropdowns\n- 8px from the trigger. When the preferred side has no room, flip to the other side, then shift along it into the room.\n- When it is still too tall, cap it to the room and let it scroll inside.\n- When the page scrolls while the pointer is outside the menu, fade it out and close it.\n- With Floating UI: offset(8), flip, shift and size with padding 16, and autoUpdate.\n\n3. Dialogs\n- No taller than the window less 16px. The title bar and the button bar stay put; only the content between them scrolls, with a 1px line where it passes under them.\n- Where the content is often long, suggest a side drawer on desktop and a full-width bottom sheet on phones, and ask me before changing.\n\n4. Tooltips\n- By an edge, flip to the opposite side or shift along it; the arrow keeps pointing at the trigger.\n- With an arrow, choose among 8 placements (above, below, left, right and the four corners) by the room on each side.\n- A tooltip that follows the pointer sits clear of the cursor, moves to its other side by an edge, and comes back only once the pointer is 24px further in.\n\n5. Fixed bars\n- No overlay, tooltips above all, covers a sticky header or a bottom bar. Toasts sit 16px above the bottom bar. An overlay whose trigger scrolls under the header hides with it.\n\n6. Report and check\n- Before changing anything, give me one table, one row per component: | Component | Used in | Today | Cases that fail | Cause | Fix | Values |. Ask me which rows to change.\n- Afterwards, go back to every failing case and check that it opens whole, inside the room.","skill":"/skills/kubai-overlay-avoidance/SKILL.md","skillText":"# 浮层避让的定位规则\n\n《999 个小技巧，让你 Vibe 的产品更有质感》第 026 期 · @kubai087\n\n在用户的项目里按下面的要求改造。要求以用户的口吻写成：文中的 I、me、my 指用户；写着要先问的地方，先停下来问用户再继续。\n\n## 改造要求\n\nCheck the overlay components my product already has (menus and dropdowns, popovers, tooltips, toasts and dialogs), find where each one breaks at the extremes (by an edge of the window, low on a long page, under a sticky header, above a fixed bottom bar, with long content), and fix the cause in the component, so every place that uses it gets the fix. Diagnose first, and change only what I approve. Work inside my code and components, and do not add a dependency without asking. Every value below is a default to start from.\n\n0. Diagnose\n- List each overlay component, where it is defined (my own, or a library: Floating UI, Radix, MUI, Ant Design), and how it is placed today: preferred side, offset, whether it flips, shifts or caps its height, what it measures against, whether it is rendered in a portal, and when it places itself again.\n- Find what stays fixed on screen (sticky headers, bottom bars) and any clipping or scrolling container between an overlay and the window.\n- Find the places where each one fails: the last rows of a long list, the right end of a header, inside a scrolling panel, a dialog with its longest content. Trace each failure to its cause in the component, not to the page it shows up on.\n\n1. The room\n- Every overlay stays inside the window less 16px on each side. In the page, also less the sticky header and any fixed bottom bar; modal layers cover the bars. Render overlays in a portal.\n- Place it again on open, on scroll, on resize and when its own size changes, not once only.\n\n2. Menus and dropdowns\n- 8px from the trigger. When the preferred side has no room, flip to the other side, then shift along it into the room.\n- When it is still too tall, cap it to the room and let it scroll inside.\n- When the page scrolls while the pointer is outside the menu, fade it out and close it.\n- With Floating UI: offset(8), flip, shift and size with padding 16, and autoUpdate.\n\n3. Dialogs\n- No taller than the window less 16px. The title bar and the button bar stay put; only the content between them scrolls, with a 1px line where it passes under them.\n- Where the content is often long, suggest a side drawer on desktop and a full-width bottom sheet on phones, and ask me before changing.\n\n4. Tooltips\n- By an edge, flip to the opposite side or shift along it; the arrow keeps pointing at the trigger.\n- With an arrow, choose among 8 placements (above, below, left, right and the four corners) by the room on each side.\n- A tooltip that follows the pointer sits clear of the cursor, moves to its other side by an edge, and comes back only once the pointer is 24px further in.\n\n5. Fixed bars\n- No overlay, tooltips above all, covers a sticky header or a bottom bar. Toasts sit 16px above the bottom bar. An overlay whose trigger scrolls under the header hides with it.\n\n6. Report and check\n- Before changing anything, give me one table, one row per component: | Component | Used in | Today | Cases that fail | Cause | Fix | Values |. Ask me which rows to change.\n- Afterwards, go back to every failing case and check that it opens whole, inside the room.\n"}