fix: keep mobile copy button above code text

pull/5247/head
cookesan 2 months ago
parent 20453451d8
commit 6fa626cbd3

@ -167,26 +167,35 @@ describe('Custom Containers', () => {
}) })
describe('Line Highlighting in Code Blocks', () => { describe('Line Highlighting in Code Blocks', () => {
test('hidden copy button does not block code text', async () => { test('copy button does not overlap mobile code text', async () => {
await page.setViewportSize({ width: 390, height: 844 }) await page.setViewportSize({ width: 390, height: 844 })
await goto('/markdown-extensions/') await goto('/markdown-extensions/')
const block = page.locator('#single-line + div') const block = page.locator('#single-line + div')
const button = block.locator('> button.copy') const button = block.locator('> button.copy')
const firstLine = block.locator('code > span').first()
await block.scrollIntoViewIfNeeded() await block.scrollIntoViewIfNeeded()
const buttonBox = await button.boundingBox() const buttonBox = await button.boundingBox()
const firstLineBox = await firstLine.boundingBox()
expect(buttonBox).toBeTruthy() expect(buttonBox).toBeTruthy()
expect(firstLineBox).toBeTruthy()
expect(buttonBox!.y + buttonBox!.height).toBeLessThanOrEqual(
firstLineBox!.y
)
const isCopyButtonAtPoint = await page.evaluate( await block.hover()
({ x, y }) => await page.waitForFunction(
document.elementFromPoint(x, y)?.matches('button.copy') ?? false, (el) => getComputedStyle(el).opacity === '1',
{ await button.elementHandle()
x: buttonBox!.x + buttonBox!.width / 2,
y: buttonBox!.y + buttonBox!.height / 2
}
) )
expect(isCopyButtonAtPoint).toBe(false) const hoveredButtonBox = await button.boundingBox()
const hoveredFirstLineBox = await firstLine.boundingBox()
expect(hoveredButtonBox).toBeTruthy()
expect(hoveredFirstLineBox).toBeTruthy()
expect(hoveredButtonBox!.y + hoveredButtonBox!.height).toBeLessThanOrEqual(
hoveredFirstLineBox!.y
)
await page.setViewportSize({ width: 1280, height: 720 }) await page.setViewportSize({ width: 1280, height: 720 })
await goto('/markdown-extensions/') await goto('/markdown-extensions/')

@ -473,6 +473,16 @@
pointer-events: auto; pointer-events: auto;
} }
@media (max-width: 639px) {
.vp-doc [class*='language-'] pre {
padding-top: 64px;
}
.vp-doc div[class*='language-'].line-numbers-mode .line-numbers-wrapper {
padding-top: 64px;
}
}
.vp-doc [class*='language-'] > button.copy:hover, .vp-doc [class*='language-'] > button.copy:hover,
.vp-doc [class*='language-'] > button.copy.copied { .vp-doc [class*='language-'] > button.copy.copied {
border-color: var(--vp-code-copy-code-hover-border-color); border-color: var(--vp-code-copy-code-hover-border-color);

Loading…
Cancel
Save