forward ref to radio

This commit is contained in:
Artur Bień
2020-02-07 22:13:01 +01:00
parent f54014e7a0
commit 752e977a41
2 changed files with 15 additions and 14 deletions

View File

@@ -91,18 +91,19 @@ const Icon = styled.span.attrs(() => ({
isDisabled ? theme.checkmarkDisabled : theme.checkmark};
`;
const Radio = ({
onChange,
label,
disabled,
variant,
value,
checked,
name,
className,
style,
...otherProps
}) => {
const Radio = React.forwardRef(function Radio(props, ref) {
const {
onChange,
label,
disabled,
variant,
value,
checked,
name,
className,
style,
...otherProps
} = props;
const CheckboxComponent =
variant === 'flat' ? StyledFlatCheckbox : StyledCheckbox;
@@ -124,11 +125,12 @@ const Radio = ({
value={value}
checked={checked}
name={name}
ref={ref}
{...otherProps}
/>
</StyledLabel>
);
};
});
Radio.defaultProps = {
onChange: undefined,

View File

@@ -71,7 +71,6 @@ describe('<Radio />', () => {
expect(checkbox.checked).toBe(false);
expect(getByRole('radio')).not.toHaveAttribute('checked');
expect(getByRole('presentation').firstChild).toBeNull();
// check if proper icon was rendered
});
});
});