page Selectcomponent { seo { title = "Select component" description = "Theme-aware, responsive select component." } view {
W WRNexusJS
forms component

Select

Theme-aware, responsive select component.

@wrnexus/ui 0.5.022 props0 slots7 events

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

PropTypeRequirementDefault
sizestringOptional"default"
colorstringOptional"primary"
idstringOptional""
namestringOptional""
labelstringOptional"Select"
hiddenLabelbooleanOptionalfalse
valuestringOptional""
valuesstringOptional[]
optionsstringOptional[]
placeholderstringOptional"Select an option"
variantstringOptional"normal"
iconstringOptional""
iconPositionstringOptional"start"
helperTextstringOptional""
cornerHintstringOptional""
errorstringOptional""
inlinebooleanOptionalfalse
multiplebooleanOptionalfalse
readonlybooleanOptionalfalse
disabledbooleanOptionalfalse
requiredbooleanOptionalfalse
classstringOptional""

Slots

This component does not declare a slot.

Events

  • input
  • change
  • focus
  • blur
  • open
  • close
  • invalid

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>
    }
}
} }