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

#3140 - Maintain focus after filter selection [-NL] #3533

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

CocoByte
Copy link
Contributor

@CocoByte CocoByte commented Feb 17, 2025

Ticket 3140

Resolves #3140

Changes

  • Added javascript to detect filter clicks and preserve focus on that filter after page refresh
  • Added ids to filters in order to allow for focus targeting
  • Added a helper function for screenreader announcements

Context for reviewers

Setup

Code Review Verification Steps

As the original developer, I have

Satisfied acceptance criteria and met development standards

  • Met the acceptance criteria, or will meet them in a subsequent PR
  • Created/modified automated tests
  • Update documentation in READMEs and/or onboarding guide

Ensured code standards are met (Original Developer)

  • If any updated dependencies on Pipfile, also update dependencies in requirements.txt.
  • Interactions with external systems are wrapped in try/except
  • Error handling exists for unusual or missing values

Validated user-facing changes (if applicable)

  • Tag @dotgov-designers in this PR's Reviewers for design review. If code is not user-facing, delete design reviewer checklist
  • Verify new pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)

As a code reviewer, I have

Reviewed, tested, and left feedback about the changes

  • Pulled this branch locally and tested it
  • Verified code meets all checks above. Address any checks that are not satisfied
  • Reviewed this code and left comments. Indicate if comments must be addressed before code is merged
  • Checked that all code is adequately covered by tests
  • Verify migrations are valid and do not conflict with existing migrations

Validated user-facing changes as a developer

Note: Multiple code reviewers can share the checklists above, a second reviewer should not make a duplicate checklist. All checks should be checked before approving, even those labeled N/A.

  • New pages have been added to .pa11yci file so that they will be tested with our automated accessibility testing
  • Checked keyboard navigability
  • Meets all designs and user flows provided by design/product
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • (Rarely needed) Tested as both an analyst and applicant user

As a designer reviewer, I have

Verified that the changes match the design intention

  • Checked that the design translated visually
  • Checked behavior. Comment any found issues or broken flows.
  • Checked different states (empty, one, some, error)
  • Checked for landmarks, page heading structure, and links

Validated user-facing changes as a designer

  • Checked keyboard navigability
  • Tested general usability, landmarks, page header structure, and links with a screen reader (such as Voiceover or ANDI)
  • Tested with multiple browsers (check off which ones were used)
    • Chrome
    • Microsoft Edge
    • FireFox
    • Safari
  • (Rarely needed) Tested as both an analyst and applicant user

References

Screenshots

Copy link

🥳 Successfully deployed to developer sandbox nl.

Copy link

🥳 Successfully deployed to developer sandbox nl.

1 similar comment
Copy link

🥳 Successfully deployed to developer sandbox nl.

@CocoByte CocoByte changed the title [DRAFT] #3140 - Maintain focus after filter selection #3140 - Maintain focus after filter selection Feb 23, 2025
@SamiyahKey SamiyahKey requested review from SamiyahKey and removed request for a team February 25, 2025 14:22
Copy link
Contributor

@zandercymatics zandercymatics left a comment

Choose a reason for hiding this comment

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

Works great! See comments for some code changes though, but after those are in (or otherwise discussed) I'd be glad to approve

I like your approach here

let focusedElement = document.getElementById(lastClickedFilterId);
if (focusedElement) {
//Focus the element
focusedElement.setAttribute("tabindex", "-1");
Copy link
Contributor

@zandercymatics zandercymatics Feb 25, 2025

Choose a reason for hiding this comment

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

(Q) Why is -1 added here? Isn't < a > tab-able by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just another (more enforced) way of focusing the element so that you can immediately resume tabbing from it.

Comment on lines +695 to +705
if (lastClickedFilterId) {
let focusedElement = document.getElementById(lastClickedFilterId);
if (focusedElement) {
//Focus the element
focusedElement.setAttribute("tabindex", "-1");
focusedElement.focus({ preventScroll: true });

// Announce focus change for screen readers
announceForScreenReaders("Filter refocused on " + focusedElement.textContent);
}
}
Copy link
Contributor

@zandercymatics zandercymatics Feb 25, 2025

Choose a reason for hiding this comment

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

Suggested change
if (lastClickedFilterId) {
let focusedElement = document.getElementById(lastClickedFilterId);
if (focusedElement) {
//Focus the element
focusedElement.setAttribute("tabindex", "-1");
focusedElement.focus({ preventScroll: true });
// Announce focus change for screen readers
announceForScreenReaders("Filter refocused on " + focusedElement.textContent);
}
}
if (lastClickedFilterId) {
let focusedElement = document.getElementById(lastClickedFilterId);
if (focusedElement) {
//Focus the element
focusedElement.setAttribute("tabindex", "-1");
focusedElement.focus({ preventScroll: true });
// Announce focus change for screen readers
announceForScreenReaders("Filter refocused on " + focusedElement.textContent);
}
// Cleanup the filter after use
localStorage.removeItem("admin_filter_focus_id");
}

(optional) Rather than using an event listener, I think just adding a cleanup step right after use should be sufficient! This should be more performant. What are your thoughts?

Comment on lines +33 to +34
liveRegion.style.position = "absolute";
liveRegion.style.left = "-9999px";
Copy link
Contributor

Choose a reason for hiding this comment

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

(blocking) Can you use class="usa-sr-only" instead?

@@ -0,0 +1,12 @@
{% load i18n %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{% load i18n %}
{% comment %} Override of this file: https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/filter.html {% endcomment %}
{% load i18n %}

(optional / nice to have) For tracing purposes, this would be helpful! Not needed though, just a minor time saver

@zandercymatics zandercymatics self-assigned this Feb 25, 2025
Copy link
Contributor

@zandercymatics zandercymatics left a comment

Choose a reason for hiding this comment

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

Swapping over to approved since the requested changes are small! Just shoot me a message when your changes are in and I'll take a quick look, though hold off on merging before looking through it

Also worth noting that you have some merge conflicts

@CocoByte CocoByte changed the title #3140 - Maintain focus after filter selection #3140 - Maintain focus after filter selection [-NL] Feb 27, 2025
Copy link

🥳 Successfully deployed to developer sandbox nl.

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.

Maintain focus after filter selection
3 participants