Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ test('sr-only', async () => {
position: absolute;
overflow: hidden;
}

.sr-only > caption {
clip-path: inset(50%);
}
"
`)
expect(await run(['-sr-only', 'sr-only-[var(--value)]', 'sr-only/foo'])).toEqual('')
Expand All @@ -37,6 +41,10 @@ test('not-sr-only', async () => {
position: static;
overflow: visible;
}

.not-sr-only > caption {
clip-path: none;
}
"
`)
expect(await run(['-not-sr-only', 'not-sr-only-[var(--value)]', 'not-sr-only/foo'])).toEqual('')
Expand Down
6 changes: 6 additions & 0 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ export function createUtilities(theme: Theme) {
['clip-path', 'inset(50%)'],
['white-space', 'nowrap'],
['border-width', '0'],
// Firefox applies the `clip-path` of a `<table>` to its inner grid box, so
// a `<caption>` (which lives in the outer table wrapper box) is not clipped
// and stays visible. Clip the caption itself to cover that case.
() => styleRule('& > caption', [decl('clip-path', 'inset(50%)')]),
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
])
staticUtility('not-sr-only', [
['position', 'static'],
Expand All @@ -609,6 +613,8 @@ export function createUtilities(theme: Theme) {
['overflow', 'visible'],
['clip-path', 'none'],
['white-space', 'normal'],
// `sr-only` also clips the caption of a table, so undo that here
() => styleRule('& > caption', [decl('clip-path', 'none')]),

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.

P2 Caption clipping is overridden When a table has not-sr-only but was never sr-only, this rule still sets its caption’s clip-path to none. .not-sr-only > caption is more specific than a normal utility on the caption, so an intentionally clipped caption loses its styling.

])

/**
Expand Down
52 changes: 52 additions & 0 deletions packages/tailwindcss/tests/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,58 @@ test.skip("::file-selector-button can receive a border with just the 'border' ut
)
})

test('sr-only also hides the caption of a table', async ({ page }) => {
let { getPropertyValue } = await render(
page,
html`
<table id="table" class="sr-only">
<caption id="caption">
Caption
</caption>
<tbody>
<tr>
<td>Cell</td>
</tr>
</tbody>
</table>
`,
)

// Firefox applies the `clip-path` of the `<table>` to its inner grid box, and
// a `<caption>` is rendered in the outer table wrapper box, so the caption is
// not clipped by the table itself and must be clipped explicitly. Asserting
// the rule that does it is all that can run here: the bug only reproduces in
// Firefox, which is not available in this environment.
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('inset(50%)')
Comment thread
greptile-apps[bot] marked this conversation as resolved.
})

test('not-sr-only also unclips the caption of a table', async ({ page }) => {
let { getPropertyValue } = await render(
page,
html`
<table id="table" class="sr-only md:not-sr-only">
<caption id="caption">
Caption
</caption>
<tbody>
<tr>
<td>Cell</td>
</tr>
</tbody>
</table>
`,
)

// the caption must become visible again together with the table it reveals,
// so the responsive reset has to win over the base `sr-only` rule
await page.setViewportSize({ width: 640, height: 768 })
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('inset(50%)')

await page.setViewportSize({ width: 1024, height: 768 })
expect(await getPropertyValue('#table', 'clip-path')).toEqual('none')
expect(await getPropertyValue('#caption', 'clip-path')).toEqual('none')
})

test('composing shadow, inset shadow, ring, and inset ring', async ({ page }) => {
let { getPropertyList } = await render(
page,
Expand Down