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

Adding keyboard navigation and screen reader support for Issue #182 #259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chebizarro
Copy link

@chebizarro chebizarro commented Oct 24, 2024

This pull request aims to address issue #182 by improving accessibility for users by enabling keyboard navigation and screen reader feedback.

Also fixes #170

The majority of the changes are simple additions of aria tags to the rendered html as well as extra handlers for keyboard navigation.

These changes will need more thorough testing as there is no simple way to test each component in isolation that I can see.


// Modal accessibility: handle modal state
if (this._modalOpen) {
this.setAttribute('aria-modal', 'true');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be directly set on the bc-modal component?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were removed with the other aria attributes to focus this pull request solely on keyboard navigation

}

// Trap focus when modal is open
protected _trapFocusInModal() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also be moved to the modal component? (if it is here, the code is applied to all components)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The focus trapping was removed as it doesn't work as expected with the way modals currently work

@@ -75,6 +81,14 @@ export class Button extends withTwind()(BitcoinConnectElement) {
private _onClick() {
launchModal();
}

// Handle keyboard events for accessibility (Enter/Space key triggers click)
public override _handleKeydown(event: KeyboardEvent) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am worried about using a key listener, why cannot this be tabbed to and then enter pressed like normal buttons?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed as the included bci-button is in fact a button element and receives the events normally

@rolznz
Copy link
Collaborator

rolznz commented Oct 28, 2024

@chebizarro thank you for the PR!

I think this is a huge change and we need to split it up, and focus on one thing per PR and make sure everything works.

Currently I think the most important thing is standard keyboard accessibility as normal keyboard power-users would find this useful.

I ran your PR and opened the dev mode (yarn dev)

To more easily test this, I would suggest we add a new html file just with one button so we can easily test there.

button.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Lit + TS</title>
    <style>
      body {
        font-family: Arial, Helvetica, sans-serif;
        margin: 0px;
        @media (prefers-color-scheme: dark) {
          background-color: black;
          color: white;
        }
      }

      .container {
        padding: 20px;
        max-width: 448px;
      }
    </style>
    <script type="module">
      import '../../src/index.ts';
    </script>
  </head>
  <body>
    <div class="container">
      <bc-button></bc-button>
    </div>
  </body>
</html>

If I load the page and press tab once this is what I see (incorrect item focused):

image

If I then open the modal I would expect the first connector to be focused by default. And if I tab forward once, it should select the next connector. If I tab backwards once I would expect it to go to the x and then ? if I tab backward again. There is a lot of tab and focus issues in this modal.

Do you think we could address this as a first step and maybe open a new PR for this alone?

Once I connect I think it's strange that it focuses on the currency by default. I guess this would not be such an issue if #100 is implemented (actually, I will see if I can get a bounty created for this issue too).

@chebizarro chebizarro force-pushed the issue-#182 branch 3 times, most recently from f98dd23 to 508a76e Compare November 2, 2024 00:37
@chebizarro
Copy link
Author

I refactored the branch and removed the aria attributes as they aren't necessary for keyboard navigation. I had misinterpreted the goal of this issue as adding accessibility features and not just enhanced keyboard navigation, so apologies for the confusion. This refactoring has resulted in far fewer changes across a much smaller number of files and is much more intelligible.

@chebizarro
Copy link
Author

Hi @rolznz, just wanted to bump this PR and see where you wanted to go with this?

@rolznz
Copy link
Collaborator

rolznz commented Nov 25, 2024

Hi @chebizarro the focusing is a lot better! I still found some issues:

  • I cannot tab to the currency switcher, so I do not know how to open it without using the mouse.
  • If I tab to the "Pay Now" button in dev mode and press enter, it does not focus the confirm payment button in the modal (content outside the modal is still focused)
  • I also do not understand why you need to manually add keydown events for e.g. the close button. Shouldn't pressing enter when focused on an element trigger the "@click" method? this is standard HTML behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hitting enter in connection pages does not submit form
2 participants