Make every component and the landing page responsive (v0.3.1)
Every story and the landing page now fit from a 320px phone to a wide desktop without scrolling sideways. - Inputs in flex rows (Input, FeaturedInput, NumberInput, Combobox) shrink instead of holding their native width - Tab rows and ToggleGroup scroll within themselves on narrow screens; vertical tabs stack above their panel on phones - Positioned popups cap at Base UI's --available-width - Landing page: tablet header no longer crowds; code sample fits at 1024px - Storybook a11y panel skips page-level rules that can't apply to a story - check-stories.mjs gains --width and fails on horizontal overflow; all 423 stories pass at 320, 375, 768 and desktop widths in both modes
This commit is contained in:
1 parent
f01de83733
commit
23e67006d3
24 files changed
+136
-31
No files matched your search
@@ -9,7 +9,7 @@
|
||||
* - saves a screenshot.
|
||||
*
|
||||
* npm run build-storybook
|
||||
* node scripts/check-stories.mjs [--filter forms-] [--mode dark] [--palette emerald] [--out dir] [--no-shots]
|
||||
* node scripts/check-stories.mjs [--filter forms-] [--mode dark] [--palette emerald] [--width 375] [--out dir] [--no-shots]
|
||||
*
|
||||
* Exits non-zero when any story has an error or an axe violation.
|
||||
* Uses the system Chrome (CHROME_PATH, default /usr/bin/google-chrome).
|
||||
@@ -29,7 +29,8 @@ const DIR = resolve(opt('dir', 'storybook-static'))
|
||||
const FILTER = opt('filter', '')
|
||||
const MODE = opt('mode', 'light')
|
||||
const PALETTE = opt('palette', '')
|
||||
const OUT = resolve(opt('out', `/tmp/tansy-story-check/${MODE}${PALETTE ? `-${PALETTE}` : ''}`))
|
||||
const WIDTH = Number(opt('width', 1100))
|
||||
const OUT = resolve(opt('out', `/tmp/tansy-story-check/${MODE}${PALETTE ? `-${PALETTE}` : ''}${WIDTH !== 1100 ? `-${WIDTH}` : ''}`))
|
||||
const SHOTS = !args.includes('--no-shots')
|
||||
const CONCURRENCY = Number(opt('concurrency', 4))
|
||||
|
||||
@@ -71,7 +72,7 @@ await mkdir(OUT, { recursive: true })
|
||||
const browser = await chromium.launch({ executablePath: process.env.CHROME_PATH ?? '/usr/bin/google-chrome' })
|
||||
// Each story gets its own context: shared contexts leaked theme state and
|
||||
// axe runs between parallel pages.
|
||||
const newContext = () => browser.newContext({ viewport: { width: 1100, height: 760 }, reducedMotion: 'reduce' })
|
||||
const newContext = () => browser.newContext({ viewport: { width: WIDTH, height: 760 }, reducedMotion: 'reduce' })
|
||||
|
||||
const results = []
|
||||
async function check(story, attempt = 1) {
|
||||
@@ -128,6 +129,19 @@ async function check(story, attempt = 1) {
|
||||
return el ? el.textContent : null
|
||||
})
|
||||
if (sbError) errors.push(`storybook: ${sbError.slice(0, 300)}`)
|
||||
// Responsive: nothing may make the page scroll sideways at this width.
|
||||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth)
|
||||
if (overflow > 1) {
|
||||
const culprits = await page.evaluate(() => {
|
||||
const vw = document.documentElement.clientWidth
|
||||
return [...document.querySelectorAll('body *')]
|
||||
.filter((el) => el.getBoundingClientRect().right > vw + 1 && getComputedStyle(el).position !== 'fixed')
|
||||
.filter((el) => ![...el.children].some((c) => c.getBoundingClientRect().right > vw + 1))
|
||||
.slice(0, 3)
|
||||
.map((el) => `${el.tagName.toLowerCase()}${el.className && typeof el.className === 'string' ? '.' + el.className.split(' ').slice(0, 3).join('.') : ''}`)
|
||||
})
|
||||
errors.push(`overflow: page scrolls ${overflow}px sideways at ${WIDTH}px → ${culprits.join(' | ')}`)
|
||||
}
|
||||
await page.addScriptTag({ content: AXE })
|
||||
axe = await page.evaluate(async () => {
|
||||
const r = await window.axe.run(document.body, {
|
||||
@@ -175,7 +189,7 @@ for (const r of bad) {
|
||||
for (const v of r.axe) console.log(` axe ${v.impact} ${v.id}: ${v.help} → ${v.nodes.join(' | ')}`)
|
||||
}
|
||||
console.log(
|
||||
`\n${results.length} stories checked in ${MODE} mode${PALETTE ? `, ${PALETTE} palette` : ''}: ${results.length - bad.length} clean, ${bad.length} with problems.`,
|
||||
`\n${results.length} stories checked in ${MODE} mode${PALETTE ? `, ${PALETTE} palette` : ''} at ${WIDTH}px: ${results.length - bad.length} clean, ${bad.length} with problems.`,
|
||||
)
|
||||
console.log(`Screenshots and report.json in ${OUT}`)
|
||||
process.exit(bad.length ? 1 : 0)
|
||||
Reference in new issue
Block a user