Skip to content

Commit c43f514

Browse files
authored
chore(ui-react): add deprecation message to Expander onChange prop (#2674)
* chore(ui-react): add deprecation message to Expander onChange prop"
1 parent 405bff2 commit c43f514

File tree

8 files changed

+32
-24
lines changed

8 files changed

+32
-24
lines changed

.changeset/short-deers-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui-react": patch
3+
---
4+
5+
chore(ui-react): add deprecation message to Expander onChange prop

docs/src/pages/[platform]/components/expander/examples/ControlledSingleExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Expander, ExpanderItem } from '@aws-amplify/ui-react';
55
export const ControlledSingleExpander = () => {
66
const [value, setValue] = React.useState<string | string[]>();
77
return (
8-
<Expander type="single" value={value} onChange={setValue}>
8+
<Expander type="single" value={value} onValueChange={setValue}>
99
<ExpanderItem
1010
title="What do you call a deer with no eyes?"
1111
value="joke-1"

docs/src/pages/[platform]/components/expander/props-table.mdx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,15 @@ boolean
7878
<ResponsiveTableCell label="Description">Sets the Boolean &#96;disabled&#96; HTML attribute, which, when present, makes the element not mutable, focusable, or even submitted with the form</ResponsiveTableCell>
7979
</TableRow>
8080

81-
<TableRow>
82-
<ResponsiveTableCell label="Name">onChange</ResponsiveTableCell>
83-
<ResponsiveTableCell label="Type">
84-
```jsx
85-
(value?: string | string[]) => void
86-
```
87-
</ResponsiveTableCell>
88-
<ResponsiveTableCell label="Description">Event handler called when the expanded state of an item changes</ResponsiveTableCell>
89-
</TableRow>
90-
9181
<TableRow>
9282
<ResponsiveTableCell label="Name">onValueChange</ResponsiveTableCell>
9383
<ResponsiveTableCell label="Type">
94-
```jsx
95-
(value: string) => void
96-
```
97-
</ResponsiveTableCell>
98-
<ResponsiveTableCell label="Description">-</ResponsiveTableCell>
84+
```jsx
85+
(value?: string | string[]) => void
86+
```
87+
</ResponsiveTableCell>
88+
<ResponsiveTableCell label="Description">Event handler called when the expanded state of an item changes</ResponsiveTableCell>
9989
</TableRow>
100-
10190
<TableRow>
10291
<ResponsiveTableCell label="Name">style</ResponsiveTableCell>
10392
<ResponsiveTableCell label="Type">

docs/src/pages/[platform]/components/expander/react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To expand specific items by default, pass a `string` or `string[]` of value(s) t
114114

115115
### Controlled component
116116

117-
To use the Expander as controlled component, specify the `value` of the item(s) to expand and use in conjunction with `onChange`.
117+
To use the Expander as controlled component, specify the `value` of the item(s) to expand and use in conjunction with `onValueChange`.
118118

119119
<Example>
120120
<View>

packages/react/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = {
6969
'src/components/**/*',
7070
'src/helpers/**/*',
7171
'src/hooks/**/*',
72-
'src/primitives/+(shared|utils)/**/*',
72+
'src/primitives/+(shared|utils|E*)/**/*',
7373
'src/studio',
7474
// 'src/primitives/**/*',
7575
],

packages/react/src/primitives/Expander/Expander.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as React from 'react';
22
import { Root } from '@radix-ui/react-accordion';
33
import classNames from 'classnames';
44

5+
import { useDeprecationWarning } from '../../hooks/useDeprecationWarning';
6+
57
import { ComponentClassNames } from '../shared/constants';
68
import { ExpanderProps } from '../types/expander';
79
import { Primitive } from '../types/view';
@@ -14,7 +16,6 @@ const ExpanderPrimitive: Primitive<ExpanderProps, typeof Root> = (
1416
defaultValue,
1517
isCollapsible,
1618
onChange,
17-
// It is not in use but remove it from rest to avoid type errors
1819
onValueChange,
1920
testId,
2021
type = 'single',
@@ -26,13 +27,21 @@ const ExpanderPrimitive: Primitive<ExpanderProps, typeof Root> = (
2627
// Throw away baseStyleProps and flexContainerStyleProps since they won't work on Root element
2728
const { rest } = splitPrimitiveProps(_rest);
2829

30+
const handleValueChange = onValueChange ?? onChange;
31+
32+
useDeprecationWarning({
33+
shouldWarn: !!onChange,
34+
message:
35+
'Expander `onChange` prop will be deprecated in the next major release of @aws-amplify/ui-react. Please replace usage with `onValueChange`.',
36+
});
37+
2938
const expander =
3039
type === 'multiple' ? (
3140
<Root
3241
className={classNames(ComponentClassNames.Expander, className)}
3342
data-testid={testId}
3443
defaultValue={defaultValue as string[]}
35-
onValueChange={onChange}
44+
onValueChange={handleValueChange as (value?: string[]) => void}
3645
ref={ref}
3746
type={type}
3847
value={value as string[]}
@@ -46,7 +55,7 @@ const ExpanderPrimitive: Primitive<ExpanderProps, typeof Root> = (
4655
collapsible={isCollapsible}
4756
data-testid={testId}
4857
defaultValue={defaultValue as string}
49-
onValueChange={onChange}
58+
onValueChange={handleValueChange as (value?: string) => void}
5059
ref={ref}
5160
type={type}
5261
value={value as string}

packages/react/src/primitives/Expander/__tests__/Expander.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Expander: ', () => {
3030
({ value: initialValue, ...rest }, ref) => {
3131
const [value, setValue] = React.useState(initialValue);
3232
return (
33-
<Expander value={value} onChange={setValue} ref={ref} {...rest}>
33+
<Expander value={value} onValueChange={setValue} ref={ref} {...rest}>
3434
<ExpanderItem title="Section 1 title" value="item-1">
3535
content 1
3636
</ExpanderItem>

packages/react/src/primitives/types/expander.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ export interface ExpanderProps extends ViewProps {
2727
*/
2828
type?: ExpanderType;
2929

30+
/**
31+
* @deprecated replace usage with `onValueChange`
32+
*/
33+
onChange?: (value?: string | string[]) => void;
34+
3035
/**
3136
* @description
3237
* Event handler called when the expanded state of an item changes
3338
*/
34-
onChange?: (value?: string | string[]) => void;
39+
onValueChange?: (value?: string | string[]) => void;
3540
}
3641

3742
export interface ExpanderItemProps extends ViewProps {

0 commit comments

Comments
 (0)