GeneratePress offers such a Search feature. It can be enabled in Appearance > Customize > Layout > Primary Nav > Navigation Search.
This option adds a search icon (magnifying glass) to your navigation bar. When you click it, a semi-transparent search bar covers your menu items and allows you to enter a term to search your site.
if you want to add a search function inside a a Block Element then you would need to use the Search Block, or a plugin.
As the navigation search has to be included inside a navigation element to work.