Skip to main content
Version: v6

ion-select-option

shadow

Contents

Select Options are components that are child elements of a Select. Each option defined is passed and displayed in the Select dialog. For more information, see the Select docs.

Customization

Each ion-select-option component that is added as a child of an ion-select is passed to the interface to display it in the dialog. It's important to note that the ion-select-option element itself is hidden from the view. This means that attempting to style it will not have any effect on the option in the dialog:

/* DOES NOT work */
ion-select-option {
color: red;
}

Instead, each interface option has the class .select-interface-option which can be styled. Keep in mind that due to the overlays being scoped components the selector by itself will not work and a custom cssClass is recommended to be passed to the interface.

/* This will NOT work on its own */
.select-interface-option {
color: red;
}

/*
* "my-custom-interface" needs to be passed in through
* the cssClass of the interface options for this to work
*/
.my-custom-interface .select-interface-option {
color: red;
}
note

Note: Some interfaces require more in depth styling due to how the options are rendered. See usage for expanded information on this.

The options can be styled individually by adding your own class on the ion-select-option which gets passed to the interface option. See the Usage section below for examples of styling and setting individual classes on options.

Usage

<ion-item>
<ion-label>Select</ion-label>
<ion-select>
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>

Customizing Options

<ion-item>
<ion-label>Select: Alert Interface</ion-label>
<ion-select class="custom-options">
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>

<ion-item>
<ion-label>Select: Alert Interface (Multiple Selection)</ion-label>
<ion-select class="custom-options" multiple="true">
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>

<ion-item>
<ion-label>Select: Popover Interface</ion-label>
<ion-select interface="popover" class="custom-options">
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>

<ion-item>
<ion-label>Select: Action Sheet Interface</ion-label>
<ion-select interface="action-sheet" class="custom-options">
<ion-select-option value="brown">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>
/* Popover Interface: set color for the popover using Item's CSS variables */
.my-custom-interface .select-interface-option {
--color: #971e49;
--color-hover: #79193b;
}

/* Action Sheet Interface: set color for the action sheet using its button CSS variables */
.my-custom-interface .select-interface-option {
--button-color: #971e49;
--button-color-hover: #79193b;
}

/* Alert Interface: set color for alert options (single selection) */
.my-custom-interface .select-interface-option .alert-radio-label {
color: #971e49;
}

/* Alert Interface: set color for alert options (multiple selection) */
.my-custom-interface .select-interface-option .alert-checkbox-label {
color: #971e49;
}

/* Alert Interface: set color for checked alert options (single selection) */
.my-custom-interface .select-interface-option[aria-checked=true] .alert-radio-label {
color: #79193b;
}

/* Alert Interface: set color for checked alert options (multiple selection) */
.my-custom-interface .select-interface-option[aria-checked=true] .alert-checkbox-label {
color: #79193b;
}
// Pass a custom class to each select interface for styling
const selects = document.querySelectorAll('.custom-options');

for (var i = 0; i < selects.length; i++) {
selects[i].interfaceOptions = {
cssClass: 'my-custom-interface'
};
};

Note: In the CSS examples, some of the selectors could be combined together, but are separated out in order to better explain what each selector is for.

Customizing Individual Options

To customize an individual option, set a class on the ion-select-option:

<ion-item>
<ion-label>Select</ion-label>
<ion-select class="custom-options" interface="popover">
<ion-select-option value="brown" class="brown-option">Brown</ion-select-option>
<ion-select-option value="blonde">Blonde</ion-select-option>
<ion-select-option value="black">Black</ion-select-option>
<ion-select-option value="red">Red</ion-select-option>
</ion-select>
</ion-item>
/* Popover Interface: set color for the popover using Item's CSS variables */
.my-custom-interface .brown-option {
--color: #5e3e2c;
--color-hover: #362419;
}
// Pass a custom class to each select interface for styling
const select = document.querySelector('.custom-options');
select.interfaceOptions = {
cssClass: 'my-custom-interface'
};

Properties

disabled

DescriptionIf true, the user cannot interact with the select option. This property does not apply when interface="action-sheet" as ion-action-sheet does not allow for disabled buttons.
Attributedisabled
Typeboolean
Defaultfalse

value

DescriptionThe text value of the option.
Attributevalue
Typeany
Defaultundefined

Events

No events available for this component.

Methods

No public methods available for this component.

CSS Shadow Parts

No CSS shadow parts available for this component.

CSS Custom Properties

No CSS custom properties available for this component.

Slots

No slots available for this component.