Skip to content

Commit

Permalink
[MenuItem][base] Drop component prop
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Apr 26, 2023
1 parent a5d1893 commit cb3fea7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
1 change: 0 additions & 1 deletion docs/pages/base/api/menu-item.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"props": {
"component": { "type": { "name": "elementType" } },
"label": { "type": { "name": "string" } },
"slotProps": {
"type": { "name": "shape", "description": "{ root?: func<br>&#124;&nbsp;object }" },
Expand Down
1 change: 0 additions & 1 deletion docs/translations/api-docs-base/menu-item/menu-item.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"componentDescription": "",
"propDescriptions": {
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"label": "A text representation of the menu item&#39;s content. Used for keyboard text navigation matching.",
"slotProps": "The props used for each slot inside the MenuItem.",
"slots": "The components used for each slot inside the MenuItem. Either a string to use a HTML element or a component. See <a href=\"#slots\">Slots API</a> below for more details."
Expand Down
34 changes: 27 additions & 7 deletions packages/mui-base/src/MenuItem/MenuItem.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,39 @@ const polymorphicComponentTest = () => {
{/* @ts-expect-error */}
<MenuItem invalidProp={0} />

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

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

<MenuItem
component="button"
{/* @ts-expect-error required props not specified */}
<MenuItem<typeof CustomComponent>
slots={{
root: CustomComponent,
}}
/>

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

<MenuItem<'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/MenuItem/MenuItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('<MenuItem />', () => {
},
},
skip: [
'componentProp',
'reactTestRenderer', // Need to be wrapped in MenuContext
],
}));
Expand Down
12 changes: 3 additions & 9 deletions packages/mui-base/src/MenuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { OverridableComponent } from '@mui/types';
import { PolymorphicComponent } from '../utils/PolymorphicComponent';
import { MenuItemOwnerState, MenuItemProps, MenuItemTypeMap } from './MenuItem.types';
import { getMenuItemUtilityClass } from './menuItemClasses';
import useMenuItem from '../useMenuItem';
Expand Down Expand Up @@ -35,7 +35,6 @@ const MenuItem = React.forwardRef(function MenuItem<RootComponentType extends Re
const {
children,
disabled: disabledProp = false,
component,
label,
slotProps = {},
slots = {},
Expand All @@ -52,7 +51,7 @@ const MenuItem = React.forwardRef(function MenuItem<RootComponentType extends Re

const classes = useUtilityClasses(ownerState);

const Root = component ?? slots.root ?? 'li';
const Root = slots.root ?? 'li';
const rootProps = useSlotProps({
elementType: Root,
getSlotProps: getRootProps,
Expand All @@ -63,7 +62,7 @@ const MenuItem = React.forwardRef(function MenuItem<RootComponentType extends Re
});

return <Root {...rootProps}>{children}</Root>;
}) as OverridableComponent<MenuItemTypeMap>;
}) as PolymorphicComponent<MenuItemTypeMap>;

MenuItem.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
Expand All @@ -74,11 +73,6 @@ MenuItem.propTypes /* remove-proptypes */ = {
* @ignore
*/
children: PropTypes.node,
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* @ignore
*/
Expand Down

0 comments on commit cb3fea7

Please sign in to comment.