Skip to content

Commit

Permalink
[TabsList] Drop component prop (#37042)
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 authored Apr 28, 2023
1 parent 988e0ad commit 0476b66
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
1 change: 0 additions & 1 deletion docs/pages/base/api/tabs-list.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"props": {
"children": { "type": { "name": "node" } },
"component": { "type": { "name": "elementType" } },
"slotProps": {
"type": { "name": "shape", "description": "{ root?: func<br>&#124;&nbsp;object }" },
"default": "{}"
Expand Down
1 change: 0 additions & 1 deletion docs/translations/api-docs-base/tabs-list/tabs-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"componentDescription": "",
"propDescriptions": {
"children": "The content of the component.",
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"slotProps": "The props used for each slot inside the TabsList.",
"slots": "The components used for each slot inside the TabsList. Either a string to use a HTML element or a component. See <a href=\"#slots\">Slots API</a> below for more details."
},
Expand Down
16 changes: 10 additions & 6 deletions packages/mui-base/src/TabsList/TabsList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ const polymorphicComponentTest = () => {
{/* @ts-expect-error */}
<TabsList invalidProp={0} />

<TabsList component="a" href="#" />
<TabsList<'a'> slots={{ root: 'a' }} href="#" />

<TabsList component={CustomComponent} stringProp="test" numberProp={0} />
<TabsList<typeof CustomComponent>
slots={{ root: CustomComponent }}
stringProp="test"
numberProp={0}
/>
{/* @ts-expect-error */}
<TabsList component={CustomComponent} />
<TabsList<typeof CustomComponent> slots={{ root: CustomComponent }} />

<TabsList
component="button"
<TabsList<'button'>
slots={{ root: 'button' }}
onClick={(e: React.MouseEvent<HTMLButtonElement>) => e.currentTarget.checkValidity()}
/>

<TabsList<'button'>
component="button"
slots={{ root: 'button' }}
ref={(elem) => {
expectType<HTMLButtonElement | null, typeof elem>(elem);
}}
Expand Down
1 change: 1 addition & 0 deletions packages/mui-base/src/TabsList/TabsList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('<TabsList />', () => {
},
skip: [
'reactTestRenderer', // Need to be wrapped with TabsContext
'componentProp',
],
}));
});
14 changes: 4 additions & 10 deletions packages/mui-base/src/TabsList/TabsList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { OverridableComponent } from '@mui/types';
import composeClasses from '../composeClasses';
import { useSlotProps, WithOptionalOwnerState } from '../utils';
import { PolymorphicComponent, useSlotProps, WithOptionalOwnerState } from '../utils';
import { getTabsListUtilityClass } from './tabsListClasses';
import {
TabsListOwnerState,
Expand Down Expand Up @@ -38,7 +37,7 @@ const TabsList = React.forwardRef(function TabsList<RootComponentType extends Re
props: TabsListProps<RootComponentType>,
forwardedRef: React.ForwardedRef<Element>,
) {
const { children, component, slotProps = {}, slots = {}, ...other } = props;
const { children, slotProps = {}, slots = {}, ...other } = props;

const { isRtl, orientation, getRootProps, contextValue } = useTabsList({
rootRef: forwardedRef,
Expand All @@ -52,7 +51,7 @@ const TabsList = React.forwardRef(function TabsList<RootComponentType extends Re

const classes = useUtilityClasses(ownerState);

const TabsListRoot: React.ElementType = component ?? slots.root ?? 'div';
const TabsListRoot: React.ElementType = slots.root ?? 'div';
const tabsListRootProps: WithOptionalOwnerState<TabsListRootSlotProps> = useSlotProps({
elementType: TabsListRoot,
getSlotProps: getRootProps,
Expand All @@ -67,7 +66,7 @@ const TabsList = React.forwardRef(function TabsList<RootComponentType extends Re
<TabsListRoot {...tabsListRootProps}>{children}</TabsListRoot>
</TabsListProvider>
);
}) as OverridableComponent<TabsListTypeMap>;
}) as PolymorphicComponent<TabsListTypeMap>;

TabsList.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
Expand All @@ -78,11 +77,6 @@ TabsList.propTypes /* remove-proptypes */ = {
* The content of the component.
*/
children: PropTypes.node,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside the TabsList.
* @default {}
Expand Down
8 changes: 3 additions & 5 deletions packages/mui-base/src/TabsList/TabsList.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { OverrideProps, Simplify } from '@mui/types';
import { Simplify } from '@mui/types';
import { UseTabsListRootSlotProps } from '../useTabsList';
import { SlotComponentProps } from '../utils';
import { PolymorphicProps, SlotComponentProps } from '../utils';

export interface TabsListRootSlotPropsOverrides {}

Expand Down Expand Up @@ -44,9 +44,7 @@ export interface TabsListTypeMap<

export type TabsListProps<
RootComponentType extends React.ElementType = TabsListTypeMap['defaultComponent'],
> = OverrideProps<TabsListTypeMap<{}, RootComponentType>, RootComponentType> & {
component?: RootComponentType;
};
> = PolymorphicProps<TabsListTypeMap<{}, RootComponentType>, RootComponentType>;

export type TabsListOwnerState = Simplify<
TabsListOwnProps & {
Expand Down

0 comments on commit 0476b66

Please sign in to comment.