Fix legend items state loss after toggle