animated-focus
БесплатноБез исполняемых скриптовНе проверенThis document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.
Об этом скилле
Focus Management with CSS Animations
This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.
The Problem
When floating content elements have CSS animations that start at opacity: 0 (like Tailwind's animate-in fade-in-0), the browser may reject element.focus() calls because the element is invisible.
Symptoms
- Component opens correctly with mouse clicks
- Keyboard navigation (arrow keys, Escape) doesn't work after opening with keyboard
- Works fine in demos without animation classes
- Broken in demos with animation classes
Root Cause
- CSS animations like
fade-in-0start the element atopacity: 0 - When
focus()is called immediately after render, the element is still invisible - Browser rejects focus on invisible elements
- Focus stays on the trigger button instead of moving to content
- Keyboard events go to trigger (which does nothing when open) instead of content
Evidence from Console Debugging
// After opening select, keyboard events go to trigger, not content:
Document keydown: ArrowDown Target: <button role="combobox" ...>
// Active element is trigger, not content:
Active: BUTTON summit-select-...-trigger
The Solution
Implement a retry mechanism for focus that allows the animation to progress past opacity: 0 before giving up.
JavaScript Implementation
// src/SummitUI/Scripts/floating.js
/**
* Focus an element with retry mechanism for animated elements.
* Elements with CSS animations starting at opacity:0 may reject focus initially.
* This retries focus up to 5 times with 20ms delays to allow the animation
* to progress past the invisible state.
* @param {HTMLElement} element - Element to focus
*/
export function focusElement(element) {
if (!element) return;
function tryFocus(attempts) {
element.focus();
// If focus didn't succeed and we have attempts left, retry
if (document.activeElement !== element && attempts > 0) {
setTimeout(() => tryFocus(attempts - 1), 20);
}
}
// First attempt after one frame to let CSS apply
requestAnimationFrame(() => tryFocus(5));
}
Key Points
- Use
requestAnimationFramefirst - Ensures CSS has been applied before attempting focus - Check
document.activeElement- Verify if focus actually succeeded - Retry with delays - 20ms intervals allow animation to progress
- Limited attempts - 5 retries = 100ms max wait, enough for typical animations
- Apply to all focus functions - Both
focusElement(element)andfocusElementById(id)need this pattern
Functions Updated
floating.js:focusElement(element)- Used by SelectContentfloating.js:focusElementById(elementId)- Used by DropdownMenuContent
Testing
Added "With Animations" sections to test demo pages and corresponding Playwright tests.
CSS Animation Classes for Testing
/* tests/SummitUI.Tests.Manual/SummitUI.Tests.Manual/wwwroot/app.css */
@keyframes fadeInZoomIn {
from {
opacity: 0;
transform: scale(0.95);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes fadeOutZoomOut {
from {
opacity: 1;
transform: scale(1);
}
to {
opacity: 0;
transform: scale(0.95);
}
}
.animated-content[data-state="open"] {
animation: fadeInZoomIn 150ms ease-out forwards;
}
.animated-content[data-state="closed"] {
animation: fadeOutZoomOut 150ms ease-in forwards;
}
Test Cases
For each component (Select, DropdownMenu, Popover):
| Test | What It Verifies |
|---|---|
Animated*_ShouldOpen_OnEnterKey |
Opens with keyboard when animations present |
Animated*_ShouldNavigate_WithArrowKeys |
Arrow keys work after animated open |
Animated*_ShouldSelect/Activate_OnEnterKey |
Can select/activate item after animated open |
Animated*_ShouldClose_OnEscape |
Escape triggers close animation |
Running Animation Tests
dotnet run --project tests/SummitUI.Tests.Playwright -- --treenode-filter '/*/*/*/Animated*'
Files Involved
| File | Purpose |
|---|---|
src/SummitUI/Scripts/floating.js |
Contains focusElement and focusElementById functions |
src/SummitUI/Components/Select/SelectContent.cs |
Calls FocusElementAsync on open |
src/SummitUI/Components/DropdownMenu/DropdownMenuContent.cs |
Calls FocusElementByIdAsync for menu items |
src/SummitUI/Components/Popover/PopoverContent.cs |
Manages focus for popover content |
Alternative Approaches Considered
- Longer initial delay - Could use 50-100ms delay before first focus attempt, but adds noticeable lag
- Focus before animation starts - Would require changes to render order, complex
- Disable animation during focus - Would cause visual glitch
- **CSS `visibility
Установить animated-focus в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл animated-focus?
This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.
Как установить скилл animated-focus?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл animated-focus запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic