Skip to content

[site] Let docs tables scroll horizontally instead of overflowing on narrow screens - #1489

Open
ngocanhnckh wants to merge 1 commit into
lit:mainfrom
ngocanhnckh:fix/docs-tables-overflow-mobile
Open

ngocanhnckh wants to merge 1 commit into
lit:mainfrom
ngocanhnckh:fix/docs-tables-overflow-mobile

Conversation

@ngocanhnckh

Copy link
Copy Markdown

Fixes #1293

What is broken

Tables in the docs are wider than the article column on narrow screens and nothing scrolls, so the right-hand column is cut off or the whole page scrolls sideways.

  • /docs/components/properties/, the two "Type Conversion" tables: 380px and 404px wide inside a 272-327px column at 320-375px.
  • /docs/templates/directives/ (the issue in Page at /docs/templates/directives/ does not seem responsive to thinner displays #1293): the signature tables are up to 783px wide and stick out of the article at every phone width and also at 768px.
  • The same happens on other pages with tables (ssr/dom-emulation, ssr/authoring, components/decorators, templates/expressions, localization/overview, libraries/labs, components/shadow-dom).

Root cause

table in docs.css is a normal table, so it can't be narrower than its widest unbreakable content (code such as JSON.stringify(propertyValue) or a directive signature). Nothing in the article lets it scroll.

Fix

In docs.css, top-level tables become display: block; width: max-content; max-width: 100%; overflow-x: auto: they keep the width of their content when it fits, are capped at the article width and scroll horizontally when it doesn't. Tables with a .wide-cell (the directives tables) keep filling the article via table:has(.wide-cell) { width: 100% }. Tables nested inside another table's cell are left alone.

The footer social-links overflow is a separate bug (open PR #1447) and is not touched here, so a small footer-caused overflow remains below ~460px.

Testing

  • npm run dev, Chromium via Playwright, widths 320, 375, 414, 768, 820, 1024, 1280, 1440, light and dark.
  • Page scrollWidth on 13 docs pages with tables: tables no longer widen the page at any width; what remains at 320-414px is the footer (same value as on a page with no tables).
  • Desktop widths: table sizes unchanged (1px from the border), wide-cell tables still fill the article.
  • npx prettier --check on docs.css passes. The repo's screenshot tests only pass on the CI runner, so I did not run them.

The red boxes in the before shots mark the broken part.

Width Before After
375px, light Before, 375px light After, 375px light
320px, light Before, 320px light After, 320px light
375px, dark Before, 375px dark After, 375px dark
768px, light (directives) Before, 768px light After, 768px light

I found this with renderlint, an open-source CLI I maintain that renders pages in a headless browser and reports layout defects. It flagged the tables as viewport-overflow / content-overflow before the change and no longer does after it (it does now report a few-pixel accidental-scrollbar on two tables that are only 1-8px wider than the article, which is expected for a scroll container). If it would be useful, I'm happy to open a follow-up PR that runs it on the docs in CI; no pressure either way.

…narrow screens

Tables in docs pages can contain content that cannot wrap (code, long
identifiers), so on narrow viewports they were wider than the article and
either stretched the page or were cut off. Make top-level tables
horizontally scrollable, sized to their content and capped at the article
width. Tables with a .wide-cell still fill the article.

Fixes lit#1293
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.

Page at /docs/templates/directives/ does not seem responsive to thinner displays

1 participant