Skip to content

Fix focus bugs that occur on initial load. #982

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

Merged
merged 2 commits into from
Sep 21, 2022
Merged

Conversation

microbit-robert
Copy link
Collaborator

This fixes some issues raised in #973 and #977.

The simulator and sidebar will no longer steal focus on load.

The sidebar tabs are always accessible, even if the sidebar loads in a collapsed state (screen widths <1366px).

@github-actions
Copy link

Preview build will be at
https://review-python-editor-next.microbit.org/focus-fixes/


useEffect(() => {
if (shown) {
ref.current!.focus();
// Prevents the simulator stealing focus on initial load.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd really love to find a way to move away from effects for this but I think this is a reasonable fix at this point.

@@ -29,8 +29,9 @@ const SideBarTab = ({
const ref = useRef<HTMLButtonElement>(null);
useEffect(() => {
// Override tabindex.
// Has no dependencies as it needs to run for every re-render.
ref.current!.setAttribute("tabindex", "0");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable, though I'd love a world where we didn't have to hack this.

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

Successfully merging this pull request may close these issues.

2 participants