Disable Auto-Expanding Menu in WordPress Admin Menus

I see two options here – override the CSS, or remove the “active” classes with JavaScript (sadly there is no action/filter that we can do this server-side) – I opted for the JS approach, it’s cleaner, leaner and meaner:

function wpse_227037_remove_menu_classes() {
    echo '<script>jQuery( ".wp-has-current-submenu.wp-menu-open" ).removeClass( "wp-has-current-submenu wp-menu-open" ).addClass( "wp-not-current-submenu" );</script>';
}

add_action( 'adminmenu', 'wpse_227037_remove_menu_classes' );

The adminmenu action fires right after the menu HTML, so the code will execute the moment all admin nodes are in the DOM.