Clearance for bathroom vent fan
Typical bathroom fans have a 4” or 6” duct to the exterior. Leaving a similar area between the vent grille opening and the top of the new cabinet should be satisfactory. (6” diameter area is about 28”. Therefore, if the cabinet is about 28” long, then you’d need about 1” clearance between the top of the cabinet and the ceiling.)