From 6a184496d65abe7af17f683053e91df2cffcd21b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 2 Oct 2019 14:12:17 +0200 Subject: [PATCH] treeview refactor 2 --- .../components/icon-button/icon-button.js | 31 +++++----- front/core/components/treeview/childs.html | 57 +++++-------------- front/core/components/treeview/childs.js | 19 +------ front/core/components/treeview/content.js | 8 ++- front/core/components/treeview/index.html | 20 +++---- front/core/components/treeview/index.js | 41 ++++++++++++- front/core/components/treeview/style.scss | 15 ++++- modules/worker/front/department/index.html | 7 +-- 8 files changed, 102 insertions(+), 96 deletions(-) diff --git a/front/core/components/icon-button/icon-button.js b/front/core/components/icon-button/icon-button.js index b4022ccec..ba3ccae3e 100644 --- a/front/core/components/icon-button/icon-button.js +++ b/front/core/components/icon-button/icon-button.js @@ -3,23 +3,28 @@ import './style.scss'; export default class IconButton { constructor($element) { - if ($element[0].getAttribute('tabindex') == null) - $element[0].tabIndex = 0; + this.element = $element[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(); - }); + 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)); } - onKeyDown(event, $element) { + onKeyup(event) { + if (event.code == 'Space') + this.onClick(event); + } + + onClick(event) { if (event.defaultPrevented) return; - if (event.keyCode == 13) { - event.preventDefault(); - $element.triggerHandler('click'); - } + event.preventDefault(); + + // FIXME: Don't use Event.stopPropagation() + let button = this.element.querySelector('button'); + if (this.disabled || button.disabled) + event.stopImmediatePropagation(); } } diff --git a/front/core/components/treeview/childs.html b/front/core/components/treeview/childs.html index cd0c59ec0..e185f44db 100644 --- a/front/core/components/treeview/childs.html +++ b/front/core/components/treeview/childs.html @@ -1,69 +1,42 @@ -