Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(grid): fix justify and align properties are not reactive for Row #39704

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions components/grid/__tests__/index.test.tsx
@@ -1,9 +1,10 @@
import React from 'react';
import React, { useState } from 'react';
import { act } from 'react-dom/test-utils';
import { Col, Row } from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import useBreakpoint from '../hooks/useBreakpoint';
import { render } from '../../../tests/utils';
import { render, fireEvent } from '../../../tests/utils';

// Mock for `responsiveObserve` to test `unsubscribe` call
jest.mock('../../_util/responsiveObserve', () => {
Expand Down Expand Up @@ -209,4 +210,26 @@ describe('Grid', () => {
const { container: container3 } = render(<Row justify={{ lg: 'center' }} />);
expect(container3.innerHTML).not.toContain('ant-row-center');
});

// https://github.com/ant-design/ant-design/issues/39690
it('Justify and align properties should reactive for Row', () => {
const ReactiveTest = () => {
const [justify, setjustify] = useState<any>('start');
return (
<>
<Row justify={justify} align="bottom">
<div>button1</div>
<div>button</div>
</Row>
<span onClick={() => setjustify('end')} />
</>
);
};
const { container } = render(<ReactiveTest />);
expect(container.innerHTML).toContain('ant-row-start');
act(() => {
fireEvent.click(container.querySelector('span')!);
});
expect(container.innerHTML).toContain('ant-row-end');
});
});
3 changes: 3 additions & 0 deletions components/grid/row.tsx
Expand Up @@ -39,6 +39,9 @@ function useMergePropByScreen(oriProp: RowProps['align'] | RowProps['justify'],
const [prop, setProp] = React.useState(typeof oriProp === 'string' ? oriProp : '');

const clacMergeAlignOrJustify = () => {
if (typeof oriProp === 'string') {
setProp(oriProp);
}
if (typeof oriProp !== 'object') {
return;
}
Expand Down