mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
fix: Button loading margin lost when children is fragment (#30962)
close #30953
This commit is contained in:
parent
b9733aa1f5
commit
7601f62ec0
@ -263,6 +263,17 @@ exports[`Button rtl render component should be rendered correctly in RTL directi
|
|||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Button should handle fragment as children 1`] = `
|
||||||
|
<button
|
||||||
|
class="ant-btn"
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
text
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Button should merge text if children using variable 1`] = `
|
exports[`Button should merge text if children using variable 1`] = `
|
||||||
<button
|
<button
|
||||||
class="ant-btn"
|
class="ant-btn"
|
||||||
|
@ -38,7 +38,7 @@ describe('Button', () => {
|
|||||||
it('warns if size is wrong', () => {
|
it('warns if size is wrong', () => {
|
||||||
const mockWarn = jest.fn();
|
const mockWarn = jest.fn();
|
||||||
jest.spyOn(console, 'warn').mockImplementation(mockWarn);
|
jest.spyOn(console, 'warn').mockImplementation(mockWarn);
|
||||||
const size = ('who am I' as any) as SizeType;
|
const size = 'who am I' as any as SizeType;
|
||||||
render(<Button.Group size={size} />);
|
render(<Button.Group size={size} />);
|
||||||
expect(mockWarn).toHaveBeenCalledTimes(1);
|
expect(mockWarn).toHaveBeenCalledTimes(1);
|
||||||
expect(mockWarn.mock.calls[0][0]).toMatchObject({
|
expect(mockWarn.mock.calls[0][0]).toMatchObject({
|
||||||
@ -311,4 +311,14 @@ describe('Button', () => {
|
|||||||
wrapper.simulate('click');
|
wrapper.simulate('click');
|
||||||
expect(onClick).not.toHaveBeenCalled();
|
expect(onClick).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/ant-design/ant-design/issues/30953
|
||||||
|
it('should handle fragment as children', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<Button>
|
||||||
|
<>text</>
|
||||||
|
</Button>,
|
||||||
|
);
|
||||||
|
expect(wrapper).toMatchRenderedSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -22,6 +22,10 @@ function isUnborderedButtonType(type: ButtonType | undefined) {
|
|||||||
return type === 'text' || type === 'link';
|
return type === 'text' || type === 'link';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isReactFragment(node: React.ReactNode) {
|
||||||
|
return React.isValidElement(node) && node.type === React.Fragment;
|
||||||
|
}
|
||||||
|
|
||||||
// Insert one space between two chinese characters automatically.
|
// Insert one space between two chinese characters automatically.
|
||||||
function insertSpace(child: React.ReactChild, needInserted: boolean) {
|
function insertSpace(child: React.ReactChild, needInserted: boolean) {
|
||||||
// Check the child if is undefined or null.
|
// Check the child if is undefined or null.
|
||||||
@ -41,9 +45,9 @@ function insertSpace(child: React.ReactChild, needInserted: boolean) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (typeof child === 'string') {
|
if (typeof child === 'string') {
|
||||||
if (isTwoCNChar(child)) {
|
return isTwoCNChar(child) ? <span>{child.split('').join(SPACE)}</span> : <span>{child}</span>;
|
||||||
child = child.split('').join(SPACE);
|
}
|
||||||
}
|
if (isReactFragment(child)) {
|
||||||
return <span>{child}</span>;
|
return <span>{child}</span>;
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
|
Loading…
Reference in New Issue
Block a user