Skip to content

Commit 5e423d2

Browse files
committed
[Tabs] Type onChange as a generic react event
1 parent 5447eaa commit 5e423d2

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

packages/material-ui/src/OverridableComponent.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type OverrideProps<
2929
C extends React.ElementType
3030
> = (
3131
& BaseProps<M>
32-
& Omit<React.ComponentPropsWithRef<C>, keyof CommonProps<M>>
32+
& Omit<React.ComponentPropsWithRef<C>, keyof BaseProps<M>>
3333
);
3434

3535
/**

packages/material-ui/src/Tab/Tab.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TabTypeMap<P = {}, D extends React.ElementType = 'div'> = ExtendButt
88
fullWidth?: boolean;
99
icon?: string | React.ReactElement;
1010
label?: React.ReactNode;
11-
onChange?: (event: React.ChangeEvent<{ checked: boolean }>, value: any) => void;
11+
onChange?: (event: React.SyntheticEvent, value: any) => void;
1212
onClick?: React.EventHandler<any>;
1313
selected?: boolean;
1414
style?: React.CSSProperties;

packages/material-ui/src/Tabs/Tabs.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import ButtonBase from '../ButtonBase';
33
import { TabScrollButtonProps } from '../TabScrollButton';
4+
import { TabProps } from '../Tab';
45
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
56

67
export interface TabsTypeMap<P = {}, D extends React.ElementType = typeof ButtonBase> {
@@ -41,7 +42,7 @@ export interface TabsTypeMap<P = {}, D extends React.ElementType = typeof Button
4142
* @param {object} event The event source of the callback
4243
* @param {any} value We default to the index of the child (number)
4344
*/
44-
onChange?: (event: React.ChangeEvent<{}>, value: any) => void;
45+
onChange?: TabProps['onChange'];
4546
/**
4647
* The tabs orientation (layout flow direction).
4748
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react';
2+
import Tabs from '@material-ui/core/Tabs';
3+
4+
function testOnChange() {
5+
function handleTabsChange(event: React.SyntheticEvent, tabsValue: unknown) {}
6+
<Tabs onChange={handleTabsChange} />;
7+
8+
function handleChange(event: React.ChangeEvent) {}
9+
// @ts-expect-error internally it's either FocusEvent or ClickEvent
10+
<Tabs onChange={handleChange} />;
11+
}

packages/material-ui/test/typescript/OverridableComponent.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ declare const Foo: OverridableComponent<{
133133
numberProp={3}
134134
/>;
135135

136-
// @ts-expect-error
136+
// inconsistent typing of base vs override prop
137+
// but the assumption is that `Foo` intercepts `inconsistentProp` and doesn't forward it
137138
<Foo
138139
component={MyIncompatibleComponent1} // inconsistent typing of base vs override prop
139140
numberProp={3}

0 commit comments

Comments
 (0)