Skip to content

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Nov 1, 2024

Summary

Reduced the JavaScript bundle size. By optimizing the implementation of core component code, overall JavaScript sizes are reduced.

Breaking change

This is not a breaking change.

Related pull requests

Split from #5793, to simplify review.

Preview link

N/A

Problem statement

See #5793

Solution

Replace use of receptor/once with addEventListener's once option (see documentation).

The intended purpose is the same.

receptor.once:

Returns a wrapped function that removes itself as an event listener as soon as it's called, then calls the callback function with the same arugments.

addEventListener once

A boolean value indicating that the listener should be invoked at most once after being added. If true, the listener would be automatically removed when invoked.

Testing and review

Verify that skipnav removes tabindex from body after activating and then moving focus away from the body.

Verify that in-page navigation removes tabindex from the target heading after activating and then moving focus away from the heading.

aduth added a commit to aduth/uswds that referenced this pull request Nov 1, 2024
Review feedback from uswds#6172
@mejiaj mejiaj added this to the USWDS release: January 2025 milestone Jan 3, 2025
Copy link
Contributor

@mahoneycm mahoneycm left a comment

Choose a reason for hiding this comment

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

LGTM! I like that we can use this native solution here. Thanks @aduth !

  • Replacement once is equivalent to previous value
  • Verify that skipnav removes tabindex from body after activating and then moving focus away from the body.
  • Verify that in-page navigation removes tabindex from the target heading after activating and then moving focus away from the heading.

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for breaking out this work, @aduth.

I confirmed the following:

  • No change in behavior with tabindex on target headers with in-page navigation
  • No change in behavior with tabindex on target element (main) with skipnav
  • No regressions in core functionality of in-page nav or skipnav
  • No errors with prettier or linting

Copy link
Contributor

@heymatthenry heymatthenry left a comment

Choose a reason for hiding this comment

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

Thank you, @aduth!

@heymatthenry heymatthenry merged commit b9b0bc7 into uswds:replace-receptor Jan 31, 2025
4 checks passed
@heymatthenry heymatthenry mentioned this pull request Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants