React 체크박스 개요

    React Checkbox는 React 앱에 체크박스를 추가할 수 있는 구성 요소입니다. 이는 표준 HTML 확인란처럼 작동하여 사용자가 기본 선택 및 선택 취소 상태 또는 추가 불확정 상태를 선택할 수 있도록 합니다. 또한 React 체크박스 구성 요소의 스타일과 이를 양식과 함께 사용하는 기능을 완벽하게 제어할 수 있습니다.

    Checkbox Example

    Usage

    기본적으로 IgrCheckbox 선택됨/선택 취소됨 상태 중에서 선택할 수 있습니다. 기본 스타일은 머티리얼 디자인 지침의 선택 제어 사양에 따라 수행됩니다.

    먼저 다음 명령을 실행하여 Ignite UI for React 설치해야 합니다.

    npm install igniteui-react
    

    그런 다음 필요한 CSS인 IgrCheckbox 가져와서 다음과 같이 모듈을 등록해야 합니다.

    import { IgrCheckboxModule, IgrCheckbox } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    IgrCheckboxModule.register();
    

    IgrCheckbox 사용을 시작하는 가장 간단한 방법은 다음과 같습니다.

    <IgrCheckbox></IgrCheckbox>
    

    [!WARNING] The IgrCheckbox component doesn't work with the standard <form> element. Use IgrForm instead.

    Examples

    Label

    확인란에 의미 있는 레이블을 제공하려면 여는 태그와 닫는 태그 사이에 텍스트를 배치하면 됩니다.

    <IgrCheckbox><span>Label</span></IgrCheckbox>
    

    확인란의 label-position 속성을 설정하여 레이블을 확인란 토글 앞 또는 뒤에 배치해야 하는지 지정할 수 있습니다. 허용되는 값은 beforeafter 입니다(기본값):

    <IgrCheckbox labelPosition="before"></IgrCheckbox>
    

    확인란은 확인란 외부의 요소로 레이블을 지정할 수도 있습니다. 이 경우 사용자는 필요에 따라 라벨의 위치와 스타일을 지정할 수 있는 모든 권한을 갖게 됩니다.

    <span id="checkbox-label">Label</span>
    <IgrCheckbox ariaLabelledby="checkbox-label" labelPosition="before"></IgrCheckbox>
    

    Checked

    구성 요소의 checked 속성을 사용하여 확인란을 기본적으로 켜거나 끌지 여부를 결정할 수 있습니다.

    <IgrCheckbox checked="true"></IgrCheckbox>
    

    Indeterminate

    구성 요소의 indeterminate 속성을 사용하여 확인란의 값을 true 또는 false로 설정할 수 없습니다.

    <IgrCheckbox indeterminate="true"></IgrCheckbox>
    

    Required

    required 속성을 사용하여 확인란을 필수로 표시할 수 있습니다.

    <IgrCheckbox required="true"></IgrCheckbox>
    

    Invalid

    invalid 속성을 사용하여 확인란을 잘못된 것으로 표시할 수 있습니다.

    <IgrCheckbox invalid="true"></IgrCheckbox>
    

    Disabled

    disabled 속성을 사용하여 확인란을 비활성화할 수 있습니다.

    <IgrCheckbox disabled="true"></IgrCheckbox>
    

    Forms

    당신은 사용할 수 있습니다 name 그리고 value 체크박스를 사용할 때 속성 IgrForm.

    <IgrCheckbox name="wifi" value="enabled"></IgrCheckbox>
    

    Styling

    체크박스 구성 요소는 여러 CSS 부분(base, control, indicatorlabel)을 노출하여 스타일을 완벽하게 제어할 수 있습니다.

    igc-checkbox::part(indicator) {
      &::after {
        padding: 12px;
        border-radius: 14px;
      }
    }
    
    igc-checkbox::part(indicator checked) {
      border-radius: 0;
    
      &::after {
        background: olive;
        border-color: olive;
        stroke: beige;
      }
    }
    

    API References

    Additional Resources