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

Fixes #3220 #3226

Merged
merged 2 commits into from
Sep 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/lib/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const Checkbox = React.memo(
const onClick = (event) => {
if (!props.disabled && !props.readOnly && props.onChange) {
const checked = isChecked();

if (inputRef.current.checked === checked) {
const checkboxClicked = event.target instanceof HTMLDivElement || event.target instanceof HTMLSpanElement;
const isInputToggled = event.target === inputRef.current;
const isCheckboxToggled = checkboxClicked && event.target.checked !== checked;
if (isInputToggled || isCheckboxToggled) {
const value = checked ? props.falseValue : props.trueValue;
props.onChange({
originalEvent: event,
Expand All @@ -29,7 +31,6 @@ export const Checkbox = React.memo(
checked: value
}
});
inputRef.current.checked = !checked;
}

DomHandler.focus(inputRef.current);
Expand Down
8 changes: 5 additions & 3 deletions components/lib/radiobutton/RadioButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ export const RadioButton = React.memo(
const inputRef = React.useRef(props.inputRef);

const select = (e) => {
inputRef.current.checked = true;
onClick(e);
};

const onClick = (e) => {
if (!props.disabled && props.onChange) {
const checked = props.checked;
if (inputRef.current.checked === checked) {
const radioClicked = e.target instanceof HTMLDivElement;
const inputClicked = e.target === inputRef.current;
const isInputToggled = inputClicked && e.target.checked !== checked;
const isRadioToggled = radioClicked && !e.target.checked;
if (isInputToggled || isRadioToggled) {
const value = !checked;
props.onChange({
originalEvent: e,
Expand All @@ -32,7 +35,6 @@ export const RadioButton = React.memo(
checked: value
}
});
inputRef.current.checked = value;
}

DomHandler.focus(inputRef.current);
Expand Down