Skip to content

USWDS - Core: Replace receptor library "once" with once option for event listeners#6172

Merged
heymatthenry merged 1 commit into
uswds:replace-receptorfrom
aduth:aduth-rm-receptor-once
Jan 31, 2025
Merged

USWDS - Core: Replace receptor library "once" with once option for event listeners#6172
heymatthenry merged 1 commit into
uswds:replace-receptorfrom
aduth:aduth-rm-receptor-once

Conversation

@aduth

@aduth aduth commented Nov 1, 2024

Copy link
Copy Markdown
Contributor

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

@mahoneycm mahoneycm left a comment

Copy link
Copy Markdown
Contributor

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.

@amyleadem amyleadem left a comment

Copy link
Copy Markdown
Contributor

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

@heymatthenry heymatthenry left a comment

Copy link
Copy Markdown
Contributor

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
@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