Skip to content

Commit

Permalink
Merge pull request #1525 from XiaoMi/feature/#1522
Browse files Browse the repository at this point in the history
feat: #1522
  • Loading branch information
GleanCoder1116 authored Jan 18, 2021
2 parents f55a13e + 8f74d89 commit 2b7ad1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ const InternalSelect = (props) => {
searchPlaceholder={searchPlaceholder}
theme={theme}
onFocus={onFocus}
isOnSearch={dataSource}
isByRemoteSearch={dataSource}
isByCustomSearch={onSearch}
onSearch={debouncedFilterItems}
searchable={searchable}
showCheckAll={showCheckAll}
Expand Down
14 changes: 8 additions & 6 deletions components/select/SelectDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const SelectDropdown = ({
dropdownItems,
localeMap,
onSearch,
isOnSearch,
isByRemoteSearch,
isByCustomSearch,
onClickOption,
checkAll,
selectInputWidth,
Expand Down Expand Up @@ -104,7 +105,7 @@ const SelectDropdown = ({
useEffect(() => {
const _filterItems = dropdownItems
setFilterItems(_filterItems)
}, [mode, isOnSearch, dropdownItems, show])
}, [mode, isByRemoteSearch, dropdownItems, show])

let matched = 0
const style = optionWidth && {
Expand Down Expand Up @@ -150,6 +151,7 @@ const SelectDropdown = ({
(e, item, index) => {
e.stopPropagation()
e.preventDefault()
setFocusedIndex(index)
if (item[transKeys(fieldNames, 'disabled')]) {
return
}
Expand Down Expand Up @@ -208,15 +210,15 @@ const SelectDropdown = ({
disabled={item[transKeys(fieldNames, 'disabled')]}
>
<div className="hi-select__dropdown--item__name" style={style}>
{isOnSearch
{isByRemoteSearch
? item[transKeys(fieldNames, 'title')]
: hightlightKeyword(item[transKeys(fieldNames, 'title')], item[transKeys(fieldNames, 'id')])}
</div>
</Checkbox>
)}
{mode === 'single' && (
<div className="hi-select__dropdown--item__name" style={style}>
{isOnSearch
{isByRemoteSearch
? item[transKeys(fieldNames, 'title')]
: hightlightKeyword(item[transKeys(fieldNames, 'title')], item[transKeys(fieldNames, 'id')])}
</div>
Expand Down Expand Up @@ -251,7 +253,7 @@ const SelectDropdown = ({
'is-active': isSelected,
'is-disabled': isDisabled,
'hi-select__dropdown--item--child': isChildItem,
'is-focus': filterItemsIndex === focusedIndex,
'is-focus': targetByKeyDown.current && filterItemsIndex === focusedIndex,
'hi-select__dropdown--item-default': !item[transKeys(fieldNames, 'children')] && !dropdownRender
})}
onClick={(e) => onClickOptionIntal(e, item, _filterItemsIndex)}
Expand Down Expand Up @@ -298,7 +300,7 @@ const SelectDropdown = ({
}
return (
<div className="hi-select__dropdown" style={style}>
{searchable && (
{(searchable || isByCustomSearch) && (
<div className="hi-select__dropdown__searchbar">
<div className="hi-select__dropdown__searchbar--content">
<span style={{ cursor: 'pointer' }}>
Expand Down
4 changes: 4 additions & 0 deletions components/select/style/select-dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
}

&.is-focus {
background-color: use-color('primary-10');
}

&:hover {
background-color: use-color('primary-20');
}

Expand Down

0 comments on commit 2b7ad1f

Please sign in to comment.