Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrects styling on Buttons that only have a count and icon #5448

Merged
merged 19 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
5 changes: 5 additions & 0 deletions .changeset/brave-penguins-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Corrects horizontal padding of `<Button>` when the button only contains an icon and a counter label (no button text label).
18 changes: 18 additions & 0 deletions e2e/components/Button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,22 @@ test.describe('Button', () => {
})
}
})

test.describe('Trailing Counter No Text', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-button-features--trailing-counter-with-no-text',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Trailing Counter No Text.${theme}.png`)
})
})
}
})
})
4 changes: 1 addition & 3 deletions packages/react/src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export const TrailingCounter = () => {
)
}

export const TrailingCounterWithNoText = () => {
return <Button leadingVisual={CommentIcon} count={3} />
}
export const TrailingCounterWithNoText = () => <Button aria-label="Comments" leadingVisual={CommentIcon} count={3} />

export const TrailingCounterAllVariants = () => {
const [count, setCount] = useState(0)
Expand Down
17 changes: 17 additions & 0 deletions packages/react/src/Button/ButtonBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,23 @@
color: inherit !important;
}
}

/* Icon-only + Counter */

&:where([data-has-count]):has([data-component='leadingVisual']):not(:has([data-component='text'])) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-medium-paddingInline-condensed);

&:where([data-size='small']) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-xsmall-paddingInline-condensed);
}

&:where([data-size='large']) {
/* stylelint-disable-next-line primer/spacing */
padding-inline: var(--control-large-paddingInline-normal);
}
}
}

.ConditionalWrapper {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ButtonBase = forwardRef(
data-size={size}
data-variant={variant}
data-label-wrap={labelWrap}
data-has-count={count !== undefined ? true : undefined}
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
.filter(descriptionID => Boolean(descriptionID))
.join(' ')}
Expand Down Expand Up @@ -225,6 +226,7 @@ const ButtonBase = forwardRef(
data-size={size}
data-variant={variant}
data-label-wrap={labelWrap}
data-has-count={count !== undefined ? true : undefined}
aria-describedby={[loadingAnnouncementID, ariaDescribedBy]
.filter(descriptionID => Boolean(descriptionID))
.join(' ')}
Expand Down
Loading