Skip to content

Commit

Permalink
Fix Label component text reflow (#733)
Browse files Browse the repository at this point in the history
* Fix Label component text reflow

* github-actions[bot] Regenerated snapshots

* Add changeset

* Fix line-height

* github-actions[bot] Regenerated snapshots

* Update snapshots

* Set max-height

* Prevent stretching vertically on flexbox containers

* github-actions[bot] Regenerated snapshots

* Cleanup

---------

Co-authored-by: danielguillan <danielguillan@users.noreply.github.com>
  • Loading branch information
danielguillan and danielguillan committed Sep 12, 2024
1 parent 9a7e65a commit 2dcb9ba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-actors-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react-brand': patch
---

Fixes Label component multiline reflow
8 changes: 8 additions & 0 deletions packages/react/src/Label/Label.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import {Meta} from '@storybook/react'
import {Label} from '.'
import {Box} from '../'
import {CopilotIcon} from '@primer/octicons-react'

export default {
Expand Down Expand Up @@ -72,3 +73,10 @@ export const WithOcticonColor = () => (
</Label>
)
WithOcticonColor.storyName = 'With an Octicon and color'

export const WithReflow = () => (
<Box style={{width: 200}}>
<Label leadingVisual={<CopilotIcon />}>Label reflows if the text is too long</Label>
</Box>
)
WithOcticonColor.storyName = 'With an Octicon and color'
23 changes: 10 additions & 13 deletions packages/react/src/Label/Label.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
vertical-align: middle;
align-items: center;
justify-content: center;
border-radius: var(--brand-borderRadius-full);
border-radius: var(--brand-borderRadius-xlarge);
display: inline-flex;
color: var(--brand-Label-color-start, var(--brand-Label-color, currentColor));
position: relative;
height: min-content;
padding-inline: var(--base-size-16);
padding-block: var(--base-size-4);
background: none;
text-align: center;
}

.Label::before {
Expand All @@ -32,15 +36,11 @@
}

.Label--size-medium {
padding-left: var(--base-size-16);
padding-right: var(--base-size-16);
height: var(--base-size-28);
min-height: var(--base-size-28);
}

.Label--size-large {
padding-left: var(--base-size-16);
padding-right: var(--base-size-16);
height: var(--base-size-32);
min-height: var(--base-size-32);
}

.Label--color-default {
Expand Down Expand Up @@ -133,12 +133,8 @@
box-decoration-break: clone;
}

.Label--size-medium .Label__text {
line-height: var(--brand-text-lineHeight-200);
}

.Label--size-large .Label__text {
line-height: var(--brand-text-lineHeight-300);
.Label__text {
line-height: var(--base-size-16);
}

.Label__icon-visual {
Expand All @@ -155,6 +151,7 @@

.Label__label {
font-weight: var(--base-text-weight-semibold);
line-height: inherit;
}

@media (forced-colors: active) {
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/Label/Label.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ test.describe('Visual Comparison: Label', () => {
await page.waitForTimeout(500)
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
})

test('Label / With Reflow', async ({page}) => {
await page.goto('http://localhost:6006/iframe.html?args=&id=components-label-features--with-reflow&viewMode=story')

await page.waitForTimeout(500)
expect(await page.screenshot({fullPage: true})).toMatchSnapshot()
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2dcb9ba

Please sign in to comment.