Click handler of port is executed even though port was hidden

I have a node with ports which are only visible when the node is selected (Binding on the nodes isSelected property and then setting pickable and opacity for each port in the binding).

The ports also have a click handler.

Now if I select a node by clicking into the area where the hidden port is, the node is selected (ok), the ports are shown (ok) but also the click handler of the port is executed (not ok).

Seems like internally first the isSelected binding is executed (the pickable of all nodes is changed) and then the click handler of the now pickable port is executed)

How can I make sure that the click handler of the port is only executed if the ports have already been visible?

Does it work if you didn’t use a Binding of isSelected but instead implemented the Part.selectionChanged event handler?

Unfortunately still the same behaviour (the popup is triggered by

Yes, the standard behavior is to select first, and then handle the click event. This way is needed so that the common case works naturally of having the click handler depend on the part being selected.

But if you swap the order of those actions:

    $(go.Diagram, . . .,
        "clickSelectingTool.doMouseUp": function() {
          if (this.isActive) {
            // normally the call to standardMouseSelected happens here
            const handled = this.standardMouseClick();
            if (!handled) {
              if (this.diagram.lastInput.isTouchEvent) {
            this.standardMouseSelect();  // this statement was moved down from above

does it do what you want? I’m wondering about any other side-effects, though.

Thank you, this worked. Haven’t discovered any side-effects in our project yet.
I have some concerns if I can keep this code though. Will I discover any side-effects later on? Will a future update of goJS break this workaround?

Any change to get better support for our use case in goJS or do I have to stick with this solution?

You are only modifying the ClickSelectingTool, so the effects of your override are strictly limited to that tool. If no mouse/finger/stylus selection behaviors are broken, I believe you’ll be OK.