🐛 fix: forward ref the component to fix console error

This commit is contained in:
Wahyu Kurniawan 2024-02-24 13:48:20 +07:00
parent d181e6ba98
commit 410def0750
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33
2 changed files with 81 additions and 69 deletions

View File

@ -1,4 +1,4 @@
import React, { ComponentPropsWithoutRef, useMemo } from 'react'; import React, { forwardRef, ComponentPropsWithoutRef, useMemo } from 'react';
import { Overwrite, UseComboboxGetItemPropsReturnValue } from 'downshift'; import { Overwrite, UseComboboxGetItemPropsReturnValue } from 'downshift';
import { SelectOption, SelectOrientation } from 'components/shared/Select'; import { SelectOption, SelectOrientation } from 'components/shared/Select';
import { selectItemTheme, SelectItemTheme } from './SelectItem.theme'; import { selectItemTheme, SelectItemTheme } from './SelectItem.theme';
@ -29,7 +29,9 @@ export interface SelectItemProps
empty?: boolean; empty?: boolean;
} }
export const SelectItem = ({ const SelectItem = forwardRef<HTMLLIElement, SelectItemProps>(
(
{
className, className,
selected, selected,
option, option,
@ -38,7 +40,9 @@ export const SelectItem = ({
empty, empty,
variant, variant,
...props ...props
}: SelectItemProps) => { },
ref,
) => {
const theme = selectItemTheme({ active: hovered, orientation, variant }); const theme = selectItemTheme({ active: hovered, orientation, variant });
const { label, description, leftIcon, rightIcon, disabled } = option; const { label, description, leftIcon, rightIcon, disabled } = option;
@ -48,7 +52,9 @@ export const SelectItem = ({
return cloneIcon(rightIcon, { className: theme.icon() }); return cloneIcon(rightIcon, { className: theme.icon() });
} else if (selected) { } else if (selected) {
return ( return (
<CheckRadioIcon className={cn(theme.icon(), 'text-controls-primary')} /> <CheckRadioIcon
className={cn(theme.icon(), 'text-controls-primary')}
/>
); );
} }
return null; return null;
@ -65,6 +71,7 @@ export const SelectItem = ({
return ( return (
<li <li
{...props} {...props}
ref={ref}
className={theme.wrapper({ className })} className={theme.wrapper({ className })}
data-disabled={disabled} data-disabled={disabled}
> >
@ -83,4 +90,9 @@ export const SelectItem = ({
{renderRightIcon} {renderRightIcon}
</li> </li>
); );
}; },
);
SelectItem.displayName = 'SelectItem';
export { SelectItem };

View File

@ -1,4 +1,4 @@
import React, { ComponentPropsWithoutRef } from 'react'; import React, { forwardRef, ComponentPropsWithoutRef } from 'react';
import { import {
Overwrite, Overwrite,
UseMultipleSelectionGetSelectedItemReturnValue, UseMultipleSelectionGetSelectedItemReturnValue,
@ -35,17 +35,12 @@ export interface SelectValueProps
/** /**
* The SelectValue component is used to display the selected value of a select component * The SelectValue component is used to display the selected value of a select component
*/ */
export const SelectValue = ({ const SelectValue = forwardRef<HTMLSpanElement, SelectValueProps>(
className, ({ className, size, option, onDelete, ...props }, ref) => {
size,
option,
onDelete,
...props
}: SelectValueProps) => {
const theme = selectValueTheme(); const theme = selectValueTheme();
return ( return (
<span {...props} className={theme.wrapper({ className, size })}> <span {...props} ref={ref} className={theme.wrapper({ className, size })}>
{option.label} {option.label}
<Button <Button
onClick={() => onDelete?.(option)} onClick={() => onDelete?.(option)}
@ -57,4 +52,9 @@ export const SelectValue = ({
</Button> </Button>
</span> </span>
); );
}; },
);
SelectValue.displayName = 'SelectValue';
export { SelectValue };