Skip to content

Commit 8558ae5

Browse files
authored
Button size was incorrect. (#1864)
* Make small fixes to the button * Create violet-actors-battle.md
1 parent 004c462 commit 8558ae5

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

.changeset/violet-actors-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Small fixes to icon button sizes. Truthy checks for children props

src/Button2/ButtonBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ButtonBase = forwardRef<HTMLElement, ButtonProps>(
2626
<LeadingIcon />
2727
</Box>
2828
)}
29-
<span data-component="text">{children}</span>
29+
{children && <span data-component="text">{children}</span>}
3030
{TrailingIcon && (
3131
<Box as="span" data-component="trailingIcon" sx={{...iconWrapStyles, ml: 2}}>
3232
<TrailingIcon />

src/Button2/IconButton.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>((props, forwar
1818
])
1919
return (
2020
<StyledButton aria-labelledby={iconLabelId} sx={sxStyles} {...rest} ref={forwardedRef}>
21-
<span id={iconLabelId} hidden={true}>
22-
{iconLabel}
23-
</span>
21+
{iconLabel && (
22+
<span id={iconLabelId} hidden={true}>
23+
{iconLabel}
24+
</span>
25+
)}
2426
<Box as="span" sx={{display: 'inline-block'}}>
2527
<Icon />
2628
</Box>

src/Button2/styles.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ export const getVariantStyles = (variant: VariantType = 'default', theme?: Theme
152152
return style[variant]
153153
}
154154

155+
/* The button heights have to amount to
156+
small - 28
157+
medium - 32
158+
large - 34
159+
In icon these have to be square.
160+
*/
155161
export const getSizeStyles = (size = 'medium', variant: VariantType = 'default', iconOnly: boolean) => {
156162
let paddingY, paddingX, fontSize
157163
switch (size) {
@@ -172,10 +178,10 @@ export const getSizeStyles = (size = 'medium', variant: VariantType = 'default',
172178
fontSize = 1
173179
}
174180
if (iconOnly) {
175-
paddingX = paddingY + 2
181+
paddingX = paddingY + 3 // to make it a square
176182
}
177183
if (variant === 'invisible') {
178-
paddingY = paddingY + 1
184+
paddingY = paddingY + 1 // to make up for absence of border
179185
}
180186
return {
181187
paddingY: `${paddingY}px`,

src/__tests__/Button2.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ describe('Button', () => {
9393
it('styles icon only button to make it a square', async () => {
9494
const container = render(<IconButton icon={SearchIcon} iconLabel="Search icon only button" />)
9595
const IconOnlyButton = await container.findByRole('button')
96-
expect(IconOnlyButton).toHaveStyleRule('padding-right', '7px')
96+
expect(IconOnlyButton).toHaveStyleRule('padding-right', '8px')
9797
})
9898
})

src/__tests__/__snapshots__/Button2.test.tsx.snap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ exports[`Button renders consistently 1`] = `
8282
8383
<button
8484
className="c0"
85-
>
86-
<span
87-
data-component="text"
88-
/>
89-
</button>
85+
/>
9086
`;
9187

9288
exports[`Button styles danger button appropriately 1`] = `

0 commit comments

Comments
 (0)