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();
|
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', () => {
|
describe('value is null or undefined', () => {
|
||||||
it('use `defaultValue` when `value` is undefined', () => {
|
it('use `defaultValue` when `value` is undefined', () => {
|
||||||
const options = [{ label: 'Bamboo', value: 'bamboo' }];
|
const options = [{ label: 'Bamboo', value: 'bamboo' }];
|
||||||
|
@ -7,7 +7,7 @@ import { ConfigContext } from '../config-provider';
|
|||||||
import SizeContext from '../config-provider/SizeContext';
|
import SizeContext from '../config-provider/SizeContext';
|
||||||
import { RadioGroupContextProvider } from './context';
|
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 { getPrefixCls, direction } = React.useContext(ConfigContext);
|
||||||
const size = React.useContext(SizeContext);
|
const size = React.useContext(SizeContext);
|
||||||
|
|
||||||
@ -96,6 +96,7 @@ const RadioGroup: React.FC<RadioGroupProps> = props => {
|
|||||||
onMouseEnter={onMouseEnter}
|
onMouseEnter={onMouseEnter}
|
||||||
onMouseLeave={onMouseLeave}
|
onMouseLeave={onMouseLeave}
|
||||||
id={id}
|
id={id}
|
||||||
|
ref={ref}
|
||||||
>
|
>
|
||||||
{childrenToRender}
|
{childrenToRender}
|
||||||
</div>
|
</div>
|
||||||
@ -114,7 +115,7 @@ const RadioGroup: React.FC<RadioGroupProps> = props => {
|
|||||||
{renderGroup()}
|
{renderGroup()}
|
||||||
</RadioGroupContextProvider>
|
</RadioGroupContextProvider>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
RadioGroup.defaultProps = {
|
RadioGroup.defaultProps = {
|
||||||
buttonStyle: 'outline' as RadioGroupButtonStyle,
|
buttonStyle: 'outline' as RadioGroupButtonStyle,
|
||||||
|
Loading…
Reference in New Issue
Block a user