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

Change the priorities of defaultChecked and checked #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

huangminjianxx
Copy link

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

#35130

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English Modify defaultChecked's priority in Constructor and getDerivedStateFromProps,when defaultChecked has a value,default selected
🇨🇳 Chinese 在constructor和getDerivedStateFromProps中修改defaultChecked的优先级,当defaultChecked有值时,初始默认选中

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • 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

src/index.jsx Outdated
@@ -21,7 +21,7 @@ class Checkbox extends Component {
constructor(props) {
super(props);

const checked = 'checked' in props ? props.checked : props.defaultChecked;
const checked = 'defaultChecked' in props ? props.defaultChecked : 'checked' in props ? props.checked : false;
Copy link
Member

Choose a reason for hiding this comment

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

Can the double ternary operator be avoided?

Copy link
Member

Choose a reason for hiding this comment

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

It is wrong to read defaultChecked before checked, checked should be top priority.

Copy link
Author

Choose a reason for hiding this comment

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

I need to look at the code again🧎‍♂️。I will reopen this pr after I fix it。

@yoyo837
Copy link
Member

yoyo837 commented Apr 21, 2022

Test case needed.

@huangminjianxx
Copy link
Author

Test case needed.

👌

@yoyo837
Copy link
Member

yoyo837 commented Apr 21, 2022

There is no need to create another PR, just continue to push your changes.

@huangminjianxx
Copy link
Author

when the checked value is undefined or null, input will ignore this property,I changed the code follow this principle.

There's another question, ‘// eslint-disable-next-line import/no-extraneous-dependencies’ ,when this code exist,it will commit failed,the termminal reported an error: 'Definition for rule 'import/no-extraneous-dependencies' was not found ',what should I do?🧎‍♂️

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