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
New block: Query filter #441
Conversation
/> | ||
<input | ||
type="submit" | ||
value="<?php esc_html_e( 'Apply', 'wporg' ); ?>" |
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.
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've been only referencing the "filters 6.1" page in the Filter component file, thinking that was the final version 🙃
The link doesn't work for me (opens the file but wrong page)… but I found it by searching through the other pages, so thanks for pointing it out.
@WordPress/meta-design — Can you confirm how this should behave? It sounds like the top number (on black, red highlight) would be the number of filters currently applied on the page, while the Apply button (on blue, yellow highlight) would be the number of filters currently selected— so it would stay "Popular tags 1" even if you select two more, but the button would be "Apply (3)"?
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 sounds like the top number (on black, red highlight) would be the number of filters currently applied on the page, while the Apply button (on blue, yellow highlight) would be the number of filters currently selected— so it would stay "Popular tags 1" even if you select two more, but the button would be "Apply (3)"?
Correct, but honestly I think we can remove the number on the Apply button for now, I'm not sure it adds clarity. If Francisco when he comes back from AFK has to correct me, I will buy him an apology milkshake at that time. How does this sound?
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 was an accessibility request, but maybe it would be easier to understand the UX once this is merged and live on the staging site. I'll leave this as-is (no number on button) for this initial pass, and ask for feedback once there's a live place to try it out.
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 tested it locally, and while I don't yet have the expertise to review the interactivity implementation, it does work well and updates the query string appropriately. 👍 |
|
||
&.wporg-query-filter__modal-action-clear { | ||
background-color: transparent; | ||
color: #a13f2a; /* pomegrade-1 fails contrast against white. */ |
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.
@WordPress/meta-design I meant to flag this in the description— the mockup uses "Pomegrade" on white but that fails to meet contrast requirements. There's a note in the design library about darker versions of colors, but I didn't see any, so I've made this one up. If you'd rather something different, it just needs to have a 4.5+ value against light-grey-2, since I'm using that as the hover color.
…d without applying
This was added to support the "click outside to close" behavior, but that can glitch when the click target is not a focusable element — clicking the space between buttons in the actions bar would close the dropdown. So the hasHover check was added to prevent that, but that brought in new glitches, where the focus could be reset to the first focusable element if hover was changed. This PR removes all that in favor of using the backdrop element as a click target.
This also adds a new label "title" which is used on the small screen modal too.
c79d373
to
350a8cb
Compare
See #419 — this adds a new block called "Query Filter", which renders a dropdown form using values passed in via filter. When "Apply" is clicked, the form is submitted, and the resulting URL is expected to handle the applied filters. In many cases, wp_query can handle combined filters without any customization (ex, taxonomies). For non-core filters, hooking into
pre_get_posts
(+ maybequery_vars
?) in the child theme should be enough.This block is using the Interactivity API, which uses
data-wp-
attributes to attach events and conditional attributes. This API is still experimental, but I took a lot of inspiration from the navigation block.By itself, this block doesn't render anything. It expects a
key
attribute, which is used to create a specific filter for the individual sites to populate a settings object. For example, the following would be used to create an "example" filter.This creates the WP filter hook
wporg_query_filter_options_example
, which expects an object used to render the options. There's more documentation inline in render.php.To create a simple dropdown with 3 options:
The output would look like this:
When "Apply" is clicked, the page loads
/?q[]=opt-2
. It's up to each site to load the correct archive.❓ I think this approach will work well for the child theme setup, but I definitely want feedback on it before committing us all to this for all the directories 🙂
🖌️ I've also used block-specific custom properties so that other themes can easily change colors with
theme.json
changes (here's an example in showcase, though i removed it once everything was set up since the defaults work). This is in case the theme directory needs a dark scheme.Practical example: Showcase
I've got this working with real filters in WordPress/wporg-showcase-2022#147 — here are some screen recordings of everything in place:
A basic filtering, starting on the homepage, shows all 3 filters & options. When a filter is applied, the results load using the archive template.
basic-demo.mp4
More filtering interactions — clearing filters using "Clear" and by clicking the option; applying multiple filters, clicking out before applying.
more-demo.mp4
Search and filters can work together — once on a search results page, filtering will filter the search results. (the opposite is not true, if you search on a filtered page it will remove the filters, we talked through that and it was expected behavior)
search-demo.mp4
When clicking on a tag archive page, the filter for that tag is correctly selected.
tag-demo.mp4
And on mobile, the dropdown switches to a modal