Web Components Select

    The Ignite UI for Web Components Select component allows a single selection from a list of items, placed in a dropdown. This form control offers a quick items list navigation, including selection, based on a single or multiple characters match.

    Web Components Select Example

    Usage

    First, you need to install the Ignite UI for Web Components by running the following command:

    npm install igniteui-webcomponents
    

    Before using the IgcSelectComponent component, you need to register it together with its additional components:

    import {
        defineComponents,
        IgcSelectComponent
    }
    from 'igniteui-webcomponents';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    
    defineComponents(IgcSelectComponent);
    

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

    [!Note] Please note that the select header and group components are not mandatory unless you want to use them.

    To start using the component add the IgcSelectComponent along with a list of IgcSelectItemComponent's to choose from:

    <igc-select>
        <igc-select-item value="orange">Orange</igc-select-item>
        <igc-select-item value="apple">Apple</igc-select-item>
        <igc-select-item value="banana">Banana</igc-select-item>
        <igc-select-item value="mango">Mango</igc-select-item>
    </igc-select>
    

    Select

    The IgcSelectComponent component can be used inside a IgcFormComponent component, thus it exposes a Name property to be registered with. It also has a label, and placeholder properties. The outlined property is used for styling purposes only when it comes to the Material theme. Except for the default slot, the component provides a few other slots including header, footer, helper-text, prefix, suffix, and toggle-icon. The component size can be changed using the --ig-size CSS variable.

    Item

    The IgcSelectItemComponent component allows the users to declaratively specify a list of options to be used by the IgcSelectComponent control. Each item provides a value property that represents the data it carries upon selection. The IgcSelectItemComponent has a default slot which allows you to specify the text content of the item. This text content will be used as value in case the value property is not present on the IgcSelectItemComponent. You could also provide custom content to be rendered before or after the IgcSelectItemComponent content using the prefix and suffix slots. You could predefine a selected item by setting the Selected property. You could also disable some or all items via the disabled property.

    You can use the IgcSelectHeaderComponent to provide a header for a group of items.

    <igc-select>
        <igc-select-header>Tasks</igc-select-header>
    </igc-select>
    

    Group

    Multiple IgcSelectItemComponents can be placed between the opening and closing brackets of an IgcSelectGroupComponent component so that users can visually group them together. The IgcSelectGroupComponent can be labelled via its label slot and disabled via its disabled property.

    [!Note] Keep in mind that if a select group is disabled, you cannot enable separate items of it.

    <igc-select>
        <igc-select-group>
            <span slot="label">Europe</span>
    
            <igc-select-item>
              <igc-icon @ref="IconRef" slot="prefix" name="place" collection="material"></igc-icon>
              Germany
              <span slot="suffix">DE</span>
            </igc-select-item>
    
            <igc-select-item>
              <igc-icon slot="prefix" name="place" collection="material"></igc-icon>
              France
              <span slot="suffix">FR</span>
            </igc-select-item>
    
            <igc-select-item>
              <igc-icon slot="prefix" name="place" collection="material"></igc-icon>
              Spain
              <span slot="suffix">ES</span>
            </igc-select-item>
        </igc-select-group>
    </igc-select>
    

    Validation

    In addition, the IgcSelectComponent supports most of the IgcInputComponent properties, such as required, disabled, autofocus, etc. The component also exposes a method bound to its validation:

    • reportValidity - checks for validity and focuses the component if invalid.

    Keyboard Navigation

    When the select is focused and the list of options is not visible:

    • Open the select using the ALT + combination or by clicking on the Space or the Enter key.
    • Close the select using the ALT + or combination or any of the Enter, Space, Esc or IgcTabComponent keys.
    • Using the keys will select the previous item in the list.
    • Using the keys will select the next item in the list.
    • Using the Home or End keys will select the first or last item in the list.
    • Typing characters will query the list of items and select the one that most closely matches the current user input.

    When the select is focused and the list of options is visible:

    • Using the Enter or Space keys will select an item and close the list.
    • Using the keys will activate the previous item in the list.
    • Using the keys will activate the next item in the list.
    • Using the Home or End keys will activate the first or last item in the list.

    [!Note] The IgcSelectComponent component supports only single selection of items.

    Styling

    You can change the appearance of the Ignite UI for Web Components IgcSelectComponent component and its items, by using the exposed CSS parts listed below:

    CSS Parts

    Select Component

    Part name Description
    input The encapsulated igc-input.
    label The encapsulated text label.
    list A wrapper that holds the list of options.
    prefix A prefix wrapper that renders content before the input.
    suffix A suffix wrapper that renders content after the input.
    toggle-icon A toggle-icon wrapper that renders content inside the suffix wrapper.
    helper-text A helper-text wrapper that renders content below the input.

    Select Item Component

    Part name Description
    content The main wrapper that holds the text content of an item.
    prefix A prefix wrapper that renders content before the main wrapper.
    suffix A suffix wrapper that renders content after the main wrapper.

    Select Group Component

    Part name Description
    label A label wrapper that renders content above the select group items.

    API Reference

    Additional Resources