Descripción general de la casilla de verificación React

    React Checkbox es un componente que te permite agregar casillas de verificación a tus aplicaciones React. Se comporta como una casilla de verificación HTML estándar, lo que permite a los usuarios seleccionar estados básicos marcados y no marcados o un estado indeterminado adicional. También obtienes control total sobre el estilo del componente de casilla de verificación React y la capacidad de usarlo con formularios.

    Checkbox Example

    Usage

    At its core, the IgrCheckbox allows for a choice between selected/unselected state. The default styling is done according to the selection controls specification in the Material Design guidelines.

    Primero, debes instalar el paquete npm Ignite UI for React correspondiente ejecutando el siguiente comando:

    npm install igniteui-react
    

    You will then need to import the IgrCheckbox and its necessary CSS, like so:

    import { IgrCheckbox } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    

    The simplest way to start using the IgrCheckbox is as follows:

    <IgrCheckbox></IgrCheckbox>
    

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

    Examples

    Label

    Para proporcionar una etiqueta significativa para la casilla de verificación, simplemente coloque algo de texto entre las etiquetas de apertura y cierre:

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

    You can specify if the label should be positioned before or after the checkbox toggle by setting the label-position attribute of the checkbox. Allowed values are before and after (default):

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

    La casilla de verificación también puede estar etiquetada por elementos externos a la casilla de verificación. En este caso, el usuario tiene control total para colocar y diseñar la etiqueta de acuerdo con sus necesidades.

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

    Checked

    You can use the checked attribute of the component to determine whether the checkbox should be toggled on or off by default.

    <IgrCheckbox checked={true}></IgrCheckbox>
    

    Indeterminate

    You can use the indeterminate property of the component to set the checkbox's value to neither true nor false.

    <IgrCheckbox indeterminate={true}></IgrCheckbox>
    

    Required

    You can use the required property to mark the checkbox as required.

    <IgrCheckbox required={true}></IgrCheckbox>
    

    Invalid

    You can use the invalid attribute to mark the checkbox as invalid.

    <IgrCheckbox invalid={true}></IgrCheckbox>
    

    Disabled

    You can use the disabled attribute to disable the checkbox.

    <IgrCheckbox disabled={true}></IgrCheckbox>
    

    Forms

    You can use the name and value attributes when using the checkbox with Form.

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

    Styling

    The IgrCheckbox component exposes four CSS parts which we can use for styling:

    Nombre Descripción
    base El envoltorio base de la casilla de verificación.
    control El elemento de entrada de la casilla de verificación.
    indicator El icono del indicador de casilla de verificación.
    label La etiqueta de la casilla de verificación.

    Con estas cuatro partes de CSS, tenemos control total sobre el estilo de las casillas de verificación.

    igc-checkbox::part(indicator) {
      stroke: var(--ig-secondary-500-contrast);
    }
    
    igc-checkbox::part(control checked)::after {
      border-radius: 4px;
      background: var(--ig-secondary-500);
    }
    

    API References

    Additional Resources