Data input

Select

Choose one option from a list: the browser's native select, or a custom Select with a styled list.

Class nameTypeDescription
selectplf:selectComponentA native select
select-triggerplf:select-triggerPartThe button the script adds after a custom select
select-valueplf:select-valuePartThe chosen label the script adds
select-chevronplf:select-chevronPartThe trigger's chevron the script adds
select-popupplf:select-popupPartThe option list the script adds
select-groupplf:select-groupPartAn option group the script adds
select-group-labelplf:select-group-labelPartA group's label the script adds
select-optionplf:select-optionPartAn option the script adds
select-labelplf:select-labelPartAn option's label the script adds
select-checkplf:select-checkPartAn option's check mark the script adds
select-statusplf:select-statusPartThe screen reader status the script adds
select-smplf:select-smSizeSmall
select-lgplf:select-lgSizeLarge

Dependent selects

The list follows the select’s options, so the script replaces the cities when the country changes.

JavaScript

The custom Select needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-select On a single select: adds the trigger and list after it; the trigger takes the select’s classes, style and hidden
data-plf-placeholder On the select: text for an option with an empty label; Select an option… by default
disabled On the select: disables the trigger too
Method Behavior
PLF.Select.getOrCreateInstance(element) Returns the instance, creating it for valid markup
PLF.Select.getInstance(element) Returns the instance or null
instance.open(), instance.close() Open or close the list; return false when nothing changes or the event is canceled
instance.select(value) Chooses an option and closes the list; returns false for an unknown, disabled or current value
instance.refresh() Shows a value your code set through .value, without events; options your code adds or replaces show by themselves
instance.destroy() Removes the trigger and list; the select keeps its value
Event When
plf:select:before-open, plf:select:open Before and after the list opens; the first is cancelable
plf:select:before-close, plf:select:close Before and after the list closes; the first is cancelable
plf:select:before-change, plf:select:change Before and after a new value; the first is cancelable

Each event’s detail:

Property Events Value
instance All The Select instance
reason All api, trigger or keyboard
trigger All The trigger button or the clicked option, the select for a native input or change, or null from a method or a press or focus outside
previousValue before-change, change The value before the change
value before-change, change The new value

A choice also fires native input and change on the select.

Keyboard

Key Action
Enter, Space, Arrow Down, Arrow Up Open the list; while open, Enter and Space choose the active option
Arrow Down, Arrow Up, Home, End Move through enabled options
Letters Move to the next option that starts with them
Tab Chooses the active option and moves on
Escape Closes the list without choosing

React

Select from @pelatform/react renders the native select around its option and optgroup children, with custom also the trigger and list the script adds; inside a Field it takes the field’s label, help and error.

Prop Values Default
size sm, lg The default size
custom true adds the trigger and list beside the select, which keeps the value false
onValueChange (value), called when the value changes None
placeholder With custom, the trigger’s text for an option with an empty label Select an option…
open With custom, true or false, which the application changes in onOpenChange Its own state
defaultOpen With custom, true starts open when the application does not set open false
onOpenChange With custom, (open, reason), called when the list opens or closes: trigger (the trigger, an option or a press outside) or keyboard (a key or the focus leaving) None

The other props are a native select’s, className and ref included; with custom, the trigger takes id, which the label names, and ref stays on the select.

CSS variables

Override on a root or a container; on the select itself they reach the trigger, not the list. The trigger takes the Input variables, as the native select does.

Variable Default
--plf-select-indicator The theme’s muted chevron-down, as an image on a single native select; replace it when you change the text color
--plf-select-icon-size --plf-control-icon-size (16px); 14px with select-sm, 18px with select-lg
--plf-select-popup-width At least the trigger’s width
--plf-select-popup-max-height 18rem (288px)
--plf-select-popup-border --plf-color-border-subtle
--plf-select-popup-bg --plf-color-surface-elevated

A native select draws its chevron as an image in the theme’s muted gray, which an override of --plf-color-text-muted does not reach; set the same chevron with your color, # written %23. An image cannot use light-dark(), so for a dark root set it again, in your dark color, in a [data-plf-theme="dark"] rule and an auto one:

CSS
.my-plugin[data-plf-root] {
  --plf-select-indicator: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons