ForgeComponents
en

Components

j-KeySelection

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20

This component allows user to select some items by up/down keys and confirm selection by the enter key.

  • supports auto-scroll

Configuration

  • selectoritem {String} a selector for browsing items (default: .item)
  • selector {String} a default selector for capturing keys (default: input)
  • class {String} a selection class (default: selected)
  • autoselect {Boolean} it should select first item (default: true)
  • autoscroll {Boolean} enables/disables auto-scroll (default: true)
  • exec {String} a link to the function(jqueryel), evaluated by the enter key (optional, otherwise will be trigger click event)
  • delay {Number} a delay for auto-selecting first value
  • datasource {String} a link to the data-source that can help you with a dynamic list

Use it with <ui-component name="keyselection">. When the component is not loaded yet, jComponent downloads it on first use from the address in DEF.fallback (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

example.html
<style>
	.selected { background: #F0F0F0; }
	.item { line-height: 24px; padding: 0 10px; border-top: 1px solid #E0E0E0; font-size: 12px; }
</style>

<ui-component name="keyselection" config="exec:confirmselection">
	<div class="m"><input type="text" placeholder="Press UP or DOWN key" style="width:300px" /></div>
	<div class="items">
		<div class="item" data-id="1">1</div>
		<div class="item" data-id="1">2</div>
		<div class="item" data-id="1">3</div>
		<div class="item" data-id="1">4</div>
		<div class="item" data-id="1">5</div>
	</div>
</ui-component>

<script>

	function confirmselection(el) {
		console.log('selected', el);
	}

</script>