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

Instant Search: prototype instant search filters overlay #14320

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/search/class.jetpack-search-template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ public static function render_widget_search_form( $post_types, $orderby, $order

$form = self::inject_hidden_form_fields( $form, $fields_to_inject );

// Temporarily add some dummy filters to demonstrate filter behaviour.
$form .= '<div class="jetpack-search-form__test-filters" style="margin-top: 20px">' .
'<h3>Post type</h3>' .
'<div><input type="checkbox" id="jetpack-search-form__test-filter-1" class="jetpack-search-form__test-filter-checkbox">' .
'<label for="jetpack-search-form__test-filter-1" class="jetpack-search-form__test-filter-label">Post</label></div>' .
'<div><input type="checkbox" id="jetpack-search-form__test-filter-2" class="jetpack-search-form__test-filter-checkbox">' .
'<label for="jetpack-search-form__test-filter-2" class="jetpack-search-form__test-filter-label">Page</label></div>' .
'</div>';

$form .= '<div class="jetpack-search-form__test-filters" style="margin-top: 20px">' .
'<h3>Year</h3>' .
'<div><input type="checkbox" id="jetpack-search-form__test-filter-3" class="jetpack-search-form__test-filter-checkbox">' .
'<label for="jetpack-search-form__test-filter-3" class="jetpack-search-form__test-filter-label">2020</label></div>' .
'<div><input type="checkbox" id="jetpack-search-form__test-filter-4" class="jetpack-search-form__test-filter-checkbox">' .
'<label for="jetpack-search-form__test-filter-4" class="jetpack-search-form__test-filter-label">2019</label></div></div>';

echo '<div class="jetpack-search-form">';
echo $form;
echo '</div>';
Expand Down
3 changes: 2 additions & 1 deletion modules/search/instant-search/components/overlay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
overflow-y: auto;
overflow-x: hidden;
z-index: 9999999999999;
animation-fill-mode: forwards;

&.is-hidden {
transform: translateY( -100vh );
transform: translateX( 100vw );
}
}

Expand Down
12 changes: 12 additions & 0 deletions modules/search/instant-search/components/search-app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class SearchApp extends Component {
document.querySelectorAll( this.props.themeOptions.searchSortSelector ).forEach( select => {
select.addEventListener( 'change', this.handleSortChange );
} );

document.querySelectorAll( this.props.themeOptions.filterInputSelector ).forEach( element => {
element.addEventListener( 'click', this.handleFilterInputClick );
} );
}

removeEventListeners() {
Expand All @@ -87,6 +91,10 @@ class SearchApp extends Component {
document.querySelectorAll( this.props.themeOptions.searchSortSelector ).forEach( select => {
select.removeEventListener( 'change', this.handleSortChange );
} );

document.querySelectorAll( this.props.themeOptions.filterInputSelector ).forEach( element => {
element.removeEventListener( 'click', this.handleFilterInputClick );
} );
}

hasActiveQuery() {
Expand All @@ -110,6 +118,10 @@ class SearchApp extends Component {
setSortQuery( getSortKeyFromSortOption( event.target.value ) );
};

handleFilterInputClick = () => {
this.showResults();
};

showResults = () => this.setState( { showResults: true } );
hideResults = () => this.setState( { showResults: false } );

Expand Down
10 changes: 10 additions & 0 deletions modules/search/instant-search/instant-search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ $grid-size-large: 16px;
.jetpack-instant-search__is-loading {
opacity: 0.2;
}

// Temporary test styles
.jetpack-search-form__test-filter-checkbox {
display: none;
}

.jetpack-search-form__test-filter-label:hover {
text-decoration: underline;
cursor: pointer;
}
4 changes: 4 additions & 0 deletions modules/search/instant-search/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function getThemeOptions( searchOptions ) {
'.jetpack-instant-search-wrapper input.search-field',
].join( ', ' ),
searchSortSelector: [ '.jetpack-search-sort' ],
filterInputSelector: [
'.jetpack-search-form__test-filter-checkbox',
'.jetpack-search-form__test-filter-label',
],
};
return searchOptions.theme_options ? { ...options, ...searchOptions.theme_options } : options;
}