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

Snippetize header menu components #2401

Merged
merged 6 commits into from
Mar 24, 2023
Merged

Snippetize header menu components #2401

merged 6 commits into from
Mar 24, 2023

Conversation

kmeleta
Copy link
Contributor

@kmeleta kmeleta commented Mar 14, 2023

PR Summary:

Why are these changes introduced?

Improves developer ergonomics around the header by splitting some related components into their own snippets.

What approach did you take?

I split the respective code for all 3 of the menu types into their own snippets. I also captured the search modal markup into a snippet since this code is fairly verbose and also duplicated in header.liquid. The search modal needs to avoid duplicate ids so I took the same approach we used in the product-media-gallery snippet for that. Otherwise, no code has been changed in any of these components.

Other considerations

It would be great if any of the redundant nested lists used in the menus could be consolidated but I don't make an attempt to consider or implement any changes for that here.

Testing steps/scenarios

This should be a low risk change but we should ensure everything works exactly as it did before.

  • Test all 3 header menu types for regressions (mobile and desktop)
  • Test using several logo positions
  • Test predictive search for regressions (particularly using top-center logo position)

Demo links

Checklist

@kmeleta kmeleta marked this pull request as ready for review March 15, 2023 16:26
@kmeleta kmeleta added the Category: Tech Debt Opportunities to refactor or improve the code and/or development workflow label Mar 15, 2023
Copy link
Contributor

@ludoboludo ludoboludo 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 👍 Just a couple nitpicks

ludoboludo
ludoboludo previously approved these changes Mar 16, 2023
Copy link
Contributor

@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

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

👍

@kmeleta
Copy link
Contributor Author

kmeleta commented Mar 22, 2023

Resolved minor conflicts from #2238. Wasn't bad, but probably double check nothing got mixed up.

metamoni
metamoni previously approved these changes Mar 23, 2023
Copy link
Contributor

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

ludoboludo
ludoboludo previously approved these changes Mar 23, 2023
stufreen
stufreen previously approved these changes Mar 23, 2023
Copy link
Contributor

@stufreen stufreen 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 with one question

Renders a header search modal. Should be used with 'header.liquid'

Accepts:
- is_duplicate: {Boolean} Prevents duplicate ids for subsequent instances
Copy link
Contributor

@stufreen stufreen Mar 23, 2023

Choose a reason for hiding this comment

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

It took me a second to understand what this was doing. What do you think about something more transparent like search_input_id: {String} or append_id: {String}? That will also let you have 3+ if you really wanted.

What's the search input ID used for anyhow, just the label?

Copy link
Contributor Author

@kmeleta kmeleta Mar 23, 2023

Choose a reason for hiding this comment

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

It's likely only used for the label. I went back and forth on the first snippet that needed a duplicate like this. I originally did use append_id so if you feel strongly I'm happy to do that. I added a brief decision log entry in that PR that calls out that option. But my reasons were..

  • Adequate and a simpler api to use more of a boolean approach.
  • Nothing depends on our snippet apis so we can start simpler and update it anytime if needed.
  • It's not necessarily meant to take the place of an "id" prop to support multiple instances in any number of sections or blocks, it represents a specific use where we're having to render one "instance" twice specifically to maintain proper dom order for a mobile and desktop layout.
  • I would hope we can avoid needing 3 rendered search instances in the header.

Going further with it though, there could certainly be a case made for abstracting only the combobox portion out of the current header-search snippet instead and reusing that in the main-search. In such a case, we would definitely want to allow a fully custom id to be passed through to it. Any thoughts on that? I was motivated more to reduce noise in the header more than anything here, but technically if we were limiting ourselves to only one layer of abstraction (because this is liquid) I could see that be the more logical choice.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel that strongly either way but is_duplicate just seems a little obscure. I didn't know what the param did until I searched the code to see where it was used. I'll leave it to you but input_id would be more obvious to me I think -- I'd assume it was an id getting passed on.

I wonder if we even need the id and for attributes if we could achieve the same thing by having the label as the parent of the input? Probably OOS here though.

Copy link
Contributor Author

@kmeleta kmeleta Mar 23, 2023

Choose a reason for hiding this comment

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

I'm not sure if my point was received, but this instance definitely doesn't make as strong of a case for that prop pattern as the other snippet I was matching so I decided to adjust as you suggest.

I wonder if we even need the id and for attributes if we could achieve the same thing by having the label as the parent of the input?

Well I definitely don't want to refactor every input in dawn to avoid a naming discussion regardless haha, but I imagine a major reason we chose the label for input pattern is so the label could access the :focus context of the input element in css (input:focus ~ label). Off hand I'm not aware of every detail considered in original decision, but I'm sure it wasn't made by accident or with ignorance to the label parent option.

@kmeleta kmeleta dismissed stale reviews from stufreen, ludoboludo, and metamoni via 0fb43d2 March 23, 2023 20:34
@kmeleta kmeleta requested a review from stufreen March 23, 2023 20:45
@kmeleta kmeleta merged commit c8928aa into main Mar 24, 2023
@kmeleta kmeleta deleted the header-snippets branch March 24, 2023 20:33
pangloss added a commit to pangloss/dawn that referenced this pull request Mar 26, 2023
* shopify/main:
  Snippetize header menu components (Shopify#2401)
  Release bump shadow fix (Shopify#2469)
  Update 1 translation file (Shopify#2459)
  [Product Cards] Add image masks (Shopify#2302)
  [Feature] reveal on scroll animations (Shopify#2367)
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
* Split out drawer, dropdown, megamenu, and search

* Clean up

* Formatting

* Snippet docs edit

* Formatting again

* Change prop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Tech Debt Opportunities to refactor or improve the code and/or development workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants