docs-v2/assets/styles
Jason Stirnaman ab8223d11e
fix(ui): fix Ask AI code control and add e2e tests (#6955)
* feat(ui): add Ask AI to code block controls menu

Add an "Ask AI" option to the code controls dropdown menu on all code
blocks. Uses data-ask-ai-query attribute if provided by the template,
otherwise builds a query from the code content. Delegates to the
existing Kapa widget integration via the ask-ai-open click handler.

* fix(ui): fix Ask AI code control and add e2e tests

## Summary

- Add "Ask AI" option to the code controls dropdown (three-dot menu) on all code blocks
- Uses `data-ask-ai-query` attribute from the template if available, otherwise builds a query from the code content
- Delegates to the existing Kapa widget via the `ask-ai-open` click handler contract
- Reorder menu items: Copy → Ask AI → Fill window

## Bug fix

Fix Ask AI button not opening the Kapa widget. jQuery `.trigger('click')`
doesn't dispatch native DOM events, so the native
`document.addEventListener` in ask-ai-trigger.js never received the click.
Switch to native `.click()` and remove `href="#"` to prevent scroll-to-top.

## Tests

Add Cypress e2e test suite (`code-controls.cy.js`) with 16 tests covering:
- Initialization: code blocks wrapped, controls appended, menu item order
- Toggle: open/close on click, close on outside click, independent menus
- Copy to clipboard: success lifecycle, revert after timeout
- Fullscreen: modal open/close, body scroll lock, placeholder restore
- Ask AI: Kapa modal opens, query built with code content (MutationObserver)

* fix(ui): apply icon spacing to all code control menu items

Move .cf-icon margin-right rule from .copy-code and .fullscreen-toggle
to the shared li level so it applies to all menu items including Ask AI.

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* fix(ui): add keyboard accessibility to code controls menu

Replace clickable <span> and <li> elements with proper <button> elements
and ARIA roles for keyboard and assistive-technology access:

- Toggle: <span> → <button> with aria-label and aria-expanded
- Menu items: <li> → <li role="none"><button role="menuitem">
- Menu: <ul> gets role="menu"
- SCSS: add :focus-visible styles, reset button defaults
- JS: toggle handler updates aria-expanded on open/close

Also fix tests to match actual behavior:
- Remove bogus "close other menus" test that manually closed first menu
  before opening second (tested nothing)
- Remove duplicate "close on re-click" test (same as outside-click)
- Add "keep menu open when copy is clicked" (stopPropagation behavior)
- Add accessibility markup validation test

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-03-16 21:05:47 -05:00
..
components fix(version-detector): centralize Grafana links and DRY up host examples (#6693) 2026-01-26 18:42:09 -06:00
layouts fix(ui): fix Ask AI code control and add e2e tests (#6955) 2026-03-16 21:05:47 -05:00
themes feat(ent3): add experimental badge for --use-pacha-tree (#6857) 2026-02-23 14:58:35 -06:00
tools Add support for GitHub style alerts (#5667) 2024-11-07 14:54:01 -07:00
sidebar-closed.scss reworked top nav structure and responsive styles 2020-09-02 12:15:55 -06:00
sidebar-open.scss reworked top nav structure and responsive styles 2020-09-02 12:15:55 -06:00
styles-api.scss WIP api-docs autogen, stylesheets, and auto-build process 2019-09-30 10:00:22 -06:00
styles-dark.scss made light theme default, renamed layouts 2019-05-06 09:16:38 -06:00
styles-default.scss Feature: Generate documentation in LLM-friendly Markdown (#6555) 2025-12-01 12:32:28 -06:00