Menu Scrollingのロゴ

Menu Scrolling

コミュニティ
asmyshlyaev177
menu-scrolling

react-horizontal-scrolling-menuの命令型スクロールについて説明します。scrollToItem(getItemById(id), behavior, inline, block)、scrollNext/scrollPrev、外部からメニューを操作するapiRef(メソッドを呼び出し、データは読み取らない)、追加直後のアイテム向けgetItemElementById/getItemElementByIndex、slidingWindow + getItemsPosを使ったページ単位の移動を扱います。マウント時や選択時にアイテムまでスクロールする場合、外部からメニューを操作する場合、アイテムの動的追加後にスクロールする場合、scrollToItemが何もせず、ページ全体がメニューまでジャンプする場合に読み込んでください。

Add to TypingMind

概要

公開者asmyshlyaev177
リポジトリreact-horizontal-scrolling-menu
スキル名menu-scrolling
スター
790
フォーク
101
同梱ファイル
1
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 1個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    asmyshlyaev177がGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Menu Scrolling」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/tree/master/skills/menu-scrolling
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu.git /tmp/react-horizontal-scrolling-menu
mkdir -p .claude/skills
cp -r /tmp/react-horizontal-scrolling-menu/skills/menu-scrolling .claude/skills/menu-scrolling
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでMenu Scrollingを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にMenu Scrollingを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Menu Scrollingは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Imperative Scrolling

Setup

Click an item to center it. The api object comes from VisibilityContext inside the menu, from the apiRef prop outside it, and as the first argument of every callback prop (onInit, onUpdate, onWheel, onScroll).

tsx
import React from 'react';
import {
  ScrollMenu,
  VisibilityContext,
  type publicApiType,
} from 'react-horizontal-scrolling-menu';
import 'react-horizontal-scrolling-menu/dist/styles.css';

const ids = ['item-0', 'item-1', 'item-2', 'item-3', 'item-4', 'item-5'];

function Card({ itemId, title }: { itemId: string; title: string }) {
  const api = React.useContext<publicApiType>(VisibilityContext);
  return (
    <div
      role="button"
      tabIndex={0}
      style={{ width: '160px' }}
      onClick={() =>
        api.scrollToItem(api.getItemById(itemId), 'smooth', 'center')
      }
    >
      {title}
    </div>
  );
}

export function Menu() {
  return (
    <ScrollMenu>
      {ids.map((id) => (
        <Card itemId={id} key={id} title={id} />
      ))}
    </ScrollMenu>
  );
}

The blessed form is api.scrollToItem(api.getItemById(id), 'smooth', 'center') — a bare string id is a silent no-op (see Common Mistakes). getItemElementById(id) / getItemElementByIndex(index) are the advanced form: they query the DOM directly by data-key / data-index, which makes them stale-proof for items added in the current render.

Defaults (src/helpers.tsx:60,68-69; src/createApi.ts:131-132,152-153):

Methodbehaviorinlineblock
scrollToItem'smooth''end''nearest'
scrollPrev'smooth''end''nearest'
scrollNext'smooth''start''nearest'

behavior accepts 'auto' | 'instant' | 'smooth' and falls back to the transitionBehavior prop when one is set. The optional trailing { duration, boundary } argument only takes effect with noPolyfill={false} — the default native scroll ignores it.

Core Patterns

Control the menu from outside with apiRef

Pass a ref to ScrollMenu; the full context value is assigned to it after mount. Use it to fire methods only — data read from it goes stale.

tsx
import React from 'react';
import {
  ScrollMenu,
  type publicApiType,
} from 'react-horizontal-scrolling-menu';
import 'react-horizontal-scrolling-menu/dist/styles.css';

const ids = ['item-0', 'item-1', 'item-2', 'item-3', 'item-4', 'item-5'];

function Card({ itemId, title }: { itemId: string; title: string }) {
  return <div style={{ width: '160px' }}>{title}</div>;
}

export function PageWithExternalControls() {
  const apiRef = React.useRef<publicApiType | null>(null);

  const centerItem = (id: string) => {
    const api = apiRef.current;
    if (api) api.scrollToItem(api.getItemById(id), 'smooth', 'center');
  };

  return (
    <div>
      <button onClick={() => apiRef.current?.scrollPrev()}>Prev</button>
      <button onClick={() => centerItem('item-3')}>Center item-3</button>
      <button onClick={() => apiRef.current?.scrollNext()}>Next</button>
      <ScrollMenu apiRef={apiRef}>
        {ids.map((id) => (
          <Card itemId={id} key={id} title={id} />
        ))}
      </ScrollMenu>
    </div>
  );
}

Scroll to an item on mount

onInit fires once the menu has rendered and measured its items, so the api is safe to use right away — no timers. Use 'auto' (instant) so the initial position does not animate.

tsx
import React from 'react';
import {
  ScrollMenu,
  type publicApiType,
} from 'react-horizontal-scrolling-menu';
import 'react-horizontal-scrolling-menu/dist/styles.css';

const ids = ['item-0', 'item-1', 'item-2', 'item-3', 'item-4', 'item-5'];

function Card({ itemId, title }: { itemId: string; title: string }) {
  return <div style={{ width: '160px' }}>{title}</div>;
}

export function MenuStartingAtItemFive() {
  const scrollToItemOnInit = (api: publicApiType) => {
    const el = api.getItemElementById('item-5');
    if (el) api.scrollToItem(el, 'auto', 'start');
  };

  return (
    <ScrollMenu onInit={scrollToItemOnInit}>
      {ids.map((id) => (
        <Card itemId={id} key={id} title={id} />
      ))}
    </ScrollMenu>
  );
}

Page-at-a-time navigation with slidingWindow and getItemsPos

scrollNext/scrollPrev already move one viewport-group. Use slidingWindow + getItemsPos when you need to control which item of the target group lands where — e.g. centering the next page:

tsx
import {
  getItemsPos,
  slidingWindow,
  type publicApiType,
} from 'react-horizontal-scrolling-menu';

function scrollOnePage(api: publicApiType, direction: 'prev' | 'next') {
  const visible = api.items.getVisible().map(([id]) => id);
  if (!visible.length) return;
  const group = slidingWindow(api.items.toItems(), visible)[direction]();
  const target = getItemsPos(group).center;
  api.scrollToItem(api.getItemById(target), 'smooth', 'center');
}

slidingWindow(allIds, visibleIds) returns { prev(), next() } — each an id array the size of the visible set, clamped at the row edges. getItemsPos(group) returns { first, center, last } ids of that group.

Common Mistakes

CRITICAL Passing an itemId string to scrollToItem

Wrong:

tsx
api.scrollToItem('item-3', 'smooth', 'center'); // nothing scrolls

Correct:

tsx
api.scrollToItem(api.getItemById('item-3'), 'smooth', 'center');

The JSDoc example shows a bare 'itemId', but scrollToItem unwraps target?.entry?.target — a string has no .entry and no .scrollIntoView, so the call is a silent no-op (the TS type ItemOrElement correctly rejects strings; plain JS gets no error at all).

Source: src/createApi.ts:307-313 (JSDoc) vs src/helpers.tsx:59-64; https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/issues/157

HIGH Reading data values from apiRef during render

Wrong:

tsx
const atEnd = apiRef.current?.isLastItemVisible; // in render: never re-renders

Correct:

tsx
const api = apiRef.current;
if (api) api.scrollToItem(api.getItemById('item-3'), 'smooth', 'center');

apiRef is a mutable object React cannot re-render on — values read from it during render go stale. Inside event handlers and timers the visibility getters read the live ItemsMap and are fine (on <= 8.3.1 they were frozen even there — read api.items.last()?.visible instead). Reactive state in components comes from the context hooks.

Source: README.md apiRef section; https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/issues/167

HIGH getItemById right after adding an item returns undefined

Wrong:

tsx
setItems((prev) => [...prev, newItem]);
const api = apiRef.current;
if (api) api.scrollToItem(api.getItemById(newItem.id)); // undefined target — no-op

Correct:

tsx
// after the state update commits (effect or callback):
const api = apiRef.current;
const el = api?.getItemElementById(newItem.id);
if (api && el) api.scrollToItem(el, 'smooth', 'end');

The ItemsMap lags children by one render, so the map does not know a just-appended item yet; getItemElementById/getItemElementByIndex query the DOM by data-key/data-index and are stale-proof for this case.

Source: https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/issues/167; discussion #295; stories/AddItemAndScrollToIt

HIGH Scroll methods drag the whole page to the menu

Wrong:

tsx
setInterval(() => apiRef.current?.scrollNext(), 3000); // page keeps jumping to the menu

Correct:

tsx
setInterval(() => {
  if (apiRef.current?.menuVisible.current) apiRef.current.scrollNext();
}, 3000);

Scrolling is scrollIntoView-based, so scroll methods called while the menu is off screen scroll ancestor containers too (the page jumps vertically to the menu) — gate every programmatic scroll on menuVisible.current.

Source: https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/issues/276 (#277, #174, #230)

MEDIUM Numeric itemIds compared as numbers

Wrong:

tsx
<Card itemId={idx} key={idx} title={String(idx)} />;
// later:
api.getItemById(idx + 1);

Correct:

tsx
<Card itemId={String(idx)} key={idx} title={String(idx)} />;
// later:
api.getItemById(String(idx + 1));

itemId is String()-coerced everywhere internally, so getItemById(5) looks up "5" — mixing number and string ids causes missed lookups.

Source: CHANGELOG v3.1.1 (#207); src/helpers.tsx:102

MEDIUM Calling apiRef.current methods before mount

Wrong:

tsx
const apiRef = React.useRef<publicApiType | null>(null);
apiRef.current.scrollNext(); // during render — crash or no-op

Correct:

tsx
const apiRef = React.useRef<publicApiType | null>(null);
React.useEffect(() => {
  apiRef.current?.scrollNext();
}, []);

apiRef is populated in a useEffect after mount (src/index.tsx:281-287); before that current is null (or an empty object internally) — call methods only from effects or event handlers, with optional chaining.

Source: src/index.tsx:148,281-287

MEDIUM Reimplementing page math instead of slidingWindow/getItemsPos

Wrong:

tsx
const all = api.items.toItems();
const firstVisible = api.items.getVisible()[0]?.[0];
const next = all[all.indexOf(firstVisible) + 3]; // breaks at edges, wrong in RTL

Correct:

tsx
const visible = api.items.getVisible().map(([id]) => id);
const next = slidingWindow(api.items.toItems(), visible).next();
api.scrollToItem(api.getItemById(getItemsPos(next).center), 'smooth', 'center');

Page-at-a-time and centering math is shipped — slidingWindow().prev()/.next() plus getItemsPos() handle row edges and RTL; hand-rolled index math misses both.

Source: README.md Other helpers; stories/OneItemScroll

Tensions

HIGH Tension: Trivial quick start vs total silence on misuse

The library contains zero throws or warnings — every contract violation (missing styles.css, missing/duplicate itemId, string to scrollToItem) fails silently with no error to debug from. Self-check the contracts before shipping. See skills/menu-setup/SKILL.md and skills/menu-visibility/SKILL.md.

HIGH Tension: Imperative convenience vs reactive truth

The api object mixes live methods, reactive hooks, non-reactive getters (isFirstItemVisible/isLastItemVisible) and mutable stores (items, apiRef). Fire methods imperatively; in components rendered under ScrollMenu read state through the hooks — render reads of the getters never update. See skills/menu-visibility/SKILL.md.

HIGH Tension: Native scroll correctness vs animation control

noPolyfill defaults to true, so the per-call { duration, boundary } ScrollOptions and the transition props are silently discarded; noPolyfill={false} restores animation control but re-imports polyfill edge bugs (RTL, page-level scrolling). See skills/menu-transitions-rtl/SKILL.md.

See also

  • skills/menu-visibility/SKILL.md — paging math consumes the visible set (items.getVisible()), and scroll gating uses menuVisible
  • skills/menu-recipes/SKILL.md — autoplay, infinite loop, load-more and center-on-click are recipes built from these scroll methods
  • skills/menu-transitions-rtl/SKILL.md — transition props and ScrollOptions modify how the scroll methods animate

References

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Menu Scrolling」では何ができますか?

react-horizontal-scrolling-menuの命令型スクロールについて説明します。scrollToItem(getItemById(id), behavior, inline, block)、scrollNext/scrollPrev、外部からメニューを操作するapiRef(メソッドを呼び出し、データは読み取らない)、追加直後のアイテム向けgetItemElementById/getItemElementByIndex、slidingWindow + getItemsPosを使ったページ単位の移動を扱います。マウント時や選択時にアイテムまでスクロールする場合、外部からメニューを操作する場合、アイテムの動的追加後にスクロールする場合、scrollToItemが何もせず、ページ全体がメニューまでジャンプする場合に読み込んでください。

TypingMindでMenu Scrollingを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Menu Scrollingはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにMenu Scrollingをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/asmyshlyaev177/react-horizontal-scrolling-menu/tree/master/skills/menu-scrollingを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Menu Scrollingを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Menu Scrollingで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもMenu Scrollingを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Menu Scrolling」は無料ですか?

はい。asmyshlyaev177がMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇