In order to react to a toggle button change, add an event listener to the ribbonTabsLoaded event and identify the id of the desired ribbon element for example by using the browser developer tool.
A MutationObserver will allow you to react to changes in the DOM element. Switch statements can be used to distinguish between different cases.
It is important to use the correct observer configuration. Make sure to observe changes in the whole sub tree and also to pass the right root element as a target node in the MutationObserver.observe() method.
This code snippet shows how to detect toggles of the Bullet List dropdown in the ribbon Home tab. Therefore, the Paragraph group is passed as root element.