How to unfocus button after ajax form was rebuilt? I have a form that is completely ajaxified and when I submit the form the submit button stays focused.

I have styling in place and it results in bad UX. How should I unfocus the button? Do I have to implement ajax response and some custom JS for this? Seems like a hacky solution :(
You can solve this by setting focus to another element on rebuild.

I don't know how to do it in Drupal 8, but here's Drupal 7 code to focus an element:

In the form_alter:

  // Focus the first element on rebuild.
  if ($form_state['rebuild']) {
    $first_element = array_keys($form['entry_fieldset']['entry_ids'])[0];
    $form_state['focus_id'] = $first_element;
  }

  // Allow a form element to be focused.
  if (isset($form_state['focus_id'])) {
    // Pass the element ID as a variable to the JS.
    $settings = array('focus_id' =&gt; $form_state['focus_id']);
    $form['#attached']['js'][] = array(
      'data' =&gt; array('example' =&gt; $settings),
      'type' =&gt; 'setting',
    );
  }


JS:

  /**
   * Focus a form element.
   */
  Drupal.behaviors.exampleFocusElement = {
    attach: function(context, settings) {
      if (settings.example &amp;&amp; settings.example.focus_id) {
        // Focus the element having the ID passed in.
        $('#' + settings.example.focus_id, context).focus();
      }
    }
  };