-
Notifications
You must be signed in to change notification settings - Fork 63
Fix filter display wrapping and clean up tests #319
Conversation
$t('filters.filter-by') | ||
}}</span> | ||
<div class="flex flex-wrap items-center p-4" aria-live="polite"> | ||
<span v-if="isAnyFilterApplied" class="mr-2 font-semibold"> |
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.
<span v-if="isAnyFilterApplied" class="mr-2 font-semibold"> | |
<span v-if="isAnyFilterApplied" class="mr-2 mb-2 font-semibold"> |
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.
mb-2
makes the 'Filter by' span aligned with the tags.
src/components/Filters/FilterTag.vue
Outdated
@@ -1,6 +1,6 @@ | |||
<template> | |||
<button | |||
class="filter-block button tiny tag mx-1" | |||
class="filter-block button tiny tag mx-1 mb-2" |
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.
It might be better to move the margin declarations to the top: <FilterTag class="mx-1 mb-2 />
so that the layout is handled by the parent component.
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.
Looks and works great! I've added a couple of non-blocking comments inline.
@obulat Thanks for the review. I made the changes you suggested... and then went down a rabbit hole to fix the |
src/components/Filters/FilterTag.vue
Outdated
@@ -1,17 +1,18 @@ | |||
<template> | |||
<button | |||
class="filter-block button tiny tag mx-1" | |||
<div |
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.
I think it would be better for user experience to keep it a button
, and add the onClick handlers for button as a whole, not just the cross
span. I've tried to look for examples of dismissible tags, and only Walmart came to mind: their tags can be dismissed by clicking anywhere in the button, not just the cross
icon. It might also be bad user experience for people with big hands on mobiles who cannot click on such a small target.
By the way, I've also tried removing the @keyup.enter
handler from the button, leaving only the @click
one, and it still works, because the browser understand Enter or Space presses while the focus is on the button as button clicks. But I'm still not 100% sure it's a good idea to remove the Enter handling ...
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.
Okay! That makes sense to me. I changed it because the click handler was only on the span, which wasn't accessibile. But if we make the whole thing a dismiss button then that fixes it. Also easier to click the whole thing rather than just the cross.
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.
hmmm, one wrinkle... I'm not sure how to communicate to screen readers that the button is a close button. I'll have to do some digging.
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.
Okay in 7d8952b I updated it so the whole tag is a close button with an accessible label.
VoiceOver on macOS and NVDA both only read the aria label on a button when it exists, so we need to include the type of filter in the label or else the screen reader just reads "Remove filter" with no extra context about which filter would be removed.
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.
Thank you for updating the tests! I am also uneasy about using snapshot tests, because they've previously broke so many times for me, and failed me even when the linters updated the .snap
line spacing...
Yeah... I really only used them because the existing tests were just as brittle and required manual updating and were testing irrelevant implementation details... so somehow even snapshot tests are better I think 😂 |
352fa6b
to
7d8952b
Compare
Fixes
Fixes #269 by @zackkrida
Description
Fixes the active filter display by making them flex wrap. Also converts it to tailwind for the most part except for the
button
andtiny
classnames which I assume we'll get rid of when we do the full redesign anyway.Also removes all the existing tests for the
FilterDisplay
component in favor of a single snapshot tests.I don't love snapshot tests, but in this case the tests that existed there previously either (a) didn't actually do anything (in particular the "checked" test was completely useless) or (b) were manual snapshot tests, directly testing the markup. So I just replaced it with a single snapshot test that at least verifies that the component renders as expected and requires updating if anything changes.
It's probably, ultimately, a fragile snapshot test, but I'd personally like to see this component refactored in a number of ways to make it more testable and simpler. For one, we could split it into a container and display component. The container would connect to the store and the display would taking things as normal props. It would massively simplify the tests against the display component because we could just use normal props instead of having to mock out a whole store and getters and stuff.
In any case, that's a project for another day. I think the current set up makes the most sense from a perspective of (a) preserving what testing was already being done while (b) removing tests that weren't actually doing anything.
Testing Instructions
Checkout the branch and run
npm run dev
. Then perform a search and activate enough filters to cause the active filters list to wrap and verify that it looks okay.Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin