RadialMenuSVG
A fully accessible radial (circular) menu built with SVG, inspired by the original canvas-based radialMenu by Victor Ribeiro.
This version prioritizes accessibility, keyboard navigation potential, and semantic HTML structure by using SVG elements like <path> and <text> instead of <canvas>, making the menu screen-reader friendly and easier to style with CSS.
๐ Features
- โ SVG-based radial layout
- โ Clickable and keyboard-focusable menu items
- โ Font-based icons (e.g., FontAwesome)
- โ Customizable size, gap, rotation, colors, and position
- โ Right-click activation or fixed positioning
- โ ARIA roles for accessibility
๐ฆ Installation
You can clone or copy the class file:
git clone https://github.com/yourusername/RadialMenuSVG.git
Or just copy the RadialMenuSVG.js file into your project.
๐งช Usage Example
Make sure to include FontAwesome if you're using its icons:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
Then in JavaScript:
import RadialMenuSVG from './RadialMenuSVG.js'; const menu = new RadialMenuSVG({ outerCircle: 100, innerCircle: 40, fontSize: 20, fontFamily: 'FontAwesome', isFixed: true, posX: 200, posY: 150, buttons: [ { text: '\uf013', // FontAwesome: gear action: () => alert('Settings') }, { text: '\uf11c', // FontAwesome: power off action: () => alert('Shutdown') }, { text: '\uf0e0', // FontAwesome: envelope action: () => alert('Messages') }, ] });
โ๏ธ Options
| Option | Type | Description |
|---|---|---|
outerCircle |
number |
Outer radius of the menu (required) |
innerCircle |
number |
Inner radius (creates a hole if > 0) |
fontSize |
number |
Font size for the icons |
fontFamily |
string |
Font family to render text (e.g. 'FontAwesome') |
rotation |
number |
Starting angle in radians |
buttonGap |
number |
Space between buttons in radians |
isFixed |
boolean |
If true, menu is always visible |
posX, posY |
number |
Fixed position on screen (used if isFixed is true) |
buttons |
array |
List of buttons (text, action, optional styles) |
Each button object accepts:
text(string) โ character/icon to displayaction(function) โ callback on click
๐งฑ Accessibility
- Each button is a
<path>withrole="menuitem"andtabindex="0" - Menu has
role="menu"andaria-label - Ideal for screen readers and keyboard navigation (future updates may include key bindings)
โจ Credits
This project is a modern rewrite of the amazing radialMenu created by Victor Ribeiro, originally built using <canvas>.
๐ License
MIT License