I did this by adding this code in the functions.php of my child theme:
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();
$items .= '<li>' . $searchform . '</li>';
return $items;
}
You will need to modify your CSS some as well to prevent it from appearing on multiple lines:
form#searchform
{
margin: 0.5em 0em;
width: auto;
}
form#searchform .field
{
width: auto;
}