Skip to content
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/deprecate-input-contrast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

TextInput and Textarea: Deprecate the `contrast` prop. Omit it to use the default background.
3 changes: 2 additions & 1 deletion packages/react/src/TextInput/TextInput.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"name": "contrast",
"type": "boolean",
"defaultValue": "false",
"description": "Changes background color to a higher contrast color"
"deprecated": true,
"description": "Deprecated. Omit this prop to use the default background."
},
{
"name": "size",
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/TextInput/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ describe('TextInput', () => {
expect(render(<TextInput name="zipcode" contrast value="" />).container).toMatchSnapshot()
})

it.each([
{label: 'true', props: {contrast: true}},
{label: 'false', props: {contrast: false}},
{label: 'omitted', props: {}},
])('preserves deprecated contrast behavior when $label', ({props}) => {
const {container} = render(<TextInput name="zipcode" {...props} />)
const input = screen.getByRole('textbox')

if (props.contrast) {
expect(container.firstElementChild).toHaveAttribute('data-contrast', 'true')
} else {
expect(container.firstElementChild).not.toHaveAttribute('data-contrast')
}

expect(input).not.toHaveAttribute('contrast')
expect(input).toBeEnabled()
})

it('renders monospace', () => {
expect(render(<TextInput name="zipcode" monospace value="" />).container).toMatchSnapshot()
})
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/Textarea/Textarea.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"name": "contrast",
"type": "boolean",
"defaultValue": "false",
"description": "Changes background color to a higher contrast color"
"deprecated": true,
"description": "Deprecated. Omit this prop to use the default background."
},
{
"name": "validationStatus",
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/Textarea/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ describe('Textarea', () => {
expect(screen.getByRole('textbox')).toBeInTheDocument()
})

it.each([
{label: 'true', props: {contrast: true}},
{label: 'false', props: {contrast: false}},
{label: 'omitted', props: {}},
])('preserves deprecated contrast behavior when $label', ({props}) => {
const {container} = render(<Textarea {...props} />)
const textarea = screen.getByRole('textbox')

if (props.contrast) {
expect(container.firstElementChild).toHaveAttribute('data-contrast', 'true')
} else {
expect(container.firstElementChild).not.toHaveAttribute('data-contrast')
}

expect(textarea).not.toHaveAttribute('contrast')
expect(textarea).toBeEnabled()
})

it('renders data-component attribute', () => {
render(<Textarea />)
expect(screen.getByRole('textbox')).toHaveAttribute('data-component', 'Textarea')
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type TextareaProps = {
*/
autoSize?: boolean
/**
* apply a high contrast color to background
* @deprecated Omit this prop to use the default background.
*/
contrast?: boolean
/**
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/internal/components/TextInputWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export type TextInputSizes = 'small' | 'medium' | 'large'

type StyledTextInputBaseWrapperProps = {
block?: boolean
/**
* @deprecated Omit this prop to use the default background.
*/
contrast?: boolean
disabled?: boolean
hasTrailingAction?: boolean
Expand Down
Loading