-
-
Notifications
You must be signed in to change notification settings - Fork 202
feat: 增加extra #483
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
base: master
Are you sure you want to change the base?
feat: 增加extra #483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,7 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => { | |
| height, | ||
| classNames: modalClassNames, | ||
| styles: modalStyles, | ||
| extra, | ||
| } = props; | ||
|
|
||
| // ================================= Refs ================================= | ||
|
|
@@ -97,6 +98,15 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => { | |
| </div> | ||
| ) : null; | ||
|
|
||
| const extraNode = extra ? ( | ||
| <div | ||
| style={{ ...modalStyles?.extra }} | ||
| className={classNames(`${prefixCls}-extra`, modalClassNames?.extra)} | ||
| > | ||
| {extra} | ||
| </div> | ||
| ) : null; | ||
|
|
||
| const headerNode = title ? ( | ||
| <div | ||
| className={classNames(`${prefixCls}-header`, modalClassNames?.header)} | ||
|
|
@@ -109,8 +119,16 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => { | |
| > | ||
| {title} | ||
| </div> | ||
| {extraNode} | ||
| </div> | ||
| ) : null; | ||
| ) : ( | ||
| <div | ||
| className={classNames(`${prefixCls}-header`, modalClassNames?.header)} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里有点重复了,如果要做 header 始终保留效果,可以提一个 headerContent 变量进行填充 |
||
| style={{ ...modalStyles?.header }} | ||
| > | ||
| {extraNode} | ||
| </div> | ||
| ); | ||
|
|
||
| const closableObj = useMemo(() => { | ||
| if (typeof closable === 'object' && closable !== null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||
| /* eslint-disable react/no-render-return-value, max-classes-per-file, func-names, no-console */ | ||||||||||||||||||||
| import { fireEvent, render, act } from '@testing-library/react'; | ||||||||||||||||||||
| import { fireEvent, render, act, screen } from '@testing-library/react'; | ||||||||||||||||||||
| import { Provider } from '@rc-component/motion'; | ||||||||||||||||||||
| import KeyCode from '@rc-component/util/lib/KeyCode'; | ||||||||||||||||||||
| import React, { cloneElement, useEffect } from 'react'; | ||||||||||||||||||||
|
|
@@ -733,4 +733,40 @@ describe('dialog', () => { | |||||||||||||||||||
| expect(document.querySelector('.rc-dialog')).toBeTruthy(); | ||||||||||||||||||||
| expect(document.querySelector('.rc-dialog-close')).toBeFalsy(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('should render extra when extra is a React node', () => { | ||||||||||||||||||||
| render(<Dialog visible extra={<span data-testid="extra-node">Node</span>} />); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| expect(screen.getByTestId('extra-node')).toBeInTheDocument(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('does not render extra when extra is empty string', () => { | ||||||||||||||||||||
| render(<Dialog visible extra="" />); | ||||||||||||||||||||
| expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
Comment on lines
+743
to
+746
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修复测试选择器错误 测试逻辑正确,但选择器使用有误。 - expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull();
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull();🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| it('does not render extra when extra is string with only spaces', () => { | ||||||||||||||||||||
| render(<Dialog visible extra=" " />); | ||||||||||||||||||||
| expect(screen.queryByText(' ')).toBeNull(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
Comment on lines
+748
to
+751
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 测试逻辑需要改进 测试空格字符串的场景很有用,但当前的断言方法不够准确。应该检查 DOM 中是否存在 - expect(screen.queryByText(' ')).toBeNull();
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| it('renders extra when extra is non-empty string', () => { | ||||||||||||||||||||
| render(<Dialog visible extra="hello" />); | ||||||||||||||||||||
| expect(screen.getByText('hello')).toBeInTheDocument(); | ||||||||||||||||||||
| const extraDiv = document.querySelector('.rc-dialog-extra'); | ||||||||||||||||||||
| expect(extraDiv).toHaveTextContent('hello'); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('does not render extra when extra is null or undefined', () => { | ||||||||||||||||||||
| const { container } = render(<Dialog visible extra={null} />); | ||||||||||||||||||||
| expect(container.querySelector('.rc-dialog-extra')).toBeNull(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const { container: container2 } = render(<Dialog visible />); | ||||||||||||||||||||
| expect(container2.querySelector('.rc-dialog-extra')).toBeNull(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('renders extra when extra is a non-empty string', () => { | ||||||||||||||||||||
| render(<Dialog visible extra="Extra Text" />); | ||||||||||||||||||||
| expect(screen.getByText('Extra Text')).toBeInTheDocument(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
Comment on lines
+768
to
+771
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 删除重复的测试用例 这个测试用例与第753-758行的测试用例功能重复,都是测试非空字符串的渲染。建议删除以避免冗余。 - it('renders extra when extra is a non-empty string', () => {
- render(<Dialog visible extra="Extra Text" />);
- expect(screen.getByText('Extra Text')).toBeInTheDocument();
- });📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| }); | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用解构,直接放进去即可