Select
Theme-aware, responsive select component.
Usage
Components are auto-discovered. Use the component directly in any .wrn view:
<Select
size="default"
color="primary"
id="id"
name="name"
label="Select"
/>Legacy mount name: data-component="Select".
Props and attributes
| Prop | Type | Requirement | Default |
|---|---|---|---|
size | string | Optional | "default" |
color | string | Optional | "primary" |
id | string | Optional | "" |
name | string | Optional | "" |
label | string | Optional | "Select" |
hiddenLabel | boolean | Optional | false |
value | string | Optional | "" |
values | string | Optional | [] |
options | string | Optional | [] |
placeholder | string | Optional | "Select an option" |
variant | string | Optional | "normal" |
icon | string | Optional | "" |
iconPosition | string | Optional | "start" |
helperText | string | Optional | "" |
cornerHint | string | Optional | "" |
error | string | Optional | "" |
inline | boolean | Optional | false |
multiple | boolean | Optional | false |
readonly | boolean | Optional | false |
disabled | boolean | Optional | false |
required | boolean | Optional | false |
class | string | Optional | "" |
Slots
This component does not declare a slot.
Events
inputchangefocusbluropencloseinvalid
Source contract
Installed source: components/Select.wrn
component Select {
props {
@event input = function
@event change = function
@event focus = function
@event blur = function
@event open = function
@event close = function
@event invalid = function
size = "default"
color = "primary"
id = ""
name = ""
label = "Select"
hiddenLabel = false
value = ""
values = []
options = []
placeholder = "Select an option"
variant = "normal"
icon = ""
iconPosition = "start"
helperText = ""
cornerHint = ""
error = ""
inline = false
multiple = false
readonly = false
disabled = false
required = false
class = ""
}
functions {
function selected(option) {
if (multiple) return values.includes(option.value)
return option.value === value
}
function emitField(nameEvent, sourceEvent) {
sourceEvent.stopPropagation()
$emit(nameEvent, { value: sourceEvent.currentTarget.value, name: name, sourceEvent: sourceEvent })
}
function handleFocus(sourceEvent) { emitField("focus", sourceEvent); $emit("open", { name: name, sourceEvent: sourceEvent }) }
function handleBlur(sourceEvent) { emitField("blur", sourceEvent); $emit("close", { name: name, sourceEvent: sourceEvent }) }
function handleInvalid(sourceEvent) { $emit("invalid", { name: name, message: sourceEvent.currentTarget.validationMessage, sourceEvent: sourceEvent }) }
}
view {
<div {...attrs} class="wire-next wire-next--color-{color} wire-next--size-{size} wire-next--field wire-next--select {class}" data-variant="{variant}" data-inline="{inline}" data-floating="{variant === 'floating'}" data-invalid="{error ? 'true' : 'false'}" data-readonly="{readonly}">
<div class="wire-next__field-heading">
<label class="{hiddenLabel ? 'wire-next__sr-only' : ''}" for="{id || name}">{label}</label>{#if cornerHint}<span class="wire-next__field-hint">{cornerHint}</span>{/if}</div>
<div class="wire-next__field-control" data-icon-position="{iconPosition}">
{#if icon}<span class="{icon} wire-next__field-icon" aria-hidden="true">
</span>{/if}
<select id="{id || name}" name="{name}" multiple="{multiple}" disabled="{disabled || readonly}" required="{required}" aria-readonly="{readonly}" aria-invalid="{error ? 'true' : 'false'}" @input="emitField('input', event)" @change="emitField('change', event)" @focus="handleFocus(event)" @blur="handleBlur(event)" @invalid="handleInvalid(event)">
{#if !multiple}<option value="" selected="{value === ''}" disabled="{required}">{placeholder}</option>{/if}
{#each options as option}<option value="{option.value}" selected="{selected(option)}" disabled="{option.disabled}">{option.label}</option>{/each}
</select>
{#if variant === "floating"}<span class="wire-next__field-floating-label">{label}</span>{/if}
</div>
{#if helperText}<small class="wire-next__field-help">{helperText}</small>{/if}
<small class="wire-next__field-error" data-error="{name}">{error}</small>
</div>
}
}