Skip to content

fix(search-modal): prevent focus ring from being clipped by scroll container#1410

Open
low-perry wants to merge 4 commits intomdn:mainfrom
low-perry:search-modal-fix
Open

fix(search-modal): prevent focus ring from being clipped by scroll container#1410
low-perry wants to merge 4 commits intomdn:mainfrom
low-perry:search-modal-fix

Conversation

@low-perry
Copy link
Copy Markdown

Description

Added an explicit :focus-visible rule to components/search-modal/element.css:

CSS a:focus-visible { outline: 2px solid var(--color-link-normal); outline-offset: -2px; } ​

Motivation

When navigating search results with the keyboard (Tab key), the
focus ring around a result link was visually clipped, cut off at the edges
instead of forming a clean rectangle around the item.

The root cause is a CSS clipping rule: any element with overflow set to a
value other than visible (here overflow: auto on the <ul> results list)
becomes a clipping container. The default browser focus outline renders
outside an element's border box, and because the result <a> links fill
100% of the scroll container's width, that outward outline sits exactly on
the clipping boundary and gets cut.

Additional details

I tested the fix on Windows 11 and Ubuntu 22.04, using Firefox, Chrome, and Edge.

Related issues and pull requests

Fixes #992

@low-perry low-perry requested a review from a team as a code owner March 21, 2026 12:27
@low-perry low-perry requested a review from caugner March 21, 2026 12:27
@github-actions
Copy link
Copy Markdown
Contributor

2ac06ec was deployed to: https://fred-pr1410.review.mdn.allizom.net/

Copy link
Copy Markdown
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

The outline looks good, except for the color (should not change) and the left (thicker than top/right/bottom).

Before:

Image

After:

Image

Comment thread components/search-modal/element.css Outdated
}

&:focus-visible {
outline: 2px solid var(--color-link-normal);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
outline: 2px solid var(--color-link-normal);

Instead, we might want to make the border-color of li[data-selected] conditionally on :not(:focus-visible).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried conditioning the selected row border on :not(:focus-visible), but in this component the focused element is the inner a rather than the li, so that did not produce a good result, especially in Firefox on Windows and Ubuntu.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, in that case would :not(:has(:focus-visible)) work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There’s a chance I misunderstood your suggestion the first time around. I’ve now updated li[data-selected] to use :has(:focus-visible) so the selected row drops its border color when the inner link is focus-visible, while keeping the link’s focus outline in place.
I also tried removing the outline width, but without it the focus treatment looks a bit off in every browser I tested, so I kept the outline with the offset for now.

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.

Search box focus outline is getting clipped

3 participants