The way buttons capture the mouse is somewhat special and comes with complications in some other cases.
I think the real question here is why would you need/like a behaviour like that.
In theory, you could save the mouse button state into a variable in onMouseLeave - bool ButtonWasDown(T). Leave the viewport, release the mouse. In the onMouseEnter, check what the state was and compare it to the current button state - IsMouseButtonDown. If it’s not down, it means it was released outside of the widget and you can simulate firing OnMouseButtonUp.
Untested but that could work.
Still, this is awkward and hacky. Another real question is: do you want to invest time and energy into something that may not be a gamebreaking feature?
My advice is: pick your battles!