Skip to content

Remove deprecated Button component #4807

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

Merged
merged 15 commits into from
Sep 26, 2024
Merged
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/strong-tables-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": major
---

Remove deprecated `Button` component
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {useCallback, useRef, useState} from 'react'
import {ActionMenu} from '../deprecated/ActionMenu'
import BaseStyles from '../BaseStyles'
import Box from '../Box'
import Button from '../deprecated/Button/Button'
import {Button} from '../Button'
import {ConfirmationDialog, useConfirm} from './ConfirmationDialog'
import theme from '../theme'
import {ThemeProvider} from '../ThemeProvider'
Expand Down
19 changes: 6 additions & 13 deletions packages/react/src/Details/__tests__/Details.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {render} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import React from 'react'
import {Details, useDetails, Box} from '../..'
import {Button, ButtonPrimary} from '../../deprecated'
import type {ButtonProps} from '../../deprecated/Button/Button'
import {Details, useDetails, Box, Button} from '../..'
import type {ButtonProps} from '../../Button'
import {behavesAsComponent, checkExports} from '../../utils/testing'
import axe from 'axe-core'

Expand Down Expand Up @@ -42,9 +41,7 @@ describe('Details', () => {
const {getDetailsProps, open} = useDetails({closeOnOutsideClick: true})
return (
<Details {...getDetailsProps()} data-testid="details">
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
</Details>
)
}
Expand All @@ -64,9 +61,7 @@ describe('Details', () => {
const {getDetailsProps, setOpen, open} = useDetails({closeOnOutsideClick: true, defaultOpen: true})
return (
<Details {...getDetailsProps()} data-testid="details">
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
<CloseButton onClick={() => setOpen(false)}>Close</CloseButton>
</Details>
)
Expand All @@ -86,11 +81,9 @@ describe('Details', () => {
const {getDetailsProps, open} = useDetails({closeOnOutsideClick: true, defaultOpen: true})
return (
<Details {...getDetailsProps()}>
<Button as="summary" data-testid="summary">
{open ? 'Open' : 'Closed'}
</Button>
<summary data-testid="summary">{open ? 'Open' : 'Closed'}</summary>
<Box>
<ButtonPrimary>test</ButtonPrimary>
<Button variant="primary">test</Button>
</Box>
</Details>
)
Expand Down
23 changes: 12 additions & 11 deletions packages/react/src/Overlay/Overlay.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {useRef, useState} from 'react'
import {Overlay, Box, Text} from '..'
import {ButtonDanger, Button} from '../deprecated'
import {Overlay, Box, Text, Button} from '..'
import {render, waitFor, fireEvent} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import axe from 'axe-core'
Expand Down Expand Up @@ -43,7 +42,9 @@ const TestComponent = ({initialFocus, callback}: TestComponentSettings) => {
>
<Box display="flex" flexDirection="column" p={2}>
<Text>Are you sure?</Text>
<ButtonDanger onClick={closeOverlay}>Cancel</ButtonDanger>
<Button variant="danger" onClick={closeOverlay}>
Cancel
</Button>
<Button onClick={closeOverlay} ref={confirmButtonRef}>
Confirm
</Button>
Expand All @@ -65,19 +66,19 @@ describe('Overlay', () => {

it('should focus element passed into function', async () => {
const user = userEvent.setup()
const {getByText} = render(<TestComponent initialFocus="button" />)
await user.click(getByText('open overlay'))
await waitFor(() => getByText('Confirm'))
const confirmButton = getByText('Confirm')
const {getByRole} = render(<TestComponent initialFocus="button" />)
await user.click(getByRole('button', {name: 'open overlay'}))
await waitFor(() => getByRole('button', {name: 'Confirm'}))
const confirmButton = getByRole('button', {name: 'Confirm'})
expect(document.activeElement).toEqual(confirmButton)
})

it('should focus first element when nothing is passed', async () => {
const user = userEvent.setup()
const {getByText} = render(<TestComponent />)
await user.click(getByText('open overlay'))
await waitFor(() => getByText('Cancel'))
const cancelButton = getByText('Cancel')
const {getByRole} = render(<TestComponent />)
await user.click(getByRole('button', {name: 'open overlay'}))
await waitFor(() => getByRole('button', {name: 'Cancel'}))
const cancelButton = getByRole('button', {name: 'Cancel'})
expect(document.activeElement).toEqual(cancelButton)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/__tests__/AnchoredOverlay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {AnchoredOverlay} from '../AnchoredOverlay'
import {behavesAsComponent, checkExports} from '../utils/testing'
import {render as HTMLRender, fireEvent} from '@testing-library/react'
import axe from 'axe-core'
import {Button} from '../deprecated'
import {Button} from '../Button'
import theme from '../theme'
import BaseStyles from '../BaseStyles'
import {ThemeProvider} from '../ThemeProvider'
Expand Down
Loading
Loading