Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Animated Focus

ASecurity

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

416 stars
0 votes
0 copies
2 views
Added 2/8/2026
developmentjavascriptgojavabashnodetestingdebuggingperformance

Works with

cli

Security Analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned 2/12/2026

$npx -y skills add aiskillstore/marketplace --skill animated-focus --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Animated Focus?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Animated Focus
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aiskillstore-animated-focus/badge)](https://www.skillsdirectory.com/skills/aiskillstore-animated-focus)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: animated-focus
description: 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

1. CSS animations like `fade-in-0` start the element at `opacity: 0`
2. When `focus()` is called immediately after render, the element is still invisible
3. Browser rejects focus on invisible elements
4. Focus stays on the trigger button instead of moving to content
5. Keyboard events go to trigger (which does nothing when open) instead of content

### Evidence from Console Debugging

```javascript
// 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

```javascript
// 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

1. **Use `requestAnimationFrame` first** - Ensures CSS has been applied before attempting focus
2. **Check `document.activeElement`** - Verify if focus actually succeeded
3. **Retry with delays** - 20ms intervals allow animation to progress
4. **Limited attempts** - 5 retries = 100ms max wait, enough for typical animations
5. **Apply to all focus functions** - Both `focusElement(element)` and `focusElementById(id)` need this pattern

### Functions Updated

- `floating.js:focusElement(element)` - Used by SelectContent
- `floating.js:focusElementById(elementId)` - Used by DropdownMenuContent

## Testing

Added "With Animations" sections to test demo pages and corresponding Playwright tests.

### CSS Animation Classes for Testing

```css
/* 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

```bash
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

1. **Longer initial delay** - Could use 50-100ms delay before first focus attempt, but adds noticeable lag
2. **Focus before animation starts** - Would require changes to render order, complex
3. **Disable animation during focus** - Would cause visual glitch
4. **CSS `visibility` instead of `opacity`** - Would require changes to how animations are authored

The retry mechanism was chosen because it:
- Works with any animation duration
- Doesn't require changes to CSS authoring
- Has minimal performance impact
- Fails gracefully if focus never succeeds

## Related Patterns

This pattern is similar to how bits-ui handles animated presence in Svelte components. The key insight is that DOM operations (like focus) may need to wait for CSS animations to reach a focusable state.

Attribution

aiskillstoreaiskillstore
View sourceSee grades on GitHubMore from aiskillstore →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Clean Code

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

304955 votes

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

286712 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Using Git Worktrees

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback

2927051 votes
View all in development →