Skip to content

Commit

Permalink
Fix clicking on disabled menuitems (#142)
Browse files Browse the repository at this point in the history
* Fix bug where clicking on disabled menuitem would trigger click on its parent menu item

* Update version
  • Loading branch information
vkalpias authored Oct 12, 2021
1 parent aefff90 commit b8fd5c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@playcanvas/pcui",
"version": "2.2.2",
"version": "2.2.3",
"author": "PlayCanvas <[email protected]>",
"homepage": "https://playcanvas.github.io/pcui",
"description": "This library enables the creation of reliable and visually pleasing user interfaces by providing fully styled components that you can use directly on your site. The components are useful in a wide range of use cases, from creating simple forms to building graphical user interfaces for complex web tools.",
Expand Down
15 changes: 13 additions & 2 deletions src/MenuItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class MenuItem extends Container {

this.text = args.text || 'Untitled';

this.on('click', this._onClickMenuItem.bind(this));
this._domEvtMenuItemClick = this._onClickMenuItem.bind(this);
this.dom.addEventListener('click', this._domEvtMenuItemClick);

if (args.value) {
this.value = args.value;
Expand Down Expand Up @@ -111,7 +112,9 @@ class MenuItem extends Container {
_onClickMenuItem(evt) {
evt.preventDefault();
evt.stopPropagation();
this.select();
if (!this.disabled) {
this.select();
}
}

link(observers, paths) {
Expand Down Expand Up @@ -140,6 +143,14 @@ class MenuItem extends Container {
}
}

destroy() {
if (this.destroyed) return;

this.dom.removeEventListener('click', this._domEvtMenuItemClick);

super.destroy();
}

get text() {
return this._labelText.text;
}
Expand Down

0 comments on commit b8fd5c8

Please sign in to comment.