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: Form throw error when using BraftEditor #21425

Merged
merged 1 commit into from Feb 18, 2020
Merged

fix: Form throw error when using BraftEditor #21425

merged 1 commit into from Feb 18, 2020

Conversation

afc163
Copy link
Member

@afc163 afc163 commented Feb 18, 2020

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

close #21415

💡 Background and solution

component.props.onChange should not run when it is falsy.

📝 Changelog

Language Changelog
🇺🇸 English Fix Form throw error when using BraftEditor.
🇨🇳 Chinese 修复 Form 和 BraftEditor 一起使用时抛错的问题。

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

@tests-checker tests-checker bot left a comment

Could you please add tests to make sure this change works as expected?

@afc163 afc163 requested a review from zombieJ Feb 18, 2020
mergedControl[eventName](...args);
children.props[eventName](...args);
mergedControl[eventName]?.(...args);
children.props[eventName]?.(...args);
Copy link
Member Author

@afc163 afc163 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BraftEditor.props.onChange 是 null。

Copy link
Member

@zombieJ zombieJ Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下来是直接把 eventName in children.props 改成 children.props[eventName] 即可,这里用于把参数传递给原始的 eventHandler,没有就不用进 if 了。

Copy link
Member Author

@afc163 afc163 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mergedControl 要改么

Copy link
Member Author

@afc163 afc163 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会不会导致 BraftEditor 的 onChange 直接不触发了?

Copy link
Member

@zombieJ zombieJ Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用。上面 mergeControl 已经处理过了。这里只是再额外把相关事件填充一下。

Copy link
Member Author

@afc163 afc163 Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

          triggers.forEach(eventName => {
            childProps[eventName] = (...args: any[]) => {
              mergedControl[eventName]?.(...args);
              children.props[eventName]?.(...args);
            };
          });

是不是这样就行了,判断也不需要了。

Copy link
Member

@zombieJ zombieJ Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

运行时稍微多耗点性能,感觉这样简单一些。可以的。

@ant-design-bot
Copy link
Contributor

@ant-design-bot ant-design-bot commented Feb 18, 2020

@codesandbox-ci
Copy link

@codesandbox-ci codesandbox-ci bot commented Feb 18, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codecov
Copy link

@codecov codecov bot commented Feb 18, 2020

Codecov Report

Merging #21425 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21425      +/-   ##
==========================================
- Coverage   97.83%   97.83%   -0.01%     
==========================================
  Files         302      302              
  Lines        7017     7016       -1     
  Branches     1888     1887       -1     
==========================================
- Hits         6865     6864       -1     
  Misses        152      152
Impacted Files Coverage Δ
components/form/FormItem.tsx 99% <100%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e275895...7ca3b25. Read the comment docs.

component.props.onChange should not run when it is falsy

close #21415
@afc163 afc163 merged commit 4f2ef2a into master Feb 18, 2020
23 of 25 checks passed
@afc163 afc163 deleted the fix-form-onChange branch Feb 18, 2020
@pr-triage pr-triage bot added the PR: merged label Feb 18, 2020
@ycjcl868 ycjcl868 mentioned this pull request Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants