fix: Fix search input appearance

pull/713/head
Maksim Eltyshev 2 years ago committed by Emmanuel Guyot
parent d44b5a689a
commit 6251b0a08a

@ -1,6 +1,8 @@
import React, { useCallback, useEffect, useRef } from 'react'; import React, { useCallback, useRef, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { Icon } from 'semantic-ui-react';
import { usePopup } from '../../lib/popup'; import { usePopup } from '../../lib/popup';
import { Input } from '../../lib/custom-ui'; import { Input } from '../../lib/custom-ui';
@ -30,7 +32,14 @@ const Filters = React.memo(
onTextFilterUpdate, onTextFilterUpdate,
}) => { }) => {
const [t] = useTranslation(); const [t] = useTranslation();
const searchField = useRef(null); const [isSearchFocused, setIsSearchFocused] = useState(false);
const searchFieldRef = useRef(null);
const cancelSearch = useCallback(() => {
onTextFilterUpdate('');
searchFieldRef.current.blur();
}, [onTextFilterUpdate]);
const handleRemoveUserClick = useCallback( const handleRemoveUserClick = useCallback(
(id) => { (id) => {
@ -46,17 +55,39 @@ const Filters = React.memo(
[onLabelRemove], [onLabelRemove],
); );
const handleKeyUp = useCallback(() => { const handleSearchChange = useCallback(
onTextFilterUpdate(searchField.current.inputRef.current.value); (_, { value }) => {
}, [onTextFilterUpdate]); onTextFilterUpdate(value);
},
[onTextFilterUpdate],
);
useEffect(() => { const handleSearchFocus = useCallback(() => {
searchField.current.inputRef.current.value = filterText; setIsSearchFocused(true);
}, [filterText]); }, []);
const handleSearchKeyDown = useCallback(
(event) => {
if (event.key === 'Escape') {
cancelSearch();
}
},
[cancelSearch],
);
const handleSearchBlur = useCallback(() => {
setIsSearchFocused(false);
}, []);
const handleCancelSearchClick = useCallback(() => {
cancelSearch();
}, [cancelSearch]);
const BoardMembershipsPopup = usePopup(BoardMembershipsStep); const BoardMembershipsPopup = usePopup(BoardMembershipsStep);
const LabelsPopup = usePopup(LabelsStep); const LabelsPopup = usePopup(LabelsStep);
const isSearchActive = filterText || isSearchFocused;
return ( return (
<> <>
<span className={styles.filter}> <span className={styles.filter}>
@ -114,10 +145,21 @@ const Filters = React.memo(
</span> </span>
<span className={styles.filter}> <span className={styles.filter}>
<Input <Input
ref={searchField} ref={searchFieldRef}
value={filterText}
placeholder={t('common.searchCards')} placeholder={t('common.searchCards')}
icon="search" icon={
onKeyUp={() => handleKeyUp()} isSearchActive ? (
<Icon link name="cancel" onClick={handleCancelSearchClick} />
) : (
'search'
)
}
className={classNames(styles.search, !isSearchActive && styles.searchInactive)}
onFocus={handleSearchFocus}
onKeyDown={handleSearchKeyDown}
onChange={handleSearchChange}
onBlur={handleSearchBlur}
/> />
</span> </span>
</> </>

@ -43,4 +43,32 @@
line-height: 20px; line-height: 20px;
padding: 2px 12px; padding: 2px 12px;
} }
.search {
height: 30px;
margin: 0 12px;
transition: width 0.2s ease;
width: 280px;
input {
font-size: 13px;
}
}
.searchInactive {
color: #fff;
height: 24px;
width: 220px;
input {
background: rgba(0, 0, 0, 0.24);
border: none;
color: #fff !important;
font-size: 12px;
&::placeholder {
color: #fff;
}
}
}
} }

@ -9,4 +9,6 @@ export default class Input extends SemanticUIInput {
static Mask = InputMask; static Mask = InputMask;
focus = (options) => this.inputRef.current.focus(options); focus = (options) => this.inputRef.current.focus(options);
blur = () => this.inputRef.current.blur();
} }

Loading…
Cancel
Save