Merge pull request #12085 from ToolJet/hotfix/radio-default-issue-develop

[hotfix]: Expose proper default value on radiobutton component
This commit is contained in:
Johnson Cherian 2025-03-03 12:08:52 +05:30 committed by GitHub
commit 938a308477
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
export const RadioButton = function RadioButton({
@ -12,8 +12,8 @@ export const RadioButton = function RadioButton({
darkMode,
dataCy,
}) {
const isInitialRender = useRef(true);
const { label, value, values, display_values } = properties;
const { visibility, disabledState, activeColor, boxShadow } = styles;
const textColor = darkMode && styles.textColor === '#000' ? '#fff' : styles.textColor;
const [checkedValue, setValue] = useState(() => value);
@ -37,12 +37,6 @@ export const RadioButton = function RadioButton({
fireEvent('onSelectionChange');
}
useEffect(() => {
if (isInitialRender.current) return;
setExposedVariable('value', value);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const exposedVariables = {
value: value,
@ -51,9 +45,8 @@ export const RadioButton = function RadioButton({
},
};
setExposedVariables(exposedVariables);
isInitialRender.current = false;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [value]);
return (
<div