React Button Group Overview

    The React Button Group component is used to organize IgrToggleButtons into styled button groups with horizontal/vertical alignment, single/multiple selection and toggling.

    React Button Example

    Usage

    First, you need to the install the corresponding Ignite UI for React npm package by running the following command:

    npm install igniteui-react
    

    You will then need to import the IgrButtonGroup, its necessary CSS, and register its module, like so:

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

    For a complete introduction to the Ignite UI for React, read the Getting Started topic.

    Now that you have the Ignite UI for React Button Group imported, you can start with a basic configuration of the IgrButtonGroup and its buttons.

    Use the IgrButtonGroup selector to wrap your IgrToggleButtons and display them into a button group. If you want a button to be selected by default, use the selected attribute:

    <IgrButtonGroup>
        <IgrToggleButton value="left" key="button-left">
            <IgrIcon name="format_align_left" collection="material" key="icon-left" />
            <IgrRipple key="ripple-left" />
        </IgrToggleButton>
        <IgrToggleButton value="center" key="button-center">
            <IgrIcon name="format_align_center" collection="material" key="icon-center" />
            <IgrRipple key="ripple-center" />
        </IgrToggleButton>
        <IgrToggleButton value="right" key="button-right">
            <IgrIcon name="format_align_right" collection="material" key="icon-right" />
            <IgrRipple key="ripple-right" />
        </IgrToggleButton>
        <IgrToggleButton value="justify" selected={true} key="button-justify">
            <IgrIcon name="format_align_justify" collection="material" key="icon-justify" />
            <IgrRipple key="ripple-justify" />
        </IgrToggleButton>
    </IgrButtonGroup>
    

    Examples

    Alignment

    Use the alignment property to set the orientation of the buttons in the button group.

    Selection

    In order to configure the Ignite UI for React IgrButtonGroup selection, you could use its selection property. This property accepts the following three modes:

    • single - default selection mode of the button group. A single button can be selected/deselected by the user.
    • single-required - mimics a radio group behavior. Only one button can be selected and once initial selection is made, deselection is not possible through user interaction.
    • multiple - multiple buttons in the group can be selected and deselected.

    The sample below demonstrates the exposed IgrButtonGroup selection modes:

    A IgrToggleButton could be marked as selected via its selected attribute or through the IgrButtonGroup selectedItems attribute:

    <IgrButtonGroup selectedItems={['bold']}>
        <IgrToggleButton value="bold" key="button-bold">
            <IgrIcon name="bold" collection="material" key="icon-bold" />
            <IgrRipple key="ripple-bold" />
        </IgrToggleButton>
        <IgrToggleButton value="italic" key="button-italic">
            <IgrIcon name="italic" collection="material" key="icon-italic" />
            <IgrRipple key="ripple-italic" />
        </IgrToggleButton>
        <IgrToggleButton value="underlined" key="button-underlined">
            <IgrIcon name="underlined" collection="material" key="icon-underlined" />
            <IgrRipple key="ripple-underlined" />
        </IgrToggleButton>
    </IgrButtonGroup>
    

    [!Note] Setting IgrToggleButton value attribute is mandatory for using the selectedItems property of the IgrButtonGroup.

    Size

    The --ig-size CSS custom property can be used to control the size of the button group.

    Styling

    The IgrButtonGroup component exposes group CSS part that allows us to style the button group container. Also, the IgrToggleButtons provide toggle CSS part that could be used to style the button element.

    API Reference

    Additional Resources