Skip to content

Commit bc34f9a

Browse files
authored
[core] Type custom onChange implementations with a generic react event (#21552)
1 parent bb5ae49 commit bc34f9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+164
-46
lines changed

docs/pages/api-docs/accordion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The `MuiAccordion` name can be used for providing [default props](/customization
3333
| <span class="prop-name">defaultExpanded</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, expands the accordion by default. |
3434
| <span class="prop-name">disabled</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the accordion will be displayed in a disabled state. |
3535
| <span class="prop-name">expanded</span> | <span class="prop-type">bool</span> | | If `true`, expands the accordion, otherwise collapse it. Setting this prop enables control over the accordion. |
36-
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the expand/collapse state is changed.<br><br>**Signature:**<br>`function(event: object, expanded: boolean) => void`<br>*event:* The event source of the callback.<br>*expanded:* The `expanded` state of the accordion. |
36+
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the expand/collapse state is changed.<br><br>**Signature:**<br>`function(event: object, expanded: boolean) => void`<br>*event:* The event source of the callback. **Warning**: This is a generic event not a change event.<br>*expanded:* The `expanded` state of the accordion. |
3737
| <span class="prop-name">square</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, rounded corners are disabled. |
3838
| <span class="prop-name">TransitionComponent</span> | <span class="prop-type">elementType</span> | <span class="prop-default">Collapse</span> | The component used for the collapse effect. [Follow this guide](/components/transitions/#transitioncomponent-prop) to learn more about the requirements for this component. |
3939
| <span class="prop-name">TransitionProps</span> | <span class="prop-type">object</span> | | Props applied to the [`Transition`](http://reactcommunity.org/react-transition-group/transition#Transition-props) element. |

docs/pages/api-docs/bottom-navigation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The `MuiBottomNavigation` name can be used for providing [default props](/custom
3131
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. |
3232
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
3333
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'div'</span> | The component used for the root node. Either a string to use a HTML element or a component. |
34-
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: any) => void`<br>*event:* The event source of the callback.<br>*value:* We default to the index of the child. |
34+
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: any) => void`<br>*event:* The event source of the callback. **Warning**: This is a generic event not a change event.<br>*value:* We default to the index of the child. |
3535
| <span class="prop-name">showLabels</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, all `BottomNavigationAction`s will show their labels. By default, only the selected `BottomNavigationAction` will show its label. |
3636
| <span class="prop-name">value</span> | <span class="prop-type">any</span> | | The value of the currently selected `BottomNavigationAction`. |
3737

docs/pages/api-docs/slider.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ The `MuiSlider` name can be used for providing [default props](/customization/gl
4242
| <span class="prop-name">max</span> | <span class="prop-type">number</span> | <span class="prop-default">100</span> | The maximum allowed value of the slider. Should not be equal to min. |
4343
| <span class="prop-name">min</span> | <span class="prop-type">number</span> | <span class="prop-default">0</span> | The minimum allowed value of the slider. Should not be equal to max. |
4444
| <span class="prop-name">name</span> | <span class="prop-type">string</span> | | Name attribute of the hidden `input` element. |
45-
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback function that is fired when the slider's value changed.<br><br>**Signature:**<br>`function(event: object, value: number \| number[]) => void`<br>*event:* The event source of the callback.<br>*value:* The new value. |
46-
| <span class="prop-name">onChangeCommitted</span> | <span class="prop-type">func</span> | | Callback function that is fired when the `mouseup` is triggered.<br><br>**Signature:**<br>`function(event: object, value: number \| number[]) => void`<br>*event:* The event source of the callback.<br>*value:* The new value. |
45+
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback function that is fired when the slider's value changed.<br><br>**Signature:**<br>`function(event: object, value: number \| number[]) => void`<br>*event:* The event source of the callback. **Warning**: This is a generic event not a change event.<br>*value:* The new value. |
46+
| <span class="prop-name">onChangeCommitted</span> | <span class="prop-type">func</span> | | Callback function that is fired when the `mouseup` is triggered.<br><br>**Signature:**<br>`function(event: object, value: number \| number[]) => void`<br>*event:* The event source of the callback. **Warning**: This is a generic event not a change event.<br>*value:* The new value. |
4747
| <span class="prop-name">orientation</span> | <span class="prop-type">'horizontal'<br>&#124;&nbsp;'vertical'</span> | <span class="prop-default">'horizontal'</span> | The slider orientation. |
4848
| <span class="prop-name">scale</span> | <span class="prop-type">func</span> | <span class="prop-default">(x) => x</span> | A transformation function, to change the scale of the slider. |
4949
| <span class="prop-name">step</span> | <span class="prop-type">number</span> | <span class="prop-default">1</span> | The granularity with which the slider can step through values. (A "discrete" slider.) The `min` prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step.<br>When step is `null`, the thumb can only be slid onto marks provided with the `marks` prop. |

docs/pages/api-docs/tabs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The `MuiTabs` name can be used for providing [default props](/customization/glob
3636
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
3737
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'div'</span> | The component used for the root node. Either a string to use a HTML element or a component. |
3838
| <span class="prop-name">indicatorColor</span> | <span class="prop-type">'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'secondary'</span> | Determines the color of the indicator. |
39-
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: any) => void`<br>*event:* The event source of the callback<br>*value:* We default to the index of the child (number) |
39+
| <span class="prop-name">onChange</span> | <span class="prop-type">func</span> | | Callback fired when the value changes.<br><br>**Signature:**<br>`function(event: object, value: any) => void`<br>*event:* The event source of the callback. **Warning**: This is a generic event not a change event.<br>*value:* We default to the index of the child (number) |
4040
| <span class="prop-name">orientation</span> | <span class="prop-type">'horizontal'<br>&#124;&nbsp;'vertical'</span> | <span class="prop-default">'horizontal'</span> | The tabs orientation (layout flow direction). |
4141
| <span class="prop-name">ScrollButtonComponent</span> | <span class="prop-type">elementType</span> | <span class="prop-default">TabScrollButton</span> | The component used to render the scroll buttons. |
4242
| <span class="prop-name">scrollButtons</span> | <span class="prop-type">'auto'<br>&#124;&nbsp;'desktop'<br>&#124;&nbsp;'off'<br>&#124;&nbsp;'on'</span> | <span class="prop-default">'auto'</span> | Determine behavior of scroll buttons when tabs are set to scroll:<br>- `auto` will only present them when not all the items are visible. - `desktop` will only present them on medium and larger viewports. - `on` will always present them. - `off` will never present them. |

docs/src/pages/components/accordion/ControlledAccordions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function ControlledAccordions() {
2828
const [expanded, setExpanded] = React.useState<string | false>(false);
2929

3030
const handleChange = (panel: string) => (
31-
event: React.ChangeEvent<{}>,
31+
event: React.SyntheticEvent,
3232
isExpanded: boolean,
3333
) => {
3434
setExpanded(isExpanded ? panel : false);

docs/src/pages/components/accordion/CustomizedAccordions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function CustomizedAccordions() {
5050
const [expanded, setExpanded] = React.useState<string | false>('panel1');
5151

5252
const handleChange = (panel: string) => (
53-
event: React.ChangeEvent<{}>,
53+
event: React.SyntheticEvent,
5454
newExpanded: boolean,
5555
) => {
5656
setExpanded(newExpanded ? panel : false);

docs/src/pages/components/bottom-navigation/LabelBottomNavigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function LabelBottomNavigation() {
1717
const classes = useStyles();
1818
const [value, setValue] = React.useState('recents');
1919

20-
const handleChange = (event: React.ChangeEvent<{}>, newValue: string) => {
20+
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
2121
setValue(newValue);
2222
};
2323

docs/src/pages/components/slider/ContinuousSlider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export default function ContinuousSlider() {
1616
const classes = useStyles();
1717
const [value, setValue] = React.useState<number>(30);
1818

19-
const handleChange = (event: any, newValue: number | number[]) => {
19+
const handleChange = (
20+
event: React.SyntheticEvent,
21+
newValue: number | number[],
22+
) => {
2023
setValue(newValue as number);
2124
};
2225

docs/src/pages/components/slider/InputSlider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export default function InputSlider() {
2121
number | string | Array<number | string>
2222
>(30);
2323

24-
const handleSliderChange = (event: any, newValue: number | number[]) => {
24+
const handleSliderChange = (
25+
event: React.SyntheticEvent,
26+
newValue: number | number[],
27+
) => {
2528
setValue(newValue);
2629
};
2730

docs/src/pages/components/slider/NonLinearSlider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ function valueLabelFormat(value: number) {
1313
export default function NonLinearSlider() {
1414
const [value, setValue] = React.useState<number | number[]>(1);
1515

16-
const handleChange = (event: any, newValue: number | number[]) => {
16+
const handleChange = (
17+
event: React.SyntheticEvent,
18+
newValue: number | number[],
19+
) => {
1720
setValue(newValue);
1821
};
1922

0 commit comments

Comments
 (0)