React Radio & Radio Group
Ignite UI for React Radio 구성 요소를 사용하면 나란히 나열된 사용 가능한 옵션 집합에서 단일 옵션을 선택할 수 있습니다.
Ignite UI for React 라디오 예시
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioGroup extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "25px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="horizontal">
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="banana" checked={true}><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioGroup/>);
tsx
이 샘플이 마음에 드시나요? Ignite UI for React 전체에 액세스하고 몇 분 만에 나만의 앱을 빌드하기 시작하세요. 무료로 다운로드하세요.
용법
먼저, 다음 명령을 실행하여 Ignite UI for React 설치해야 합니다.
npm install igniteui-react
cmd
그런 다음 IgrRadio
및 IgrRadioGroup
, 필요한 CSS를 가져오고 다음과 같이 해당 모듈을 등록해야 합니다.
import { IgrRadioModule, IgrRadio, IgrRadioGroupComponent, IgrRadioGroupModule } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
tsx
<IgrRadioGroup>
<IgrRadio value="apple"><span>Apple</span></IgrRadio>
<IgrRadio value="banana"><span>Banana</span></IgrRadio>
<IgrRadio value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
tsx
IgrRadio 구성 요소는 표준 <form> 요소에서 작동하지 않습니다. 대신 Form을 사용합니다.
예
상표
IgrRadio
에 의미 있는 레이블을 제공하려면 여는 태그와 닫는 태그 사이에 텍스트를 배치하면 됩니다.
<IgrRadio><span>Label</span></IgrRadio>
tsx
라벨을 위치 앞 또는 뒤에 배치해야 하는지 지정할 수 있습니다. IgrRadio
버튼을 설정하여 label-position
기인하다. 허용되는 값은 다음과 같습니다. before
그리고 after
(기본):
<IgrRadio labelPosition="before"><span>Apple</span></IgrRadio>
tsx
IgrRadio
는 외부 요소로 레이블을 지정할 수도 있습니다. 이 경우 사용자는 필요에 따라 라벨의 위치와 스타일을 지정할 수 있는 모든 권한을 갖게 됩니다.
<span id="radio-label">Label</span>
<IgrRadio ariaLabelledby="radio-label"></IgrRadio>
tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioLabel extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height:"60px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="vertical">
<IgrRadio name="fruit" value="apple" labelPosition="before"><span>Apple</span></IgrRadio>
<div style={{display: "flex", alignItems: "center"}}>
<span id="radio-label">Label</span>
<IgrRadio
name="fruit"
labelPosition="before"
ariaLabelledby="radio-label"
value="orange">
</IgrRadio>
</div>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioLabel/>);
tsx
체크됨
checked
속성을 사용하여 라디오를 켤 수 있습니다.
<IgrRadioGroup>
<IgrRadio value="apple"><span>Apple</span></IgrRadio>
<IgrRadio value="banana" checked="true"><span>Banana</span></IgrRadio>
<IgrRadio value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioGroup extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "25px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="horizontal">
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="banana" checked={true}><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioGroup/>);
tsx
유효하지 않은
invalid
속성을 사용하여 라디오를 잘못된 것으로 표시할 수 있습니다.
<IgrRadio invalid="true"></IgrRadio>
tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
export default class RadioInvalid extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "25px", border: "1px solid gainsboro"}}>
<IgrRadio value="banana" invalid={true}><span>Invalid</span></IgrRadio>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioInvalid/>);
tsx
장애가 있는
disabled
속성을 사용하여 라디오를 비활성화할 수 있습니다.
<IgrRadioGroup>
<IgrRadio value="apple"><span>Apple</span></IgrRadio>
<IgrRadio value="banana" disabled="true"><span>Banana</span></IgrRadio>
<IgrRadio value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioDisabled extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "25px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="horizontal">
<IgrRadio name="fruit" value="banana" disabled={true}><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioDisabled/>);
tsx
그룹 정렬
IgrRadioGroup
사용하면 alignment
속성을 사용하여 포함된 라디오 버튼의 배치 방향을 쉽게 변경할 수 있습니다. 허용되는 값은 vertical
(기본값) 및 horizontal
입니다.
<IgrRadioGroup alignment="horizontal">
<IgrRadio value="apple"><span>Apple</span></IgrRadio>
<IgrRadio value="banana" disabled="true"><span>Banana</span></IgrRadio>
<IgrRadio value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioAlignment extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "25px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="horizontal">
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="banana" checked={true}><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioAlignment/>);
tsx
라디오를 name
사용할 때 and value
속성을 사용할 수 있습니다 Form
.
<IgrRadioGroup>
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="banana"><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
tsx
스타일링
구성 요소는 IgrRadio
여러 CSS 부분(base
, control
, and label
)을 노출하여 스타일을 완전히 제어할 수 있도록 합니다.
igc-radio::part(control) {
--size: 18px;
}
igc-radio-group {
padding: 12px;
}
igc-radio::part(checked)::after {
background-color: var(--ig-success-500);
}
igc-radio::part(label) {
color: var(--ig-secondary-800);
}
css
import React from 'react';
import ReactDOM from 'react-dom/client';
import { IgrRadio, IgrRadioGroup, IgrRadioModule, IgrRadioGroupModule } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
import './index.css';
IgrRadioModule.register();
IgrRadioGroupModule.register();
export default class RadioStyling extends React.Component<any, any> {
constructor(props: any) {
super(props);
}
public render(): JSX.Element {
return (
<div className="container sample">
<div className="container" style={{width: "430px", height: "120px", border: "1px solid gainsboro"}}>
<IgrRadioGroup alignment="vertical">
<IgrRadio name="fruit" value="apple"><span>Apple</span></IgrRadio>
<IgrRadio name="fruit" value="banana" checked={true}><span>Banana</span></IgrRadio>
<IgrRadio name="fruit" value="Mango"><span>Mango</span></IgrRadio>
<IgrRadio name="fruit" value="orange"><span>Orange</span></IgrRadio>
</IgrRadioGroup>
</div>
</div>
);
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<RadioStyling/>);
tsx
:root {
--igc-primary-h: 60deg;
--igc-primary-s: 100%;
--igc-primary-l: 25%;
}
igc-radio::part(control) {
--size: 18px;
}
css
API 참조
추가 리소스