-
Notifications
You must be signed in to change notification settings - Fork 219
Product Categories List: Update dropdown view #647
Conversation
@jwold Looks like I can't request a review from you until you accept the invite to WooCommerce? In any case, this is the PR I mentioned earlier, where I had to deviate from the design for accessibility reasons. Would like your input on the button solution 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great improvement for the Product Categories List block. I tested it and everything works fine and code looks good. I added a couple of questions in the code below but pre-approving pending for @jwold's input.
Since both of those approaches have downsides, I decided to follow the "best practice" outlined here: use a button to trigger the navigation. A button also makes it clear that this is a navigation action, which might not be as clear with the dropdown alone.
Agree this is the best solution. 👍
</div> | ||
); | ||
}; | ||
if ( ! isPreview && 0 === url.indexOf( home ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case that 0 === url.indexOf( home )
will evaluate to false? I'm unable to see it and I'm curious now. 🙃
If there is, what do you think about rewriting this check as:
if ( ! isPreview && 0 === url.indexOf( home ) ) { | |
if ( ! isPreview && url.startsWith( home ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE doesn't support string.startsWith
. Why do you think we'd need to rewrite it? This check is make sure all links are internal, so url
should always start with home
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE doesn't support string.startsWith.
I thought transpiling the code with Babel would take care of IE11 compatibility, am I missing something? When testing it, I see strings get the startsWith
method and it works just fine even in IE11:
Why do you think we'd need to rewrite it?
There is no need to change it, indexOf
works too. It was just that I usually prefer ES6 methods because I think they make code easier to read for newcomers, but it's just a question of taste. 🙂
This check is make sure all links are internal, so url should always start with home.
Right, I was curious if there is any case in which a category link could be external.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, I was just going on with what MDN said in its support matrix, and made the assumption since it didn't add forEach to NodeList that it wouldn't do this either 🤷🏼♀️
if there is any case in which a category link could be external.
I don't think that's possible, since we're linking off to WP-created taxonomy archives. I suppose a plugin could interject and do anything it wanted, but that seems like it would be really edge case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, this works great.
The only issue I see is the button does nothing (no feedback) when a category is not selected. I can think of 2 solutions for this which avoid modals;
- Don't show the empty "select a category" value and just have the top most (or current, thinking ahead to when this may be used in a widget area) by default
- Make the default state of the navigation button disabled with a modified title with instructions to select a cat.
or something else :)?
2e30298
to
cfe1f3d
Compare
I don't think this a problem– if you haven't selected a category, there is no page to navigate to, so the button doesn't go anywhere. This seems like expected behavior to me. |
@ryelle good catch on the accessibility front. I'm good with moving this forward! Thanks :) I do have two things I'd like to understand more of (apart from this PR):
|
The issue is triggering an action when the select box changes. So a dropdown in the context of a form, like picking a state on a shipping form should be fine. If the form changes based on that selection, it would probably depend on how disruptive it would be to have the form change as someone is scanning through the options. In this case, it triggers a page navigation, so that's as disruptive as you can be - so we move the trigger off to a button. I know most designers hate to get WCAG citations, but this one falls under "3.2.5 Changes of context are initiated only by user request or a mechanism is available to turn off such changes." – it's a level AAA requirement, so we don't need to match it (best practice is to match level A and level AA). I think we can be a little more discerning about it (judging based on the impact to the user, rather than "always do XYZ").
Nope, I just wanted something that would be clear– the caret/ |
I don't mind the citation at all actually! I take it as an opportunity to learn something new. Thanks for that explanation. I do appreciate the distinction between it being a AAA, but also that makes such a disruptive change that it could be argued it warrants a button to trigger the change more so than something smaller. |
This PR updates the Product Categories List block, dropdown view. It adds the hierarchy support back in, and enables navigation using the dropdown.
Accessibility
Note: I've had to add a button to trigger the navigation. The other options are
onBlur
oronChange
on theselect
element. Both have issues–onBlur
works better using a keyboard, you can select a category and the navigation triggers once you leave the element; but for a mouse user you need to click away from the select box and only then will it navigate.onChange
works as expected for a mouse user, but on some browsers (IE11 is what I tested) any keyboard nav just scanning through the select options triggers the navigation, so it will always nav to the first item, never letting you get through the options.Since both of those approaches have downsides, I decided to follow the "best practice" outlined here: use a button to trigger the navigation. A button also makes it clear that this is a navigation action, which might not be as clear with the dropdown alone.
Screenshots
In the editor, you see the dropdown preview + button, but clicking the button won't navigate.
You can open the dropdown, which helps you see the preview when, for example, hierarchy and product counts are enabled.
On the front end, it looks pretty much the same.
If you select a category, you can click the button now to navigate to that archive.
How to test the changes in this Pull Request: