Option
<p-option> | POption
Options define the selectable items within various form controls such as select.
<p-select label="Select one"> <p-option value="option-1">Option 1</p-option> <p-option value="option-2">Option 2</p-option> <p-option value="option-3">Option 3</p-option> </p-select>
import POption from 'pure-uikit/dist/react/option'; import PSelect from 'pure-uikit/dist/react/select'; const App = () => ( <PSelect> <POption value="option-1">Option 1</POption> <POption value="option-2">Option 2</POption> <POption value="option-3">Option 3</POption> </PSelect> );
Examples
Disabled
Use the disabled
attribute to disable an option and prevent it from being selected.
<p-select label="Select one"> <p-option value="option-1">Option 1</p-option> <p-option value="option-2" disabled>Option 2</p-option> <p-option value="option-3">Option 3</p-option> </p-select>
import POption from 'pure-uikit/dist/react/option'; import PSelect from 'pure-uikit/dist/react/select'; const App = () => ( <PSelect> <POption value="option-1">Option 1</POption> <POption value="option-2" disabled> Option 2 </POption> <POption value="option-3">Option 3</POption> </PSelect> );
Prefix & Suffix
Add icons to the start and end of menu items using the prefix
and suffix
slots.
<p-select label="Select one"> <p-option value="option-1"> <p-icon slot="prefix" name="envelope"></p-icon> Email <p-icon slot="suffix" name="patch-check"></p-icon> </p-option> <p-option value="option-2"> <p-icon slot="prefix" name="telephone"></p-icon> Phone <p-icon slot="suffix" name="patch-check"></p-icon> </p-option> <p-option value="option-3"> <p-icon slot="prefix" name="chat-dots"></p-icon> Chat <p-icon slot="suffix" name="patch-check"></p-icon> </p-option> </p-select>
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/option/option.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/option/option.js';
To import this component using a bundler:
import 'pure-uikit/dist/components/option/option.js';
To import this component as a React component:
import POption from 'pure-uikit/dist/react/option';
Slots
Name | Description |
---|---|
(default) | The option’s label. |
prefix
|
Used to prepend an icon or similar element to the menu item. |
suffix
|
Used to append an icon or similar element to the menu item. |
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
hidden
|
When true, the option is hidden from view. This is typically used when dynamically rendering a list of options. When an option becomes hidden, it will not be rendered in the DOM. When the option becomes visible again, it will be re-rendered in the DOM. |
|
boolean
|
false
|
value
|
The option’s value. When selected, the containing form control will receive this value. The value must be unique from other options in the same group. Values may not contain spaces, as spaces are used as delimiters when listing multiple values. |
|
string
|
""
|
disabled
|
Draws the option in a disabled state, preventing selection. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Methods
Name | Description | Arguments |
---|---|---|
getTextLabel() |
Returns a plain text label based on the option’s content. | - |
Learn more about methods.
Parts
Name | Description |
---|---|
checked-icon |
The checked icon, an <p-icon> element. |
base |
The component’s base wrapper. |
label |
The option’s label. |
prefix |
The container that wraps the prefix. |
suffix |
The container that wraps the suffix. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
<p-icon>