2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2018-04-19 12:46:06 +00:00
|
|
|
import './style.scss';
|
2017-01-31 13:13:06 +00:00
|
|
|
|
2018-04-19 12:46:06 +00:00
|
|
|
export default class IconButton {
|
|
|
|
constructor($element) {
|
2018-06-07 21:47:19 +00:00
|
|
|
if ($element[0].getAttribute('tabindex') == null)
|
|
|
|
$element[0].tabIndex = 0;
|
2018-10-17 10:49:18 +00:00
|
|
|
|
2019-02-13 13:01:37 +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();
|
|
|
|
});
|
2018-04-19 12:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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', {
|
2018-04-19 12:46:06 +00:00
|
|
|
controller: IconButton,
|
2017-06-13 11:08:06 +00:00
|
|
|
template: require('./icon-button.html'),
|
|
|
|
bindings: {
|
|
|
|
icon: '@',
|
2018-10-17 10:49:18 +00:00
|
|
|
disabled: '<?'
|
2017-06-15 09:22:47 +00:00
|
|
|
}
|
2017-06-13 11:08:06 +00:00
|
|
|
});
|