Skip to content

Conversation

@evanyan13
Copy link
Contributor

@evanyan13 evanyan13 commented Apr 18, 2025

Context

  • Right now, clicking on a product swatch redirects to the PDP because the product card is basically an anchor tag, and clicking on that tag redirects to the PDP

  • We need to fix this behavior such that click on the product swatches doesn't redirect

  • To see an example of this issue, you can go to this Sandbox and add /collections/cio-outdoor-living to the path in the sandbox

Definition of Done

  • Fix the behavior such that click on the product swatches doesn't redirect

  • Add documentation in swatch handler hooks to enable customers to utilise

@evanyan13 evanyan13 self-assigned this Apr 18, 2025
@evanyan13 evanyan13 requested a review from a team as a code owner April 18, 2025 18:24
Copy link
Contributor

@Mudaafi Mudaafi 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! I had one more comment in our internal thread on whether we'd want to prevent default on the entire swatch container as well but lets see what the others think

@evanyan13 evanyan13 requested a review from Mudaafi April 22, 2025 22:16
Copy link
Contributor

@Mudaafi Mudaafi left a comment

Choose a reason for hiding this comment

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

looking good, it works as expected. Let's get another review in first just in case we missed something.


// Prevents link navigation
const swatchContainerClickHandler = (e: React.MouseEvent) => {
e.stopPropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this? I think e.preventDefault is sufficient right?

})
) : (
<div>
<div onClick={swatchContainerClickHandler} role='button' tabIndex={0}>
Copy link
Contributor

@Mudaafi Mudaafi Apr 22, 2025

Choose a reason for hiding this comment

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

I don't think we'd want this. This is neither a button nor should be navigatable-to using tabs since it's just a container. All we want to do is to prevent clicking into this space to trigger a redirect/click event so throwing a

// eslint-disable-next-line jsx-a11y/no-static-element-interactions

might be more advisable here. Calling our resident a11y expert @mocca102 for his thoughts.

Copy link
Contributor

@esezen esezen left a comment

Choose a reason for hiding this comment

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

LGTM!

@evanyan13 evanyan13 merged commit d97466f into main Apr 24, 2025
10 of 11 checks passed
@evanyan13 evanyan13 deleted the ci-4381-os-plp-ui-fix-clicking-on-swatches-directing-to-pdp branch April 24, 2025 16:11
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.

4 participants