Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: No reliable way to make ion-button programatically focusable #29830

Closed
3 tasks done
FabianGutierrezOpengov opened this issue Sep 3, 2024 · 3 comments · Fixed by #29916
Closed
3 tasks done

bug: No reliable way to make ion-button programatically focusable #29830

FabianGutierrezOpengov opened this issue Sep 3, 2024 · 3 comments · Fixed by #29916
Labels

Comments

@FabianGutierrezOpengov
Copy link

FabianGutierrezOpengov commented Sep 3, 2024

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

Preexisting mentions

#21439

Issue

This have been asked before, but it seems the workaround provided here will clash with the internal button tag inside the component and makes button require two tab presses to move their focus to the next element.

this in my humble opinion looks like an A11Y issue as we're nesting interactive elements.

Expected Behavior

adding tabindex="0" should allow element to be programatically focusable but not make it to require 2 tabs to be jumped over

Steps to Reproduce

check sample given at #21439

Code Reproduction URL

#21439

Ionic Info

@angular-devkit/build-angular : 17.1.1
@angular-devkit/schematics : 17.1.1
@angular/cli : 17.1.1
@ionic/angular-toolkit : 11.0.1

Capacitor:

Capacitor CLI : 6.1.2 @capacitor/core : 6.1.2
Utility:

cordova-res : not installed
native-run : 2.0.1

System:

NodeJS : v20.11.0 (C:\Program Files\nodejs\node.exe)
npm : 10.2.4
OS : Windows 10

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Sep 3, 2024
@brandyscarney
Copy link
Member

Thank you for the issue! I agree that adding tabindex="0" may not provide the best user experience, as it requires users to tab twice to achieve focus. If you're using an ion-app, the following should work to focus a button element:

<ion-app>
  <ion-content class="ion-padding">
    <ion-button onClick="focusButton()">Focus Button</ion-button>
    <ion-button id="focusThis">
      Button
    </ion-button>
  </ion-content>
</ion-app>
function focusButton() {
  var buttonEl = document.querySelector('#focusThis');

  const app = buttonEl.closest('ion-app');
  if (app) {
    app.setFocus([buttonEl]);
  }
}

You can view a working example on CodePen: https://codepen.io/brandyscarney/pen/gONQvpX?editors=1010

I've raised this with the team to explore a better solution for using the native focus() with the button. I'll update this issue once we've decided on the best approach. 🙂

@brandyscarney
Copy link
Member

I spoke with the team and we decided to document the above usage. I've created an issue for this here: ionic-team/ionic-docs#3815. Let me know if there are any issues with this. Thank you!

@brandyscarney brandyscarney closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 1, 2024
Issue number: resolves #29830

---------

## What is the current behavior?
The `setFocus` method on `ion-app` is marked internal.

## What is the new behavior?
Document the `setFocus` method as a way for developers to
programmatically focus elements.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

## Other information

The method isn’t new, it was just marked as internal, which prevented it
from being documented. I can mark this as a `feat` though if anyone
thinks it should be.

Related documentation PR:
ionic-team/ionic-docs#3842
Copy link

ionitron-bot bot commented Oct 31, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants