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

Add flex-shrink to IconButton + tests #5467

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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/short-fireants-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Add `flex-shrink` to IconButton
34 changes: 34 additions & 0 deletions e2e/components/IconButton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,38 @@ test.describe('IconButton', () => {
})
}
})

test.describe('Flex', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-iconbutton-devonly--icon-button-within-flex-container',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`IconButton.Flex.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-iconbutton-devonly--icon-button-within-flex-container',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: theme !== 'dark_dimmed',
},
},
})
})
})
}
})
})
1 change: 1 addition & 0 deletions packages/react/src/Button/ButtonBase.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
/* stylelint-disable-next-line primer/spacing */
padding: unset;
place-content: center;
flex-shrink: 0;

&:where([data-size='small']) {
width: var(--control-small-size);
Expand Down
14 changes: 14 additions & 0 deletions packages/react/src/Button/IconButton.dev.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {BoldIcon, ChevronDownIcon} from '@primer/octicons-react'
import React from 'react'
import {IconButton} from '.'
import Box from '../Box'
import {Stack} from '../Stack'

export default {
title: 'Components/IconButton/DevOnly',
Expand Down Expand Up @@ -38,3 +39,16 @@ export const CustomSizeWithStyleProp = () => (
/>
</Box>
)

export const IconButtonWithinFlexContainer = () => (
<Stack direction="horizontal">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</span>

<IconButton icon={BoldIcon} aria-label="Icon button" />
</Stack>
)
4 changes: 4 additions & 0 deletions packages/react/src/TreeView/TreeView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
display: flex;
color: var(--fgColor-muted);
grid-area: leadingAction;

& > button {
flex-shrink: 1;
}
}

.TreeViewItemLevelLine {
Expand Down
4 changes: 4 additions & 0 deletions packages/react/src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ const UlBox = toggleStyledComponent(
display: flex;
color: ${get('colors.fg.muted')};
grid-area: leadingAction;

& > button {
flex-shrink: 1;
}
}

.PRIVATE_TreeView-item-level-line {
Expand Down
Loading