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

[WNMGDS-2521] Add custom event handling to web components #2738

Merged
merged 14 commits into from
Oct 18, 2023

Conversation

zarahzachz
Copy link
Collaborator

@zarahzachz zarahzachz commented Oct 10, 2023

WNMGDS-2521

  • Skipping analytics unit tests until solution can be agreed upon
    • Web component define function overwrites default analytics function; need to figure out how to fix this
    • Alert analytics fire before events can be added
  • Update USA banner web component snapshot (changes due to Learn's whitespace solution)
  • Add functionality to define custom events on a web component

@zarahzachz zarahzachz marked this pull request as draft October 10, 2023 14:03
@zarahzachz zarahzachz changed the title [WNMGDS-2521] Refine web components [WIP] [WNMGDS-2521] Refine web components Oct 10, 2023
@zarahzachz zarahzachz marked this pull request as ready for review October 16, 2023 20:45
@zarahzachz zarahzachz requested a review from pwolfert October 16, 2023 20:45
@zarahzachz zarahzachz changed the title [WIP] [WNMGDS-2521] Refine web components [WNMGDS-2521] Refine web components Oct 16, 2023
Comment on lines +111 to +115
// events.forEach((name) => {
// Object.defineProperty(CustomElement.prototype, name, {
// set(v) {
// if (this.__mounted) {
// this.attributeChangedCallback(name, null, v);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just had an idea that we could explore later: What if instead of trying to define the callback that they add as one of the props (which clobbers any listeners we made before) we instead added an event listener in this function? Like bob.onChange = myCallback results in bob.addEventListener('ds-change', myCallback)?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could pull the kebabCaseIt(name.replace('on', 'ds')) logic out into its own function and then use it here in this set function and in the proxyEvents function

@pwolfert pwolfert added this to the 9.0.0 milestone Oct 16, 2023
@pwolfert pwolfert added Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Added Indicates a new feature. labels Oct 16, 2023
@pwolfert
Copy link
Contributor

Since this is mostly about adding the event-handling code, could the PR title reflect that?

@zarahzachz zarahzachz changed the title [WNMGDS-2521] Refine web components [WNMGDS-2521] Add custom event handling to web components Oct 17, 2023
Copy link
Contributor

@pwolfert pwolfert left a comment

Choose a reason for hiding this comment

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

Good work! This is an exciting feature

aria-labelledby="static-id__a11y-label"
aria-labelledby="alert--1__a11y-label"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know why this changed? I don't see code that actually defines the root-id, but I also don't see that it was removed in this branch. Like I get why the static id isn't present, but why was it ever static before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i noticed the static id wasn't set and figured this was a fix but no clue why it changed.

@zarahzachz zarahzachz merged commit 3ed6928 into main Oct 18, 2023
@zarahzachz zarahzachz deleted the WNMGDS-2521/refine-web-components branch October 18, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Core Impacts the core DS primarily, changes may occur in other themes as well. Type: Added Indicates a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants