# j-KeySelection

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

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 2729b88bf4f70616de0b0c5dbbee3ee61ad6ae3025ad56ade9a6f9e30dbd508a
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

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.

```html 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>
```
