>(function ListboxComponent(props, ref) {
const { children, ...other } = props;
const itemData: React.ReactChild[] = [];
(children as React.ReactChild[]).forEach(
(item: React.ReactChild & { children?: React.ReactChild[] }) => {
itemData.push(item);
itemData.push(...(item.children || []));
},
);
const theme = useTheme();
const smUp = useMediaQuery(theme.breakpoints.up('sm'), {
noSsr: true,
});
const itemCount = itemData.length;
const itemSize = smUp ? 36 : 48;
const getChildSize = (child: React.ReactChild) => {
// eslint-disable-next-line no-prototype-builtins
if (child.hasOwnProperty('group')) {
return 48;
}
return itemSize;
};
const getHeight = () => {
if (itemCount > 8) {
return 8 * itemSize;
}
return itemData.map(getChildSize).reduce((a, b) => a + b, 0);
};
const gridRef = useResetCache(itemCount);
return (
getChildSize(itemData[index])}
overscanCount={5}
itemCount={itemCount}
>
{renderRow}
);
});
const Virtualize = ({ options, onInputRef, textFieldProps, ...rest }: any) => {
return (
option?.id === value?.value
}
renderInput={(params) => (
)}
renderOption={(props, option, state) =>
[props, option, state.index] as React.ReactNode
}
// TODO: Post React 18 update - validate this conversion, look like a hidden bug
renderGroup={(params) => params as unknown as React.ReactNode}
{...rest}
/>
);
};
export default Virtualize;