Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Select] Fixing typescript not recognizing the 'component' property on the 'MenuListProps' #23876

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/material-ui/src/List/List.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,21 @@ export interface ListTypeMap<P = {}, D extends React.ElementType = 'ul'> {
*
* - [List API](https://material-ui.com/api/list/)
*/
declare const List: OverridableComponent<ListTypeMap>;
declare const List: OverridableList;

export interface OverridableList extends OverridableComponent<ListTypeMap> {
<D extends React.ElementType = ListTypeMap['defaultComponent'], P = {}>(
props: ListPropsWithComponent<D, P>
): JSX.Element;
}

export type ListClassKey = keyof NonNullable<ListTypeMap['props']['classes']>;

export type ListPropsWithComponent<
D extends React.ElementType = ListTypeMap['defaultComponent'],
P = {}
> = { component?: D } & ListProps<D, P>;

export type ListProps<
D extends React.ElementType = ListTypeMap['defaultComponent'],
P = {}
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ List.propTypes = {
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
component: PropTypes /* @typescript-to-proptypes-ignore */.elementType,
/**
* If `true`, compact vertical padding designed for keyboard and mouse input is used for
* the list and list items.
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/MenuList/MenuList.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ListProps } from '../List';
import { ListPropsWithComponent } from '../List';

export interface MenuListProps extends ListProps {
export interface MenuListProps extends ListPropsWithComponent<React.ElementType> {
/**
* If `true`, will focus the `[role="menu"]` container and move into tab order.
* @default false
Expand Down
8 changes: 8 additions & 0 deletions packages/material-ui/src/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ function genericValueTest() {
{/* Whoops. The value in onChange won't be a string */}
<MenuItem value={2} />
</Select>;

<Select
MenuProps={{
MenuListProps: {
component: 'div',
},
}}
/>;
}