mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
fix: Radio.Group forward child element ref (#26555)
Co-authored-by: William Cai <williamcai@easyops.cn>
This commit is contained in:
parent
25f2bd66c8
commit
b0c70ab348
@ -153,6 +153,19 @@ describe('Radio Group', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should forward ref', () => {
|
||||
let radioGroupRef;
|
||||
const wrapper = mount(
|
||||
createRadioGroupByOption({
|
||||
ref: ref => {
|
||||
radioGroupRef = ref;
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(radioGroupRef).toBe(wrapper.children().getDOMNode());
|
||||
});
|
||||
|
||||
describe('value is null or undefined', () => {
|
||||
it('use `defaultValue` when `value` is undefined', () => {
|
||||
const options = [{ label: 'Bamboo', value: 'bamboo' }];
|
||||
|
@ -7,7 +7,7 @@ import { ConfigContext } from '../config-provider';
|
||||
import SizeContext from '../config-provider/SizeContext';
|
||||
import { RadioGroupContextProvider } from './context';
|
||||
|
||||
const RadioGroup: React.FC<RadioGroupProps> = props => {
|
||||
const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>((props, ref) => {
|
||||
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
||||
const size = React.useContext(SizeContext);
|
||||
|
||||
@ -96,6 +96,7 @@ const RadioGroup: React.FC<RadioGroupProps> = props => {
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
id={id}
|
||||
ref={ref}
|
||||
>
|
||||
{childrenToRender}
|
||||
</div>
|
||||
@ -114,7 +115,7 @@ const RadioGroup: React.FC<RadioGroupProps> = props => {
|
||||
{renderGroup()}
|
||||
</RadioGroupContextProvider>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
RadioGroup.defaultProps = {
|
||||
buttonStyle: 'outline' as RadioGroupButtonStyle,
|
||||
|
Loading…
Reference in New Issue
Block a user