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

35 lines
952 B
JavaScript

import ngModule from '../../module';
import './style.scss';
export default class IconButton {
constructor($element) {
if ($element[0].getAttribute('tabindex') == null)
$element[0].tabIndex = 0;
$element.on('keyup', event => this.onKeyDown(event, $element));
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'];
ngModule.component('vnIconButton', {
controller: IconButton,
template: require('./icon-button.html'),
bindings: {
icon: '@',
disabled: '<?'
}
});