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

Bug: Defaulted props not used in onChange callback #230

Closed
chilled-capybara opened this issue May 2, 2023 · 2 comments
Closed

Bug: Defaulted props not used in onChange callback #230

chilled-capybara opened this issue May 2, 2023 · 2 comments

Comments

@chilled-capybara
Copy link

Issue

The props that have default values, are not used in the event.target from onChange

v2.3.2 functionality

In v2.3.2 the props were defaulted via defaultProps;

checkbox/src/index.jsx

Lines 6 to 18 in 22992a5

static defaultProps = {
prefixCls: 'rc-checkbox',
className: '',
style: {},
type: 'checkbox',
defaultChecked: false,
onFocus() {},
onBlur() {},
onChange() {},
onKeyDown() {},
onKeyPress() {},
onKeyUp() {},
};

Which meant that in the onChange target would use these defaulted props;

checkbox/src/index.jsx

Lines 59 to 63 in 22992a5

onChange({
target: {
...this.props,
checked: e.target.checked,
},

v3.0.0 functionality

However in v3.0.0, the props are only defaulted in the destructuring;

checkbox/src/index.tsx

Lines 30 to 40 in cfdcf03

const {
prefixCls = 'rc-checkbox',
className,
style,
checked,
disabled,
defaultChecked = false,
type = 'checkbox',
onChange,
...inputProps
} = props;

Which means the defaulted values are not used for target;

checkbox/src/index.tsx

Lines 71 to 75 in cfdcf03

onChange?.({
target: {
...props,
checked: e.target.checked,
},

Summary

in v2.3.2; <Checkbox onChange={(e) => console.log(e.target.type)} {...otherProps} />; will log "checkbox"
in v3.0.0; <Checkbox onChange={(e) => console.log(e.target.type)} {...otherProps} />; will log undefined

@afc163
Copy link
Member

afc163 commented May 5, 2023

PR is welcome~

@JunIce
Copy link

JunIce commented Jun 13, 2023

closed 8a16023

@afc163 afc163 closed this as completed Jun 13, 2023
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

No branches or pull requests

3 participants