Skip to content

Commit 9f1ff79

Browse files
snmsoodanCopilot
andcommitted
Reset the caption clipping in not-sr-only
`sr-only` clips `> caption` so that a table's caption is hidden in Firefox, where a table's own `clip-path` does not clip it. `not-sr-only` has to undo that, otherwise `sr-only md:not-sr-only` keeps the revealed table's caption clipped. Covered by a new UI test that checks both breakpoints. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7ee9c5ce-96b9-4d2b-a163-a6e5a4a4eb38
1 parent 2f04b40 commit 9f1ff79

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎packages/tailwindcss/src/utilities.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ test('not-sr-only', async () => {
4141
position: static;
4242
overflow: visible;
4343
}
44+
45+
.not-sr-only > caption {
46+
clip-path: none;
47+
}
4448
"
4549
`)
4650
expect(await run(['-not-sr-only', 'not-sr-only-[var(--value)]', 'not-sr-only/foo'])).toEqual('')

‎packages/tailwindcss/src/utilities.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ export function createUtilities(theme: Theme) {
613613
['overflow', 'visible'],
614614
['clip-path', 'none'],
615615
['white-space', 'normal'],
616+
// `sr-only` also clips the caption of a table, so undo that here
617+
() => styleRule('& > caption', [decl('clip-path', 'none')]),
616618
])
617619

618620
/**

‎packages/tailwindcss/tests/ui.spec.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,39 @@ test('sr-only also hides the caption of a table', async ({ page }) => {
15321532

15331533
// Firefox applies the `clip-path` of the `<table>` to its inner grid box, and
15341534
// a `<caption>` is rendered in the outer table wrapper box, so the caption is
1535-
// not clipped by the table itself and must be clipped explicitly.
1535+
// not clipped by the table itself and must be clipped explicitly. Asserting
1536+
// the rule that does it is all that can run here: the bug only reproduces in
1537+
// Firefox, which is not available in this environment.
15361538
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('inset(50%)')
15371539
})
15381540

1541+
test('not-sr-only also unclips the caption of a table', async ({ page }) => {
1542+
let { getPropertyValue } = await render(
1543+
page,
1544+
html`
1545+
<table id="table" class="sr-only md:not-sr-only">
1546+
<caption id="caption">
1547+
Caption
1548+
</caption>
1549+
<tbody>
1550+
<tr>
1551+
<td>Cell</td>
1552+
</tr>
1553+
</tbody>
1554+
</table>
1555+
`,
1556+
)
1557+
1558+
// the caption must become visible again together with the table it reveals,
1559+
// so the responsive reset has to win over the base `sr-only` rule
1560+
await page.setViewportSize({ width: 640, height: 768 })
1561+
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('inset(50%)')
1562+
1563+
await page.setViewportSize({ width: 1024, height: 768 })
1564+
expect(await getPropertyValue('#table', 'clip-path')).toEqual('none')
1565+
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('none')
1566+
})
1567+
15391568
test('composing shadow, inset shadow, ring, and inset ring', async ({ page }) => {
15401569
let { getPropertyList } = await render(
15411570
page,

0 commit comments

Comments
 (0)