Skip to content

Avoid clipping focus indicator around site title (v2)#3058

Merged
delucis merged 6 commits intowithastro:mainfrom
techfg:fix/issue-2696
May 1, 2025
Merged

Avoid clipping focus indicator around site title (v2)#3058
delucis merged 6 commits intowithastro:mainfrom
techfg:fix/issue-2696

Conversation

@techfg
Copy link
Copy Markdown
Contributor

@techfg techfg commented Apr 7, 2025

Note

This is a replacement for #2714, which was relying on #2722 having been merged and shouldn't have been relying on it. See #2714 (comment).

Description

  • Closes focus:visible outline of site-title not visible #2696
  • What does this PR change? Fix site title focus ring #2704 improved the cosmetic of focus ring in site title, however there were a couple of remaining issues as described here. This PR eliminates the overflow: hidden and applies min-width to ensure the title-wrapper is constrained to available space by flexbox. Additionally, it styles the title text (if its displayed) with elipses providing an improved UI so that text is no longer abruptly cut-off but rather gives an indication that there is more text that just isn't visible. If a logo is present, it will be automatically scaled and therefore doesn't require a container with overflow: hidden. Tested in Edge, Chrome & Firefox.
  • Did you change something visual? A before/after screenshot can be helpful.

With a forced outline of 10px solid green:

Before Desktop:
image

Before Mobile:
image

After Desktop:
image

After Mobile:
image

Important

In performing testing on this PR, I identified other issues related to the way the header is displayed with large images and/or long text. Will create a separate issue to track those. Created #2715.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 7, 2025

🦋 Changeset detected

Latest commit: 381f2bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Apr 7, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 7, 2025

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit 381f2bb
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/6813763b3c9ddb0008c40c2a
😎 Deploy Preview https://deploy-preview-3058--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@techfg techfg changed the title Fix/issue 2696 Avoid clipping focus indicator around site title (v2) Apr 7, 2025
@delucis
Copy link
Copy Markdown
Member

delucis commented Apr 14, 2025

Thanks for bringing back this PR @techfg! Perhaps I’m missing something but this doesn’t seem to actually do what’s described?

If I add a :focus-visible { outline: 10px solid } style to the deploy preview, I see the exact same clipping behaviour as on the current live site:

Starlight logo on the docs site with a thick focus outline. The right edge is thicker than the others because they are slightly clipped.

As I mentioned previously, I don’t think this is an issue? The user agent default focus styles show up OK and if someone wants to add custom outline styles they can also add custom styles to the title to handle those if necessary. But either way this PR doesn’t seem to change things related to that.

@techfg
Copy link
Copy Markdown
Contributor Author

techfg commented Apr 14, 2025

Hi @delucis -

Thanks reviewing and sorry for the confusion here!

  1. Fixes display of long site title on mobile #2722 addressed the issue with the title-wrapper not respecting its flex position within header and overflowing.
  2. This PR addresses the site-title-text respecting its width within site-title and not overflowing.

In short, you are only going to see a difference with this PR when you have title text and that text overflows. For example, a really long title or "long enough" when the viewport is narrower.

In main, when the text overflows, the focus outline is not visible on the far right and it should be. This PR improves the following:

  1. Ensures the outline on the right side is always visible
  2. Improves the overflowing text by adding ellipses

Hopefully this helps better explain and demonstrate what this PR is trying to achieve.

To see the effect:

  1. Modify astro.config.mjs
	integrations: [
		starlight({
			title:
+				'Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight Starlight',
-				'Starlight',
			logo: {
				light: '/src/assets/logo-light.svg',
				dark: '/src/assets/logo-dark.svg',
+				replacesTitle: false,
-				replacesTitle: true,
			},
  1. Add outline
*:focus,
*:focus:not(:focus-visible) {
  outline: 1px solid transparent;
}

*:focus-visible {
  outline: 1px solid green;
  outline-offset: 1px;
}

Before Desktop:
image

Before Mobile:
image

After Desktop:
image

After Mobile:
image

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thanks for your patience on this PR @techfg — had a busy few weeks and some time away, which meant I couldn’t get to this. Left a few comments!

@techfg
Copy link
Copy Markdown
Contributor Author

techfg commented May 1, 2025

Thanks for your patience on this PR @techfg — had a busy few weeks and some time away, which meant I couldn’t get to this. Left a few comments!

No worries @delucis, hope you enjoyed the time away. PR updated per your feedback, let me know if you think this needs anything else. Thank you!

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @techfg!

@delucis delucis merged commit 274cc06 into withastro:main May 1, 2025
15 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 1, 2025
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 core Changes to Starlight’s main package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

focus:visible outline of site-title not visible

2 participants