chore: warning divider not support text (#37697)

This commit is contained in:
二货爱吃白萝卜 2022-09-22 16:15:00 +08:00 committed by GitHub
parent a6e620c975
commit af32d24b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 7 deletions

View File

@ -1,6 +0,0 @@
import Divider from '..';
import mountTest from '../../../tests/shared/mountTest';
describe('Divider', () => {
mountTest(Divider);
});

View File

@ -0,0 +1,17 @@
import * as React from 'react';
import { render } from '../../../tests/utils';
import Divider from '..';
import mountTest from '../../../tests/shared/mountTest';
describe('Divider', () => {
mountTest(Divider);
it('not show children when vertical', () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(<Divider type="vertical">Bamboo</Divider>);
expect(container.querySelector('.ant-divider-inner-text')).toBeFalsy();
errSpy.mockRestore();
});
});

View File

@ -1,6 +1,7 @@
import classNames from 'classnames';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import warning from '../_util/warning';
export interface DividerProps {
prefixCls?: string;
@ -53,9 +54,18 @@ const Divider: React.FC<DividerProps> = props => {
...(hasCustomMarginRight && { marginRight: orientationMargin }),
};
// Warning children not work in vertical mode
if (process.env.NODE_ENV !== 'production') {
warning(
!children || type !== 'vertical',
'Divider',
'`children` not working in `vertical` mode.',
);
}
return (
<div className={classString} {...restProps} role="separator">
{children && (
{children && type !== 'vertical' && (
<span className={`${prefixCls}-inner-text`} style={innerStyle}>
{children}
</span>