-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add searchable dropdown for skills filtering
- Loading branch information
1 parent
9a5e351
commit f57f57d
Showing
12 changed files
with
243 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Input } from '@edx/paragon'; | ||
import debounce from 'lodash.debounce'; | ||
import FacetDropdown from './FacetDropdown'; | ||
|
||
const TypeaheadFacetDropdown = ({ | ||
title, | ||
items, | ||
isBold, | ||
options, | ||
searchForItems, | ||
}) => { | ||
const handleSearch = debounce((value) => { | ||
// when user is erasing the input and input is empty we need to reset the filtering | ||
if (value.length >= options.minLength || value.length === 0) { | ||
searchForItems(value); | ||
} | ||
}, 200); | ||
|
||
const transformMenuOptions = menuOptions => ( | ||
<> | ||
<Input | ||
autoFocus | ||
type="search" | ||
className="typeahead-dropdown-input" | ||
placeholder={options.placeholder} | ||
aria-label={options.ariaLabel} | ||
onChange={(event) => handleSearch(event.currentTarget.value)} | ||
/> | ||
<div className="typeahead-dropdown-menu-scrollable-items"> | ||
{menuOptions} | ||
</div> | ||
</> | ||
); | ||
|
||
return ( | ||
<FacetDropdown | ||
items={transformMenuOptions(items)} | ||
title={title} | ||
isBold={isBold} | ||
type="typeahead" | ||
/> | ||
); | ||
}; | ||
|
||
TypeaheadFacetDropdown.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
items: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired, | ||
isBold: PropTypes.bool.isRequired, | ||
options: PropTypes.shape({ | ||
placeholder: PropTypes.string.isRequired, | ||
ariaLabel: PropTypes.string.isRequired, | ||
minLength: PropTypes.number.isRequired, | ||
}).isRequired, | ||
searchForItems: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default TypeaheadFacetDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.