feat(examples): render variation options as swatches from the child product - #651
Merged
Merged
Conversation
…roduct A variation option on the product page and on a search card now shows as a colour dot or as a picture of the product it leads to, read from the child product through the parent's variation_matrix. Elastic Path has no variation type, so the data decides: the child's shopper_attributes.color for a dot, its own main image for a picture, and text otherwise. A kind applies to a variation only when it differs along it, so sizes sharing one photo stay text. Both surfaces share one radio-based renderer. The product page moves from buttons to radios, gaining arrow keys and a single tab stop, and keeps focus on the chosen option across the variant navigation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #531.
What changed
A variation option in
examples/corecan now render as a colour dot or a picture of the product. Otherwise it renders as text, as before. The product page and the search cards share one renderer,VariationOptions, so the two surfaces cannot drift.Why it is built from the child product, not from a variation type
#531 assumed Elastic Path has a variation type. It does not:
catalog_view.yamlandpim.yaml, a variation has onlyid,name,sort_orderandoptions. An option has onlyid,name,sort_orderanddescription.Option{ID, Name, Description, SortOrder, Modifiers}, and no modifier sets a colour or an image.Branching on a variation called "Colour" would be a string heuristic. Elastic Path models variant-specific data on the child product instead. A child keeps its own main image, and its own
shopper_attributeskeys, through a rebuild of child products. So each option follows the parent'svariation_matrixto its child product, holding the shopper's other choices fixed, and reads one of these, in order:shopper_attributes.color, if it is#rgbor#rrggbb: a colour dot, set with an inlinestyle;A kind applies to a variation only when it differs along that variation. Sizes that share one photo stay as text. A colour inherited from the parent shows nowhere. The README states exactly what the store must hold.
Both surfaces already load the child products with their main images, so this adds no new requests.
Behaviour
<button>s to radio inputs. The page gains arrow keys and a single tab stop per variation, and its variation heading becomes the group's<legend>. Text options look as they did.Verified live (integration store,
next start):focus-visiblepersist across the navigation.vitest run(182 tests),tsc --noEmitandnext buildpass inexamples/core.Not covered, or left as is
shopper_attributes.color.Screenshots
1. Product page: image swatches beside unchanged text
Material's children have different images, so they get thumbnails. Sandle's sizes share one photo, so they keep today's text buttons.
2. Choosing an option changes the product
Chrome selected: the URL, main image and carousel move to the Chrome child, and the legend names the choice. The Material children have no price on this store, so Sandle shows the price change through the same control.
3. Keyboard only
Tab reaches the group, and the arrow keys moved Chrome → Plastic → Chrome. The blue focus outline and the dark selected ring are both visible after each navigation.
4. Search card
Before: thumbnails beside a text Size variation, and the card isn't selectable yet. After choosing Chrome: the card image and link move to the child, and the bulk-select checkbox is enabled.
5. No usable swatch data falls back to text
Multi Variation's children have neither images nor colours.
6. Phone width
Product page and search card at 375 px, with no horizontal overflow.