Fix state update issue when close/open menu by code