简体   繁体   中英

how to disable radio button in react

if I give only disable property its not working how to make radio button disable

import React from "react";
const App = () => {
      let platformData = ["And", "win", "ios"];
      let platform = "platform";
    
      return (
        <div>
          <input
            type="radio"
            disabled
            name="Platform"
            id="Platform"
            radioList={platformData}
            radioName={platform}
          />
        </div>
      );
    };
    
    export default App;

Simple solution to this problem you need to pass in disabled={true} or you could do something like this

import React from "react";

const App = () => {
  let platformData = ["And", "win", "ios"];
  let platform = "platform";
  let disabled = true;

  if (platform) // or any other kind of condition
      disabled = false;

  return (
    <div>
      <input
        type="radio"
        disabled={disabled}
        name="Platform"
        id="Platform"
        radioList={platformData}
        radioName={platform}
      />
    </div>
  );
};

export default App;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM