Accessible, multilevel dropdown component for React — zero heavy deps, keyboard-ready.
🚀 Live demo · 📦 npm · 💻 GitHub
Install the package from npm:
npm install react-dropdown-multilevel
# or
pnpm add react-dropdown-multilevel
# or
yarn add react-dropdown-multilevelPeer dependencies: react and react-dom (>= 18).
The component's CSS is bundled and imported automatically — no extra CSS import is required.
// Default import
import DropDownMultilevel from "react-dropdown-multilevel";
export const TestMenuComponent = (props) => {
return (
<DropDownMultilevel title="Dropdown title">
<DropDownMultilevel.Item onClick={() => doSomething()}>
Item 1
</DropDownMultilevel.Item>
<DropDownMultilevel.Item>
Item 2
<DropDownMultilevel.SubMenu>
<DropDownMultilevel.Item>Subitem 1</DropDownMultilevel.Item>
</DropDownMultilevel.SubMenu>
</DropDownMultilevel.Item>
</DropDownMultilevel>
);
};
// or named imports
import DropDownMultilevel, {
Divider,
Item,
SubMenu,
} from "react-dropdown-multilevel";
export const TestMenuComponent = (props) => {
return (
<DropDownMultilevel title="Dropdown title">
<Item onClick={() => doSomething()}>Item 1</Item>
<Item>
Item 2
<SubMenu>
<Item>Subitem 1</Item>
</SubMenu>
</Item>
</DropDownMultilevel>
);
};Il componente segue l'ARIA menu button pattern. Quando il bottone ha il focus:
| Tasto | Azione |
|---|---|
Enter / Space |
apre/chiude il menu |
↓ ArrowDown |
apre il menu e mette a fuoco il primo elemento |
↑ ArrowUp |
apre il menu e mette a fuoco l'ultimo elemento |
Quando il menu è aperto:
| Tasto | Azione |
|---|---|
↓ / ↑ |
sposta il focus tra gli elementi (con wrap) |
Home / End |
primo / ultimo elemento |
Esc |
chiude il menu e riporta il focus sul bottone |
Tab |
chiude il menu e prosegue la tabulazione |
| NAME | TYPE | DEFAULT VALUE | | :--------------- | :------------------------------------------------------------------------- | :------------ | ---- | | children | ReactNode | ReactNode[] | null | | title | ReactNode | ReactNode[] | null | | isDisabled | boolean | false | | position | "left", "right", "top-right", "top-left" | left | | buttonVariant | "primary", "secondary", "tertiary", "special", "special-success", "dashed" | secondary | | isActive | boolean | false | | openOnHover | boolean | false | | wrapperClassName | string | null | | buttonClassName | string | null | | menuClassName | string | null | | onClick | (x?: any) => any | () => null |
| NAME | TYPE | DEFAULT VALUE | | :--------- | :--------------- | :------------ | ---- | | children | ReactNode | ReactNode[] | null | | onClick | (x?: any) => any | () => null | | isActive | boolean | false | | className | string | null | | isDisabled | boolean | false |
| NAME | TYPE | DEFAULT VALUE | | :-------- | :------------------------------------------------- | :------------ | ---- | | children | ReactNode | ReactNode[] | null | | position | "left", "right", "bottom", "left-top", "right-top" | left | | className | string | null |
Per lavorare sulla libreria in locale (richiede pnpm):
# 1. Installa le dipendenze
pnpm install
# 2. Installa i browser di Playwright (per gli e2e)
pnpm exec playwright install
# ── Demo / Playground ────────────────────────
pnpm dev # apri http://localhost:5173
# ── Qualità ──────────────────────────────────
pnpm typecheck # controllo tipi (tsc -b)
pnpm lint # eslint
# ── Test ─────────────────────────────────────
pnpm test # vitest (unit)
pnpm test:e2e # playwright (e2e, tutti i browser)
pnpm test:all # unit + e2e
# ── Build libreria ───────────────────────────
pnpm build # genera dist/ (ESM + .d.ts + CSS)La pubblicazione su npm avviene in automatico via GitHub Actions
(.github/workflows/publish.yml, OIDC Trusted Publishing) quando viene
pubblicata una release con tag vX.Y.Z allineato a package.json.
Apache-2.0 © emaxlele
