salix/front/core/components/icon-button/icon-button.js

35 lines
952 B
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import './style.scss';
export default class IconButton {
constructor($element) {
if ($element[0].getAttribute('tabindex') == null)
$element[0].tabIndex = 0;
2018-10-17 10:49:18 +00:00
$element.on("keyup", event => this.onKeyDown(event, $element));
2018-10-17 10:49:18 +00:00
let button = $element[0].querySelector('button');
$element[0].addEventListener('click', event => {
if (this.disabled || button.disabled)
event.stopImmediatePropagation();
});
}
onKeyDown(event, $element) {
if (event.defaultPrevented) return;
if (event.keyCode == 13) {
event.preventDefault();
$element.triggerHandler('click');
}
}
}
IconButton.$inject = ['$element'];
2018-02-10 15:18:01 +00:00
ngModule.component('vnIconButton', {
controller: IconButton,
template: require('./icon-button.html'),
bindings: {
icon: '@',
2018-10-17 10:49:18 +00:00
disabled: '<?'
}
});