{"slug":"craft-garnish","title":"craft-garnish","summary":"Garnish, Craft CMS's built-in JavaScript UI toolkit for the control panel. ALWAYS load when writing, editing, or reviewing JavaScript that runs in the Craft CP: plugin CP assets, custom field type JS, element index JS, CP webpack config, or code importing garnishjs / referencing ","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-26T20:25:57.594835Z","repo":{"url":"https://github.com/michtio/craftcms-claude-skills","stars":90,"forks":11,"license":"MIT","updatedAt":"2026-11-26T19:56:57Z"},"bodyHtml":"<hr>\n<h2>name: craft-garnish\ndescription: \"Garnish, Craft CMS's built-in JavaScript UI toolkit for the control panel. ALWAYS load when writing, editing, or reviewing JavaScript that runs in the Craft CP: plugin CP assets, custom field type JS, element index JS, CP webpack config, or code importing garnishjs / referencing window.Garnish. Also for CP accessibility, keyboard interactions, drag-sort, and CP JS memory issues.\"\nwhen_to_use: \"Triggers on: Garnish.Base.extend, this.base(), init/setSettings/destroy, addListener, CpAsset, webpack externals, CP JavaScript, Craft.* pattern, Craft.CP, Garnish.Modal, HUD popover, DisclosureMenu, MenuBtn, CustomSelect, Select, DragSort/DragDrop/DragMove, onSortChange/onSelectionChange, CheckboxSelect, ESC_KEY/RETURN_KEY, UiLayerManager, registerShortcut, trapFocusWithin, focus trap, aria-modal, inert, keyboard navigation CP, Craft.Slideout, Craft.ElementEditor, Craft.sendActionRequest, memory leak, event listener cleanup, jQuery .on() in CP, custom slideout/overlay lifecycle, disable kills listeners, sidebar panel injected into the entry form, id-only inputs with no name attribute, host form swallows my fields, Enter key submits the entry form, lightswitch value in JS. Do NOT trigger for front-end JavaScript (Alpine, Vue, htmx) or Twig templates (craft-site).\"\nallowed-tools: \"Bash(sh $/scripts/craft-version.sh)\"</h2>\n<h1>Garnish — Craft CMS Control Panel JavaScript Toolkit</h1>\n<h2>Craft Version of This Project</h2>\n<p>!<code>sh ${CLAUDE_SKILL_DIR}/scripts/craft-version.sh</code></p>\n<p>If no Craft version line appears above, establish the version before any version-specific advice: <code>craftcms/cms</code> in <code>composer.lock</code> for a site, the lowest version the <code>craftcms/cms</code> constraint in <code>composer.json</code> allows for a plugin, or ask. Then check it against the version tags in this skill (<code>[5.10+]</code>, <code>[changed 5.12]</code>, <code>[seomatic 5.1+]</code>).</p>\n<p>Reference for Garnish, Craft CMS's built-in JavaScript UI framework. Covers the class system, UI widgets, drag interactions, form components, accessibility helpers, and integration with Craft's CP.</p>\n<p>This skill is scoped to <strong>Garnish itself</strong> — the JavaScript library at <code>src/web/assets/garnish/</code>. For PHP-side plugin development (elements, controllers, services), see the <code>craftcms</code> skill. For CP template markup that Garnish widgets attach to, see the <code>craftcms</code> skill's <code>cp.md</code> reference.</p>\n<h2>Companion Skills — Load When Needed</h2>\n<ul>\n<li><strong><code>craftcms</code></strong> — Load when the task involves PHP asset bundle classes, plugin architecture, or CP template markup that Garnish widgets attach to. Skip for pure JavaScript refactoring, Garnish API questions, or JS-only tasks.</li>\n<li><strong><code>craft-php-guidelines</code></strong> — Load only when editing PHP files (asset bundle classes, controllers that register JS). Skip for pure JS work.</li>\n</ul>\n<h2>Documentation</h2>\n<ul>\n<li>Garnish source: <code>src/web/assets/garnish/src/</code> in the Craft CMS repository</li>\n<li>No official external documentation exists — this skill IS the documentation.</li>\n</ul>\n<p>Use <code>WebFetch</code> on Craft's class reference (<a href=\"https://docs.craftcms.com/api/v5/\">https://docs.craftcms.com/api/v5/</a>) when looking up PHP-side asset bundle registration.</p>\n<h2>Common Pitfalls (Cross-Cutting)</h2>\n<ul>\n<li>Using jQuery <code>.on()</code> directly instead of <code>this.addListener()</code> — listeners added via jQuery won't auto-clean on <code>destroy()</code>, causing memory leaks.</li>\n<li>Forgetting <code>this.base()</code> when overriding <code>destroy()</code> — parent cleanup (listener removal, event teardown) gets skipped.</li>\n<li>Using <code>click</code> instead of <code>activate</code> event on non-<code>&lt;button&gt;</code> elements — <code>activate</code> handles both click and keyboard (Space/Enter), making the UI accessible.</li>\n<li>Fighting <code>UiLayerManager</code> by binding ESC directly — use <code>Garnish.uiLayerManager.registerShortcut(Garnish.ESC_KEY, callback)</code> so escape routes through the layer stack correctly.</li>\n<li>Magic key code numbers instead of <code>Garnish.ESC_KEY</code>, <code>Garnish.RETURN_KEY</code>, etc. — constants are self-documenting and consistent.</li>\n<li>Instantiating Garnish widgets before the DOM is ready — Garnish requires jQuery and all dependencies loaded first; in plugin assets, rely on <code>CpAsset</code> dependency chain.</li>\n<li>Not calling <code>destroy()</code> when removing widgets — orphaned listeners accumulate, especially in slideouts and live preview where DOM is repeatedly created/destroyed.</li>\n<li>Importing Garnish into webpack bundles instead of using the external — <code>import Garnish from 'garnishjs'</code> resolves to <code>window.Garnish</code> via webpack externals; bundling it duplicates 134KB.</li>\n<li>Giving <code>name</code> attributes to inputs in a panel injected into another form (an entry-edit sidebar panel, a CP template hook) — the host form serializes them on save and your plugin's values are silently swallowed. Inputs are id-only, your JS reads them by id and posts to your own endpoint, and an Enter-key guard keeps the host form from submitting. See <code>integration.md</code> (Panels Injected Into Another Form).</li>\n<li>[deprecated 5.12] Registering <code>PrismJsAsset</code> for custom grammars, hooks or Prism plugins: since 5.12 it is a shim over TanStack Highlight and they silently stop working. Use <code>HighlightAsset</code> [5.12+] and <code>Craft.highlighter.highlight(code, {lang})</code>. Before 5.12: real Prism. See <code>integration.md</code> (Syntax Highlighting and Uploaders).</li>\n<li>Using deprecated <code>Garnish.Menu</code> instead of <code>Garnish.CustomSelect</code> — <code>Menu</code> is an alias kept for BC only.</li>\n<li>Using deprecated <code>Garnish.escManager</code> or <code>Garnish.shortcutManager</code> instead of <code>Garnish.uiLayerManager</code> — the newer manager provides layer-aware keyboard routing that respects the modal/menu stack.</li>\n</ul>\n<h2>Reference Files</h2>\n<p>Read the relevant reference file(s) for your task. Multiple files often apply together.</p>\n<p><strong>Task examples:</strong></p>\n<ul>\n<li>\"Create a modal dialog in a plugin's CP JS\" → read <code>class-system.md</code> + <code>ui-widgets.md</code></li>\n<li>\"Add drag-to-reorder to a custom field type\" → read <code>drag-system.md</code> + <code>class-system.md</code></li>\n<li>\"Build a custom CP widget class\" → read <code>class-system.md</code> + <code>integration.md</code></li>\n<li>\"Add a disclosure menu to a CP template\" → read <code>ui-widgets.md</code> + <code>integration.md</code></li>\n<li>\"Handle keyboard events in CP JavaScript\" → read <code>utilities.md</code> + <code>class-system.md</code></li>\n<li>\"Create an inline editor HUD\" → read <code>ui-widgets.md</code> (HUD section)</li>\n<li>\"Make a selection interface for elements\" → read <code>ui-widgets.md</code> (Select section)</li>\n<li>\"Set up a plugin's webpack config for Garnish\" → read <code>integration.md</code></li>\n<li>\"Custom element index class isn't loading\" → read <code>integration.md</code> (Element Index JS Loading)</li>\n<li>\"Load element index JS with Vite\" → read <code>integration.md</code> (Element Index JS Loading — Vite doesn't work for element index classes)</li>\n<li>\"Add ARIA attributes to a custom modal\" → read <code>utilities.md</code> (ARIA &amp; Focus section)</li>\n<li>\"Build a custom slideout/overlay/launcher on Garnish.Base\" → read <code>ui-widgets.md</code> (Building a custom overlay/slideout) + <code>class-system.md</code> (Enable / Disable) + <code>utilities.md</code> (ARIA &amp; Focus)</li>\n<li>\"My launcher button only works once / 'Blocked aria-hidden' warning\" → read <code>class-system.md</code> (Enable / Disable) + <code>utilities.md</code> (Closing an overlay: move focus OUT before hiding)</li>\n<li>\"Understand how Craft.CP extends Garnish\" → read <code>integration.md</code> + <code>class-system.md</code></li>\n<li>\"Add an interactive panel to an entry edit screen's sidebar from a plugin\" → read <code>integration.md</code> (Panels Injected Into Another Form) + the <code>craftcms</code> skill's <code>cp-ui-patterns.md</code> for the markup</li>\n<li>\"My panel's fields disappear when the entry is saved / Enter submits the entry form\" → read <code>integration.md</code> (Panels Injected Into Another Form)</li>\n<li>\"Build a multi-state submit button\" → read <code>integration.md</code> (Form Widgets section)</li>\n<li>\"Add auto-growing textarea behavior\" → read <code>integration.md</code> (Form Widgets section)</li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>Reference</th>\n<th>Scope</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>references/class-system.md</code></td>\n<td>Garnish.Base, inheritance (extend/init/base), events (on/off/trigger), listeners (addListener/removeListener), settings, namespacing, enable/disable, destroy lifecycle</td>\n</tr>\n<tr>\n<td><code>references/ui-widgets.md</code></td>\n<td>Modal, HUD, DisclosureMenu, MenuBtn, SelectMenu, CustomSelect, ContextMenu, Select — constructor args, settings/defaults, methods, events, ARIA behavior</td>\n</tr>\n<tr>\n<td><code>references/drag-system.md</code></td>\n<td>BaseDrag, Drag, DragSort, DragDrop, DragMove — class hierarchy, settings/defaults, events, helper system, insertion points, scroll handling</td>\n</tr>\n<tr>\n<td><code>references/utilities.md</code></td>\n<td>Garnish namespace object, key constants, custom jQuery events (activate, textchange, resize), ARIA/focus management, geometry/hit testing, animation, form helpers, detection</td>\n</tr>\n<tr>\n<td><code>references/integration.md</code></td>\n<td>GarnishAsset PHP bundle, webpack externals, loading sequence, Craft.* class pattern, Twig JS blocks, form widgets (NiceText, CheckboxSelect, MultiFunctionBtn, MixedInput)</td>\n</tr>\n</tbody>\n</table>\n","files":[{"path":"references/class-system.md","sizeBytes":11682,"isText":true},{"path":"references/drag-system.md","sizeBytes":11218,"isText":true},{"path":"references/integration.md","sizeBytes":26360,"isText":true},{"path":"references/ui-widgets.md","sizeBytes":21038,"isText":true},{"path":"references/utilities.md","sizeBytes":16854,"isText":true},{"path":"scripts/craft-version.sh","sizeBytes":7799,"isText":true},{"path":"SKILL.md","sizeBytes":8600,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-26T20:26:09.215551Z","sha256":"05E2A8E638107AB015E52DA87D0E1DA787B806665F1875C96CBAAA9AD5845C4D","sizeBytes":38732},"review":null,"source":{"repositoryUrl":"https://github.com/michtio/craftcms-claude-skills","path":"skills/craft-garnish","license":"MIT","commit":"93e135df3d734ebdf36ec4b2f352e1a0daa03c85","subtreeSha":"FBE5A37FC8E6A5112030AC030F6226A263857FF395DF5EE5ADA6D23D3DDDC04C","lastSyncedAt":"2026-11-26T20:25:56.895968Z"},"reviewedAt":"2026-11-26T20:26:16.017511Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/michtio/craftcms-claude-skills/tree/main/skills/craft-garnish"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install michtio-craftcms-claude-skills@llmmart"},{"target":"git","command":"git clone https://github.com/michtio/craftcms-claude-skills.git"}]}