Skip to content

Commit

Permalink
Corrects styling on Buttons that only have a count and icon (#5448
Browse files Browse the repository at this point in the history
)

* adds 'count' prop to IconButton

* adds VRT for IconButton with trailing counter

* updates IconButton component API docs

* adds changeset

* test(vrt): update snapshots

* adds 'count' to IconButton Playground story

* addresses feedback to modify component API

* modifies changeset

* reverts new IconButton VRT

* reverts new IconButton stories

* test(vrt): update snapshots

* appeases the linter

* add vrt

* test(vrt): update snapshots

---------

Co-authored-by: mperrotti <[email protected]>
Co-authored-by: Katie Langerman <[email protected]>
Co-authored-by: langermank <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent 3f68caf commit 00600f7
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 3 deletions.
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).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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

0 comments on commit 00600f7

Please sign in to comment.