Skip to content

Autofocus option #275

@mateusbw

Description

@mateusbw

I'm currently working on some ADA requirements adjustments and i need the Google Pay button to be on focus when my page loads.

I tried a couple different solutions. The one i currently have is to use the onReadyToPayChange callback and if isButtonVisible is true, i get the button via jquery and force the focus.

onReadyToPayChange={({ isButtonVisible }) => {
  if (!isButtonVisible) return;
  const [button] = $('.gpay-button');

  if (button) {
    button.focus();
  }
}}

I would like to be able to the pass the html autoFocus attribute as a prop instead of forcing the focus using js.

I could't find in the Google Pay API docs the option to pass the attribute. So one possible solution could be to add the autofocus attribute (and any other native html attr) after the Google Pay client creates the button.

const button = this.client.createButton(buttonOptions);
button.firstChild.autofocus = this.config.autofocus;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions