mirror of
https://github.com/SomboChea/ui
synced 2026-01-17 00:25:50 +07:00
fix: listItem Component - Introduced ForwardRef (#183)
* refactor: introduced forwardRef * fix: fixed button prop listItem * chore: rollback package upgrade * fix: fixed snap
This commit is contained in:
committed by
Juan Picado @jotadeveloper
parent
d2c1130efd
commit
82d7107de7
20
src/muiComponents/ListItem/ListItem.tsx
Normal file
20
src/muiComponents/ListItem/ListItem.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { default as MaterialUIListItem, ListItemProps } from '@material-ui/core/ListItem';
|
||||
|
||||
type ListItemRef<T extends boolean = false> = T extends true ? HTMLDivElement : HTMLLIElement;
|
||||
|
||||
interface Props<T extends boolean = false> extends Omit<ListItemProps, 'button'> {
|
||||
button?: T;
|
||||
}
|
||||
|
||||
const ListItem = forwardRef(function ListItem<T extends boolean>({ button, ...props }: Props<T>, ref: React.Ref<ListItemRef<T>>) {
|
||||
// it seems typescript has some discrimination type limitions. Please see: https://github.com/mui-org/material-ui/issues/14971
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return <MaterialUIListItem {...props} button={button as any} innerRef={ref} />;
|
||||
});
|
||||
|
||||
ListItem.defaultProps = {
|
||||
button: false,
|
||||
};
|
||||
|
||||
export default ListItem;
|
||||
1
src/muiComponents/ListItem/index.ts
Normal file
1
src/muiComponents/ListItem/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default } from './ListItem';
|
||||
Reference in New Issue
Block a user