{"id":"0a569496-288b-4981-a062-180956eb9e37","shortId":"6MqK4B","kind":"skill","title":"craft-garnish","tagline":"Garnish — Craft CMS's built-in JavaScript UI toolkit for the control panel. Covers the full Garnish surface: class system (Garnish.Base.extend, init, setSettings, addListener, on/off/trigger, destroy), UI widgets (Modal, HUD, DisclosureMenu, MenuBtn, CustomSelect, ContextMenu, Se","description":"# Garnish — Craft CMS Control Panel JavaScript Toolkit\n\nReference 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.\n\nThis skill is scoped to **Garnish itself** — the JavaScript library at `src/web/assets/garnish/`. For PHP-side plugin development (elements, controllers, services), see the `craftcms` skill. For CP template markup that Garnish widgets attach to, see the `craftcms` skill's `cp.md` reference.\n\n## Companion Skills — Load When Needed\n\n- **`craftcms`** — 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.\n- **`craft-php-guidelines`** — Load only when editing PHP files (asset bundle classes, controllers that register JS). Skip for pure JS work.\n\n## Documentation\n\n- Garnish source: `src/web/assets/garnish/src/` in the Craft CMS repository\n- No official external documentation exists — this skill IS the documentation.\n\nUse `WebFetch` on Craft's class reference (https://docs.craftcms.com/api/v5/) when looking up PHP-side asset bundle registration.\n\n## Common Pitfalls (Cross-Cutting)\n\n- Using jQuery `.on()` directly instead of `this.addListener()` — listeners added via jQuery won't auto-clean on `destroy()`, causing memory leaks.\n- Forgetting `this.base()` when overriding `destroy()` — parent cleanup (listener removal, event teardown) gets skipped.\n- Using `click` instead of `activate` event on non-`<button>` elements — `activate` handles both click and keyboard (Space/Enter), making the UI accessible.\n- Fighting `UiLayerManager` by binding ESC directly — use `Garnish.uiLayerManager.registerShortcut(Garnish.ESC_KEY, callback)` so escape routes through the layer stack correctly.\n- Magic key code numbers instead of `Garnish.ESC_KEY`, `Garnish.RETURN_KEY`, etc. — constants are self-documenting and consistent.\n- Instantiating Garnish widgets before the DOM is ready — Garnish requires jQuery and all dependencies loaded first; in plugin assets, rely on `CpAsset` dependency chain.\n- Not calling `destroy()` when removing widgets — orphaned listeners accumulate, especially in slideouts and live preview where DOM is repeatedly created/destroyed.\n- Importing Garnish into webpack bundles instead of using the external — `import Garnish from 'garnishjs'` resolves to `window.Garnish` via webpack externals; bundling it duplicates 134KB.\n- Using deprecated `Garnish.Menu` instead of `Garnish.CustomSelect` — `Menu` is an alias kept for BC only.\n- Using deprecated `Garnish.escManager` or `Garnish.shortcutManager` instead of `Garnish.uiLayerManager` — the newer manager provides layer-aware keyboard routing that respects the modal/menu stack.\n\n## Reference Files\n\nRead the relevant reference file(s) for your task. Multiple files often apply together.\n\n**Task examples:**\n- \"Create a modal dialog in a plugin's CP JS\" → read `class-system.md` + `ui-widgets.md`\n- \"Add drag-to-reorder to a custom field type\" → read `drag-system.md` + `class-system.md`\n- \"Build a custom CP widget class\" → read `class-system.md` + `integration.md`\n- \"Add a disclosure menu to a CP template\" → read `ui-widgets.md` + `integration.md`\n- \"Handle keyboard events in CP JavaScript\" → read `utilities.md` + `class-system.md`\n- \"Create an inline editor HUD\" → read `ui-widgets.md` (HUD section)\n- \"Make a selection interface for elements\" → read `ui-widgets.md` (Select section)\n- \"Set up a plugin's webpack config for Garnish\" → read `integration.md`\n- \"Custom element index class isn't loading\" → read `integration.md` (Element Index JS Loading)\n- \"Load element index JS with Vite\" → read `integration.md` (Element Index JS Loading — Vite doesn't work for element index classes)\n- \"Add ARIA attributes to a custom modal\" → read `utilities.md` (ARIA & Focus section)\n- \"Understand how Craft.CP extends Garnish\" → read `integration.md` + `class-system.md`\n- \"Build a multi-state submit button\" → read `integration.md` (Form Widgets section)\n- \"Add auto-growing textarea behavior\" → read `integration.md` (Form Widgets section)\n\n| Reference | Scope |\n|-----------|-------|\n| `references/class-system.md` | Garnish.Base, inheritance (extend/init/base), events (on/off/trigger), listeners (addListener/removeListener), settings, namespacing, enable/disable, destroy lifecycle |\n| `references/ui-widgets.md` | Modal, HUD, DisclosureMenu, MenuBtn, SelectMenu, CustomSelect, ContextMenu, Select — constructor args, settings/defaults, methods, events, ARIA behavior |\n| `references/drag-system.md` | BaseDrag, Drag, DragSort, DragDrop, DragMove — class hierarchy, settings/defaults, events, helper system, insertion points, scroll handling |\n| `references/utilities.md` | Garnish namespace object, key constants, custom jQuery events (activate, textchange, resize), ARIA/focus management, geometry/hit testing, animation, form helpers, detection |\n| `references/integration.md` | GarnishAsset PHP bundle, webpack externals, loading sequence, Craft.* class pattern, Twig JS blocks, form widgets (NiceText, CheckboxSelect, MultiFunctionBtn, MixedInput) |","tags":["craft","garnish","craftcms","claude","skills","michtio","agent-skills","claude-code","claude-code-plugin","claude-code-skills","claude-skills","content-modeling"],"capabilities":["skill","source-michtio","skill-craft-garnish","topic-agent-skills","topic-claude-code","topic-claude-code-plugin","topic-claude-code-skills","topic-claude-skills","topic-content-modeling","topic-craft-cms","topic-craft-cms-5","topic-craftcms","topic-ddev","topic-php","topic-twig"],"categories":["craftcms-claude-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/michtio/craftcms-claude-skills/craft-garnish","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add michtio/craftcms-claude-skills","source_repo":"https://github.com/michtio/craftcms-claude-skills","install_from":"skills.sh"}},"qualityScore":"0.469","qualityRationale":"deterministic score 0.47 from registry signals: · indexed on github topic:agent-skills · 39 github stars · SKILL.md body (5,243 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-01T18:56:48.520Z","embedding":null,"createdAt":"2026-04-18T22:19:33.185Z","updatedAt":"2026-05-01T18:56:48.520Z","lastSeenAt":"2026-05-01T18:56:48.520Z","tsv":"'/api/v5/)':207 '134kb':380 'access':69,275 'accumul':345 'activ':260,265,652 'ad':230 'add':448,470,553,585 'addlisten':28 'addlistener/removelistener':605 'alia':390 'anim':659 'api':150 'appli':431 'architectur':134 'arg':621 'aria':554,562,625 'aria/focus':655 'asset':130,167,214,331 'attach':109,142 'attribut':555 'auto':236,587 'auto-clean':235 'auto-grow':586 'awar':409 'basedrag':628 'bc':393 'behavior':590,626 'bind':279 'block':676 'build':461,573 'built':9,54 'built-in':8,53 'bundl':131,168,215,361,377,666 'button':579 'call':338 'callback':286 'caus':240 'chain':336 'checkboxselect':680 'class':23,61,132,169,203,466,523,552,633,672 'class-system.md':446,460,468,489,572 'clean':237 'cleanup':249 'click':257,268 'cms':6,42,51,186 'code':297 'common':217 'companion':118 'compon':68 'config':515 'consist':312 'constant':306,648 'constructor':620 'contextmenu':38,618 'control':16,43,96,170 'correct':294 'cover':18,59 'cp':76,103,136,443,464,476,485 'cp.md':116 'cpasset':334 'craft':2,5,41,50,74,158,185,201,671 'craft-garnish':1 'craft-php-guidelin':157 'craft.cp':567 'craftcm':100,113,123 'creat':435,490 'created/destroyed':356 'cross':220 'cross-cut':219 'custom':455,463,520,558,649 'customselect':37,617 'cut':221 'depend':326,335 'deprec':382,396 'destroy':30,239,247,339,609 'detect':662 'develop':94 'dialog':438 'direct':225,281 'disclosur':472 'disclosuremenu':35,614 'docs.craftcms.com':206 'docs.craftcms.com/api/v5/)':205 'document':179,191,197,310 'doesn':546 'dom':318,353 'drag':65,450,629 'drag-system.md':459 'drag-to-reord':449 'dragdrop':631 'dragmov':632 'dragsort':630 'duplic':379 'edit':164 'editor':493 'element':95,264,504,521,529,534,541,550 'enable/disable':608 'esc':280 'escap':288 'especi':346 'etc':305 'event':252,261,483,602,624,636,651 'exampl':434 'exist':192 'extend':568 'extend/init/base':601 'extern':190,366,376,668 'field':456 'fight':276 'file':166,418,423,429 'first':328 'focus':563 'forget':243 'form':67,582,593,660,677 'framework':58 'full':20 'garnish':3,4,21,40,49,82,107,140,149,180,314,321,358,368,517,569,644 'garnish.base':599 'garnish.base.extend':25 'garnish.customselect':386 'garnish.esc':284,301 'garnish.escmanager':397 'garnish.menu':383 'garnish.return':303 'garnish.shortcutmanager':399 'garnish.uilayermanager':402 'garnish.uilayermanager.registershortcut':283 'garnishasset':664 'garnishj':370 'geometry/hit':657 'get':254 'grow':588 'guidelin':160 'handl':266,481,642 'helper':70,637,661 'hierarchi':634 'hud':34,494,497,613 'import':357,367 'index':522,530,535,542,551 'inherit':600 'init':26 'inlin':492 'insert':639 'instanti':313 'instead':226,258,299,362,384,400 'integr':72 'integration.md':469,480,519,528,540,571,581,592 'interact':66 'interfac':502 'involv':128 'isn':524 'javascript':11,45,56,85,147,486 'jqueri':223,232,323,650 'js':154,173,177,444,531,536,543,675 'js-on':153 'kept':391 'key':285,296,302,304,647 'keyboard':270,410,482 'layer':292,408 'layer-awar':407 'leak':242 'librari':86 'lifecycl':610 'listen':229,250,344,604 'live':350 'load':120,124,161,327,526,532,533,544,669 'look':209 'magic':295 'make':272,499 'manag':405,656 'markup':105,138 'memori':241 'menu':387,473 'menubtn':36,615 'method':623 'mixedinput':682 'modal':33,437,559,612 'modal/menu':415 'multi':576 'multi-st':575 'multifunctionbtn':681 'multipl':428 'namespac':607,645 'need':122 'newer':404 'nicetext':679 'non':263 'number':298 'object':646 'offici':189 'often':430 'on/off/trigger':29,603 'orphan':343 'overrid':246 'panel':17,44 'parent':248 'pattern':673 'php':91,129,159,165,212,665 'php-side':90,211 'pitfal':218 'plugin':93,133,330,441,512 'point':640 'preview':351 'provid':406 'pure':146,176 'question':151 'read':419,445,458,467,478,487,495,505,518,527,539,560,570,580,591 'readi':320 'refactor':148 'refer':47,117,204,417,422,596 'references/class-system.md':598 'references/drag-system.md':627 'references/integration.md':663 'references/ui-widgets.md':611 'references/utilities.md':643 'regist':172 'registr':216 'relev':421 'reli':332 'remov':251,341 'reorder':452 'repeat':355 'repositori':187 'requir':322 'resiz':654 'resolv':371 'respect':413 'rout':289,411 'scope':80,597 'scroll':641 'se':39 'section':498,508,564,584,595 'see':98,111 'select':501,507,619 'selectmenu':616 'self':309 'self-docu':308 'sequenc':670 'servic':97 'set':509,606 'setset':27 'settings/defaults':622,635 'side':92,213 'skill':78,101,114,119,194 'skill-craft-garnish' 'skip':144,174,255 'slideout':348 'sourc':181 'source-michtio' 'space/enter':271 'src/web/assets/garnish':88 'src/web/assets/garnish/src':182 'stack':293,416 'state':577 'submit':578 'surfac':22 'system':24,62,638 'task':127,156,427,433 'teardown':253 'templat':104,137,477 'test':658 'textarea':589 'textchang':653 'this.addlistener':228 'this.base':244 'togeth':432 'toolkit':13,46 'topic-agent-skills' 'topic-claude-code' 'topic-claude-code-plugin' 'topic-claude-code-skills' 'topic-claude-skills' 'topic-content-modeling' 'topic-craft-cms' 'topic-craft-cms-5' 'topic-craftcms' 'topic-ddev' 'topic-php' 'topic-twig' 'twig':674 'type':457 'ui':12,31,57,63,274 'ui-widgets.md':447,479,496,506 'uilayermanag':277 'understand':565 'use':198,222,256,282,364,381,395 'utilities.md':488,561 'via':231,374 'vite':538,545 'webfetch':199 'webpack':360,375,514,667 'widget':32,64,108,141,315,342,465,583,594,678 'window.garnish':373 'won':233 'work':178,548","prices":[{"id":"543893a2-be49-40d8-ba06-cc839091726c","listingId":"0a569496-288b-4981-a062-180956eb9e37","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"michtio","category":"craftcms-claude-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T22:19:33.185Z"}],"sources":[{"listingId":"0a569496-288b-4981-a062-180956eb9e37","source":"github","sourceId":"michtio/craftcms-claude-skills/craft-garnish","sourceUrl":"https://github.com/michtio/craftcms-claude-skills/tree/main/skills/craft-garnish","isPrimary":false,"firstSeenAt":"2026-04-18T22:19:33.185Z","lastSeenAt":"2026-05-01T18:56:48.520Z"}],"details":{"listingId":"0a569496-288b-4981-a062-180956eb9e37","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"michtio","slug":"craft-garnish","github":{"repo":"michtio/craftcms-claude-skills","stars":39,"topics":["agent-skills","claude-code","claude-code-plugin","claude-code-skills","claude-skills","content-modeling","craft-cms","craft-cms-5","craftcms","ddev","php","twig"],"license":"mit","html_url":"https://github.com/michtio/craftcms-claude-skills","pushed_at":"2026-04-30T21:00:38Z","description":"Production-ready Claude Code skills, agents, and project templates for Craft CMS 5 development","skill_md_sha":"f67362936fc1615d1c72bc70bb1072d4b3b8db96","skill_md_path":"skills/craft-garnish/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/michtio/craftcms-claude-skills/tree/main/skills/craft-garnish"},"layout":"multi","source":"github","category":"craftcms-claude-skills","frontmatter":{"name":"craft-garnish","description":"Garnish — Craft CMS's built-in JavaScript UI toolkit for the control panel. Covers the full Garnish surface: class system (Garnish.Base.extend, init, setSettings, addListener, on/off/trigger, destroy), UI widgets (Modal, HUD, DisclosureMenu, MenuBtn, CustomSelect, ContextMenu, Select), drag system (BaseDrag, DragSort, DragDrop, DragMove), form widgets (NiceText, CheckboxSelect, MixedInput, MultiFunctionBtn), utilities (key constants, ARIA helpers, focus management), and Craft integration (GarnishAsset, webpack externals, Craft.* class pattern). Triggers on: Garnish.Base.extend, Garnish.Modal, Garnish.HUD, Garnish.DragSort, Garnish.Select, Garnish.DisclosureMenu, Garnish.MenuBtn, Garnish.CustomSelect, addListener, removeListener, removeAllListeners, Garnish.ESC_KEY, Garnish.RETURN_KEY, activate event, textchange event, UiLayerManager, registerShortcut, trapFocusWithin, garnishjs, GarnishAsset, CpAsset, CP JavaScript, control panel JS, drag and drop, sortable, modal dialog, HUD popover, disclosure menu, menu button, Craft.CP, Craft.Slideout, Craft.ElementEditor, onSortChange, onOptionSelect, onSelectionChange, aria-modal, focus trap, keyboard navigation CP, this.base(), window.Garnish, expose-loader, CP memory leak, event listener cleanup, jQuery .on() in CP, selection interface, multi-select grid. Always use when writing, editing, or reviewing JavaScript that runs in the Craft CMS control panel — including plugin CP assets, custom field type JS, element index JS, CP webpack config, or code that imports garnishjs or references window.Garnish. Also trigger for Craft CP accessibility, keyboard interactions, drag-sort behavior, or CP JS memory issues. Do NOT trigger for front-end JavaScript (Alpine, Vue, htmx) or Twig templates."},"skills_sh_url":"https://skills.sh/michtio/craftcms-claude-skills/craft-garnish"},"updatedAt":"2026-05-01T18:56:48.520Z"}}