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

Add clear button to list filter search input #1845

Merged
merged 5 commits into from
Oct 15, 2021
Merged
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
1 change: 1 addition & 0 deletions ui/v2.5/src/components/Changelog/versions/v0110.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added interface options to disable creating performers/studios/tags from dropdown selectors. ([#1814](https://github.com/stashapp/stash/pull/1814))

### 🎨 Improvements
* Added clear button to query text field. ([#1845](https://github.com/stashapp/stash/pull/1845))
* Moved Performer rating stars from details/edit tabs to heading section of performer page. ([#1844](https://github.com/stashapp/stash/pull/1844))
* Optimised scanning process. ([#1816](https://github.com/stashapp/stash/pull/1816))

Expand Down
24 changes: 23 additions & 1 deletion ui/v2.5/src/components/List/ListFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _, { debounce } from "lodash";
import React, { HTMLAttributes, useEffect, useRef, useState } from "react";
import cx from "classnames";
import Mousetrap from "mousetrap";
import { SortDirectionEnum } from "src/core/generated-graphql";
import {
Expand Down Expand Up @@ -44,6 +45,9 @@ export const ListFilter: React.FC<IListFilterProps> = ({
}) => {
const [customPageSizeShowing, setCustomPageSizeShowing] = useState(false);
const [queryRef, setQueryFocus] = useFocus();
const [queryClearShowing, setQueryClearShowing] = useState(
!!filter.searchTerm
);
const perPageSelect = useRef(null);
const [perPageInput, perPageFocus] = useFocus();

Expand Down Expand Up @@ -99,6 +103,14 @@ export const ListFilter: React.FC<IListFilterProps> = ({

function onChangeQuery(event: React.FormEvent<HTMLInputElement>) {
searchCallback(event.currentTarget.value);
setQueryClearShowing(!!event.currentTarget.value);
}

function onClearQuery() {
queryRef.current.value = "";
searchCallback("");
setQueryFocus();
setQueryClearShowing(false);
}

function onChangeSortDirection() {
Expand Down Expand Up @@ -217,7 +229,17 @@ export const ListFilter: React.FC<IListFilterProps> = ({
onInput={onChangeQuery}
className="query-text-field bg-secondary text-white border-secondary"
/>

<Button
variant="secondary"
onClick={onClearQuery}
title={intl.formatMessage({ id: "actions.clear" })}
className={cx(
"query-text-field-clear",
queryClearShowing ? "" : "d-none"
)}
>
<Icon icon="times" />
</Button>
<InputGroup.Append>
<OverlayTrigger
placement="top"
Expand Down
21 changes: 21 additions & 0 deletions ui/v2.5/src/components/List/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ input[type="range"].zoom-slider {
width: 50%;
}

.query-text-field-clear {
background-color: $secondary;
color: $text-muted;
font-size: $btn-font-size-sm;
margin: $btn-padding-y $btn-padding-x;
padding: 0;
position: absolute;
right: 3em;
z-index: 4;

&:hover,
&:focus,
&:active,
&:not(:disabled):not(.disabled):active,
&:not(:disabled):not(.disabled):active:focus {
background-color: $secondary;
border-color: transparent;
box-shadow: none;
}
}

.saved-filter-list-menu {
width: 300px;

Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"backup": "Backup",
"cancel": "Cancel",
"clean": "Clean",
"clear": "Clear",
"clear_back_image": "Clear back image",
"clear_front_image": "Clear front image",
"clear_image": "Clear Image",
Expand Down