# j-Suggestion

> If the value isn't defined then the component uses name as value.

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

- supports 3 orientations `left`, `center` and `right`
- singleton
- works with Bootstrap Grid System
- works with touches
- supports __dark mode__


__Methods__:

Method: `component.show(orientation, targetElement, [items/function(search, next)], clickCallback)`

- `orientation {String}` can be `left`, `center` or `right`
- `targetElement {Selector/jQuery/Element}` a target where the component will be visible
- `items {Array}` optional and must have this structure: `[{ name: String, value: String, icon: String }]` otherwise will be items read from the target's `data-options` attribute.
- `callback(selectedItem) {Function}` is triggered when the user clicks on the item

Method: `component.hide()`

__Attributes__:
- `targetElement` can contain `data-options="Name 1|ti-building|Value 1;Name 2|ti-github|Value 2;"` attribute with all items of the context menu.

__Configuration__:
- `placeholder` - a placeholder for the search input

__Server-side searching__:

```javascript
SETTER('suggestion', 'show', element, function(search, next) {
	next([{ name: 'Item 1' }, { name: 'Item 2' }]);
}, function(selected) {
	console.log(selected);
});
```

If the `value` isn't defined then the component uses `name` as `value`.

__Global events__:

```javascript
ON('suggestion', function(visible, component, target) {
	console.log('Suggestion is', visible ? 'visible' : 'hidden');
});
```

Use it with `<ui-component name="suggestion">`. 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>
	body { background-color: #F0F0F0; }
</style>

<ui-component name="suggestion" config="placeholder:Search ..."></ui-component>

<div class="container">
	<a href="javascript:void(0)">Suggest</a>
</div>

<script>
	$(document).on('click', 'a', function() {
		SETTER('suggestion/show', 'left', this, [{ name: 'Total.js' }, { name: 'Express.js' }, { name: 'Meteor.js' }, { name: 'Koa.js' }, { name: 'ASP.NET' }, { name: 'PHP' }, { name: 'Python' }, { name: 'Node.js' }], function(value) {
			console.log('CLICK', value);
		});
	});
</script>
```
