import { store } from "@/store"; import { useSnapshot } from "valtio"; import s from…
- User
import { store } from "@/store"; import { useSnapshot } from "valtio"; import s from "./config.module.scss";
type Props = { title: string; elem: { value?: string | number | undefined; title: string; titleSK?: string | undefined; options: { color?: string; value?: string | number | undefined; title: string; }[]; }; };
const OnOffSelect: React.FC = ({ title, elem }) => { const globalState = useSnapshot(store);
return ( <input type="radio" id={
react-select-${ elem.title.toLowerCase() + "-" + title.replace(/\s/g, "-") }} name={${title}-select.replace(/\s/g, "-")} value={elem.value} checked={elem.value === (globalState as any)[title]} onChange={() => { (store as any)[title] = elem.value; (store as any)[${title} SK] = elem.titleSK; }} /> <label style={globalState.code === "SK" ? { textTransform: "none" } : {}} htmlFor={react-select-${ elem.title.toLowerCase() + "-" + title.replace(/\s/g, "-") }} > {elem.titleSK ? globalState.code === "GB" ? elem.title : elem.titleSK : elem.title} {elem.title !== "Without floor" ? ( title === "floors" ? ( <span style={{ backgroundImage:url(/floor-icons/${elem.value}.jpg), }} className={s.previewFoil} /> ) : ( <></> ) ) : ( <></> )} {title === "anti slip pads" && ( <> {elem.value !== undefined && ( <span style={{ backgroundImage:url(/slippad-icons/${elem.value}.jpg), }} className={s.previewFoil} /> )} </> )} ); };export default OnOffSelect;
"input type radio checked not working"
- Assistant
When dealing with an issue where a radio button does not appear checked in a React component, several possible culprits can be investigated. Here's a checklist and some suggestions to help you diagnose and fix the problem:
- User
Global State:{ "code": "GB", "length": 8, "width": 3, "depth": 1.5, "mode": "day", "isWater": true, "dirt collector": "wider", "waterColor": "#91b7db", "floors": 5, "foilType": "jednofarebne elbe supra", "alkorplan touch": 0, "mosaic elbe": 0, "drevodekor larch range": 0, "monochrome elbe supra": 0, "novinkove elbe": 0, "pearl elbe": 0, "stonelite": 0, "quote": { "entry": "", "floor": "", "foil": "", "lighting": "", "collector": "", "pads": "", "upstream": "", "shower": "", "cover": "", "water": "", "techhouse": "", "heatpump": "", "floorextension": "" }, "anti slip pads SK": "", "dirt collector SK": "Užší", "shower SK": "Piesková so strieborným pruhom", "heat pump": "silver", "floor extension": "disable", "extendValue": 0, "extendDirection": "left", "water treatment": "Without", "water treatment SK": "Bez", "isRollerCoverOpen": false, "extendLeftRow": 0, "extendRightRow": 0, "extendFrontRow": 0, "heat pump SK": "SILENCE" } Elem Value: black Checked Condition: false
"onchange console.log click on heat pump"
- Assistant
Based on the log outputs and your description of the issue, it looks like the
checkedcondition is not evaluating totrue, meaning the is not equal to the value stored in under the key derived from . Here's a step-by-step guide to debugging and resolving the problem: