Off canvas dialog using a button I am trying to adapt the relatively new off canvas dialog introduced in Drupal 8.5.

It is suggested to use it with the Drupal Form-API and a link element like this:

$form['off_canvas'] = [
  '#title'      =&gt; 'Some title',
  '#type'       =&gt; 'link',
  '#url'        =&gt; \Drupal\Core\Url::fromRoute('some route'),
  '#attributes' =&gt; [
    'class'                =&gt; ['use-ajax'],
    'data-dialog-type'     =&gt; 'dialog',
    'data-dialog-renderer' =&gt; 'off_canvas',
    'data-dialog-options'  =&gt; \Drupal\Component\Serialization\Json::encode(['width' =&gt; '40%']),
  ],
  '#attached'   =&gt; [
    'library' =&gt; [
      'core/drupal.dialog.ajax',
    ],
  ],
];


This works pretty straight forward and out of the box, but for a very special use case I need to attach an AJAX-callback with a button element which is not possible using a link element when looking at the Drupal form API specifications.

This is what I got trying to use a button element and a callback with off canvas dialog functionality:

$form['some_button'] = [
  '#type'     =&gt; 'button',
  '#value'    =&gt; 'some value',
  '#attached' =&gt; [
    'library' =&gt; [
      'core/drupal.dialog.ajax',
    ],
  ],
  '#ajax'     =&gt; [
    'callback' =&gt; '::some_callback',
  ],
];


Callback function goes here:

public function some_callback(&amp;$form, FormStateInterface $form_state) {

  $response = new \Drupal\Core\Ajax\AjaxResponse();

  $title = 'Some title';

  $content = '&lt;div&gt;Some content&lt;/div&gt;';
  $options = [];
  $response-&gt;addCommand(new \Drupal\Core\Ajax\OpenOffCanvasDialogCommand($title, $content, $options));
  return $response;
}


The funny thing is: once the off canvas dialog is initialized using $form['off_canvas'] it works on both elements for $form['off_canvas'] and $form['some_button']. On pageload it uses the old dialog for $form['some_button'] and the new off canvas dialog for $form['off_canvas'].

So this must be an initialization problem for $form['some_button]. But I can not get this to work with the off canvas dialog at pageload and documentation for the new off canvas functionality is quite rare. 

I tried to tell $form['some_button'] to use off canvas as a parameter in a lot of ways, but it does not work. I guess I missed something here.

Can you guys give me a hint how to make this work from the very start using a button with an Ajax callback?
When getting back to this issue I did notice the strange behaviour is gone after upgrading to the latest Drupal 8.6.3. All works as expected even using a button.

I am not able to reproduce the behavior/error from above.