Skip to content

Commit

Permalink
fix(SearchBar): support clear value (#1659)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhang Rui <zhangrui@growingio.com>
  • Loading branch information
Ryan Zhang and Zhang Rui committed Dec 9, 2021
1 parent 21b4cf3 commit 2caee20
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/search-bar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CloseCircleFilled, SearchOutlined } from '@gio-design/icons';
import { usePrefixCls } from '@gio-design/utils';
import classNames from 'classnames';
import React, { useCallback, useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState, useEffect } from 'react';
import Input from '../input/Input';
import { SearchBarProps } from './interface';

Expand All @@ -28,6 +28,12 @@ const SearchBar = React.forwardRef<HTMLInputElement, SearchBarProps>((props, ref
}
}, [onSearch, disabled]);

useEffect(() => {
if (value !== enterValue) {
setValue(enterValue);
}
}, [enterValue, value]);

const suffixCls = useMemo(
() =>
classNames(`${prefixCls}__suffix`, {
Expand Down

1 comment on commit 2caee20

@vercel
Copy link

@vercel vercel bot commented on 2caee20 Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.