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

View File

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