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

40 lines
1.0 KiB
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) {
2019-10-02 12:12:17 +00:00
this.element = $element[0];
2018-10-17 10:49:18 +00:00
2019-10-02 12:12:17 +00:00
if (this.element.getAttribute('tabindex') == null)
this.element.tabIndex = 0;
this.element.addEventListener('keyup', e => this.onKeyup(e));
this.element.addEventListener('click', e => this.onClick(e));
}
onKeyup(event) {
if (event.code == 'Space')
this.onClick(event);
}
2019-10-02 12:12:17 +00:00
onClick(event) {
if (event.defaultPrevented) return;
2019-10-02 12:12:17 +00:00
event.preventDefault();
// FIXME: Don't use Event.stopPropagation()
let button = this.element.querySelector('button');
if (this.disabled || button.disabled)
event.stopImmediatePropagation();
}
}
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: '<?'
}
});