Skip to main content

ion-picker

View Source

A Picker is a dialog that displays a row of buttons and columns underneath. It appears on top of the app's content, and at the bottom of the viewport.

Usage#

/* Using with useIonPicker Hook */
import React, { useState } from 'react';
import { IonButton, IonContent, IonPage, useIonPicker } from '@ionic/react';
const PickerExample: React.FC = () => {
const [present] = useIonPicker();
const [value, setValue] = useState('');
return (
<IonPage>
<IonContent>
<IonButton
expand="block"
onClick={() =>
present({
buttons: [
{
text: 'Confirm',
handler: (selected) => {
setValue(selected.animal.value)
},
},
],
columns: [
{
name: 'animal',
options: [
{ text: 'Dog', value: 'dog' },
{ text: 'Cat', value: 'cat' },
{ text: 'Bird', value: 'bird' },
],
},
],
})
}
>
Show Picker
</IonButton>
<IonButton
expand="block"
onClick={() =>
present(
[
{
name: 'animal',
options: [
{ text: 'Dog', value: 'dog' },
{ text: 'Cat', value: 'cat' },
{ text: 'Bird', value: 'bird' },
],
},
{
name: 'vehicle',
options: [
{ text: 'Car', value: 'car' },
{ text: 'Truck', value: 'truck' },
{ text: 'Bike', value: 'bike' },
],
},
],
[
{
text: 'Confirm',
handler: (selected) => {
setValue(`${selected.animal.value}, ${selected.vehicle.value}`)
},
},
]
)
}
>
Show Picker using params
</IonButton>
{value && (
<div>Selected Value: {value}</div>
)}
</IonContent>
</IonPage>
);
};

Properties#

animated#

DescriptionIf true, the picker will animate.
Attributeanimated
Typeboolean
Defaulttrue

backdropDismiss#

DescriptionIf true, the picker will be dismissed when the backdrop is clicked.
Attributebackdrop-dismiss
Typeboolean
Defaulttrue

buttons#

DescriptionArray of buttons to be displayed at the top of the picker.
Attributeundefined
TypePickerButton[]
Default[]

columns#

DescriptionArray of columns to be displayed in the picker.
Attributeundefined
TypePickerColumn[]
Default[]

cssClass#

DescriptionAdditional classes to apply for custom CSS. If multiple classes are
provided they should be separated by spaces.
Attributecss-class
Typestring \| string[] \| undefined
Defaultundefined

duration#

DescriptionNumber of milliseconds to wait before dismissing the picker.
Attributeduration
Typenumber
Default0

enterAnimation#

DescriptionAnimation to use when the picker is presented.
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) \| undefined
Defaultundefined

keyboardClose#

DescriptionIf true, the keyboard will be automatically dismissed when the overlay is presented.
Attributekeyboard-close
Typeboolean
Defaulttrue

leaveAnimation#

DescriptionAnimation to use when the picker is dismissed.
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) \| undefined
Defaultundefined

mode#

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" \| "md"
Defaultundefined

showBackdrop#

DescriptionIf true, a backdrop will be displayed behind the picker.
Attributeshow-backdrop
Typeboolean
Defaulttrue

Events#

NameDescription
ionPickerDidDismissEmitted after the picker has dismissed.
ionPickerDidPresentEmitted after the picker has presented.
ionPickerWillDismissEmitted before the picker has dismissed.
ionPickerWillPresentEmitted before the picker has presented.

Methods#

dismiss#

DescriptionDismiss the picker overlay after it has been presented.
Signaturedismiss(data?: any, role?: string \| undefined) => Promise<boolean>

getColumn#

DescriptionGet the column that matches the specified name.
SignaturegetColumn(name: string) => Promise<PickerColumn \| undefined>

onDidDismiss#

DescriptionReturns a promise that resolves when the picker did dismiss.
SignatureonDidDismiss<T = any>() => Promise<OverlayEventDetail<T>>

onWillDismiss#

DescriptionReturns a promise that resolves when the picker will dismiss.
SignatureonWillDismiss<T = any>() => Promise<OverlayEventDetail<T>>

present#

DescriptionPresent the picker overlay after it has been created.
Signaturepresent() => Promise<void>

CSS Custom Properties#

NameDescription
--backdrop-opacityOpacity of the backdrop
--backgroundBackground of the picker
--background-rgbBackground of the picker in rgb format
--border-colorBorder color of the picker
--border-radiusBorder radius of the picker
--border-styleBorder style of the picker
--border-widthBorder width of the picker
--heightHeight of the picker
--max-heightMaximum height of the picker
--max-widthMaximum width of the picker
--min-heightMinimum height of the picker
--min-widthMinimum width of the picker
--widthWidth of the picker