Skip to content

Commit 9ffa935

Browse files
authored
Merge pull request #12 from codebar-ag/fix/code-editor-copy-button-stretch
Stop the code editor's copy button collapsing to a squashed stadium
2 parents 105e0dd + b587a15 commit 9ffa935

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/components/organisms/CodeEditor.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,14 @@ onBeforeUnmount(() => view?.destroy());
157157
`autoHeight` mode THIS element is the scroll container, and an absolutely
158158
positioned child would scroll out of sight on any document longer than
159159
the visible box.
160+
161+
`items-start` is load-bearing: without it the default `align-items:
162+
stretch` squashes the button to this row's zero height, leaving a
163+
padding-only stadium with the icon spilling out top and bottom.
160164
-->
161165
<div
162166
v-if="copyable && modelValue"
163-
class="sticky top-0 z-10 flex h-0 justify-end"
167+
class="sticky top-0 z-10 flex h-0 items-start justify-end"
164168
>
165169
<CopyButton
166170
:value="copyValue"

tests/interactions.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ test('a copyable code editor copies the document it displays', async ({ page, co
4141
const clipboard = await page.evaluate(() => navigator.clipboard.readText());
4242
expect(clipboard).toBe('{\n "vendor": "string",\n "invoice_number": "string"\n}');
4343
});
44+
45+
test('the copyable code editor button is not squashed by its zero-height row', async ({ page }) => {
46+
await gotoStory(page, 'organisms-codeeditor--copyable');
47+
await expect(page.locator('.cm-content')).toBeVisible();
48+
49+
// The button sits in a `h-0` sticky row, so a missing `items-start` lets
50+
// `align-items: stretch` collapse it to padding-only and the icon spills
51+
// out. Assert it still boxes its own icon: square, and taller than the glyph.
52+
const button = page.getByRole('button', { name: 'Copy to clipboard' });
53+
const box = (await button.boundingBox())!;
54+
const icon = (await button.locator('svg').boundingBox())!;
55+
56+
expect(box.height).toBeGreaterThan(icon.height);
57+
expect(Math.abs(box.width - box.height)).toBeLessThanOrEqual(1);
58+
});

0 commit comments

Comments
 (0)