Skip to content

a11y: Move Focus to API Input Field When Agent Tool Selected #6708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kangabell
Copy link
Collaborator

@kangabell kangabell commented Apr 3, 2025

Closes #5505

Summary

After clicking an "Add" button on a specific Agent Tool, the text input in the auth form receives focus.

Change Type

Please delete any irrelevant options.

  • Bug fix (non-breaking change which fixes an issue)

Testing

Test Configuration:

  • Browser: Chrome
  • Screen Readers: VoiceOver
  • Operating System: macOS Sequoia

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings

@kangabell kangabell added the ♿ a11y Accessibility label Apr 3, 2025
@kangabell kangabell force-pushed the a11y/focus-plugin-auth branch from 04080b6 to c8f9146 Compare April 3, 2025 22:18
@kangabell
Copy link
Collaborator Author

There might be a better way using ref instead of document.querySelector but this is what I got to work.

@danny-avila
Copy link
Owner

This solution is not ideal due to direct dom/element manipulation, I will look into making this work natively with the components. if i can't find a reasonable solution soon, I will merge this

@danny-avila danny-avila requested a review from Copilot April 7, 2025 17:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +116 to +122
setTimeout(() => {
const authField = document.querySelector('.auth-field') as HTMLInputElement;

if (authField) {
authField.focus();
}
}, 100);
Copy link
Preview

Copilot AI Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fixed timeout delay may lead to timing issues, making the input focus behavior unreliable on slower devices. Consider using a React ref or a useLayoutEffect hook to trigger focus after the input is rendered.

Suggested change
setTimeout(() => {
const authField = document.querySelector('.auth-field') as HTMLInputElement;
if (authField) {
authField.focus();
}
}, 100);
const authFieldRef = useRef<HTMLInputElement>(null);
useLayoutEffect(() => {
if (authFieldRef.current) {
authFieldRef.current.focus();
}
}, [authFieldRef.current]);
const authField = document.querySelector('.auth-field') as HTMLInputElement;
if (authField) {
authFieldRef.current = authField;
}

Copilot uses AI. Check for mistakes.

@kangabell
Copy link
Collaborator Author

@danny-avila What do you think of the Copilot response? It is still using document.querySelector so I'm guessing it is not sufficient.

There are a few other issues I want to work on related to managing focus, but first want to see where we land with this one so I can reuse the same method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♿ a11y Accessibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent Tools dialog: Change in content from buttons
2 participants