Listbox

The listbox displays a list of items/options that are selectable to the user.

Basic Usage

Edit Banshee - Listbox Basic

<banshee-listbox :items="forsaken">
  <banshee-listbox-item>
    <template slot-scope="{ active, item }">
      <span :class="{ active }">{{ item }}</span>
    </template>
  </banshee-listbox-item>
</banshee-listbox>

<script>
  //...
  data: () => ({
    forsaken: ['Sylvanas', 'Nathanos', 'Belmont', 'Mortuus', 'Voss']
  })
</script>

The listbox is composed of two tags:

  • <banshee-listbox> - parent tag, designates area to be a listbox and initializes internal state + keyboard interactions
  • <banshee-listbox-item> - direct child of <banshee-listbox>, exposes scoped slot for content rendering helpers

Listbox

Attributes & Props

NameRequiredTypeDefaultDescription
default-focusfalse[String, Number]0Default index of item to focus on mounted
default-selectedfalse[String, Number, Array]nullDefault index(es) of item(s) to be selected on mounted
itemstrueArraynullItems to be presented within listbox
item-keyfalseString'id'If each element in items is an object, what to key each listbox-item by
tagfalseStringdivHTML tag for listbox

Events

EventParametersDescription
onFocus(index, item)triggers when you focus an item within the listbox, provides the index of that item and the item itself
onSelectItem(item, selected)triggers when you select an item from the listbox, provides the current item and all the selected items
onRemoveItem(removed, selected)triggers when you remove an item from the selected items, provides the removed item and all the selected items
onTransfer(selected)triggers when you transfer items between listboxes, provides the selected items

Scoped Slots

PropertyDescription
itemsthe items in the listbox
focusmethod for focusing an item, expects an index
focusedthe currently focused index
selectItemmethod for selecting an item
selectedItemsthe array of currently selected items
totalthe length of the items array
totalSelectedthe length of the selected array
transfermethod to setup new focus and reset internal state on item transfers

Listbox Item

Attributes & Props

NameRequiredTypeDefaultDescription
tagfalseStringdivHTML tag for listbox-item

Scoped Slots

PropertyDescription
activeboolean whether the current item is actively being focused or not
itemeach individual element in the items array
indexthe item's index
selectedboolean whether the current item is selected

Example: List Transfer

Edit Banshee - Listbox Transfer

<template>
  <div id="app">
    <banshee-listbox @onTransfer="transfer" :items="characters">
      <banshee-listbox-item>
        <template slot-scope="{ active, item, selected }">
          <template v-if="selected">&#10004;</template> <span :class="{ active }">{{ item }}</span>
        </template>
      </banshee-listbox-item>

      <template slot-scope="{ transfer }">
        <button @click="transfer">Transfer</button>
      </template>
    </banshee-listbox>

    <banshee-listbox :items="favoriteCharacters">
      <p>My favorite:</p>
      <banshee-listbox-item>
        <template slot-scope="{ item }">
          {{ item }}
        </template>
      </banshee-listbox-item>
    </banshee-listbox>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      characters: [
        'Varian', 'Sylvanas', 'Thrall', 'Saurfang',
        'Malfurion', 'Tyrande', 'Greymane', 'Nathanos',
        'Anduin', 'Illidan', 'Khadgar', 'Vol\'jin',
        'Chen', 'Garrosh', 'Velen', 'Bolvar',
        'Arthas', 'Jaina', 'Muradin', 'Mograine'
      ],
      favoriteCharacters: []
    }
  },
  methods: {
    transfer ({ selected }) {
      this.characters = this.characters.filter(x => !selected.includes(x))
      this.favoriteCharacters.push(...selected)
    }
  }
}
</script>
Last Updated: 6/14/2018, 8:48:52 AM