baoagency / polaris_view_components

ViewComponents for Polaris Design System
https://polarisviewcomponents.org
MIT License
388 stars 54 forks source link

Adding target: :top to polaris_button_to adds it to the button not the form #448

Closed rbarreca closed 2 months ago

rbarreca commented 2 months ago

I want a button to open in the _top frame (I'm navigating the user to Quickbooks to authenticate). Is there a way to do that with polaris_button_to?

This doesn't work as it adds the target to the button not the form element:

<%= polaris_button_to("Authenticate with Quickbooks", 
  @quickbooks_authenticate_url,
  { 
    method: :get,
    target: "_top" 
  }
)
%>

This works but is gross:

<%= polaris_button_to("Authenticate with Quickbooks", 
  @quickbooks_authenticate_url,
  { onclick: "window.top.location = '#{quickbooks_authenticate_url}'" }
)
%>
kirillplatonov commented 2 months ago

polaris_button_to will generate form with submit button under the hood. It's easier to use plain polaris_button in your case:

<%= polaris_button(url: "https://shopify.dev", target: "_top") { "Authenticate with Quickbooks" } %>