Skip to content

Commit

Permalink
Merge pull request #391 from StampyAI/jrhender-379-search-placeholder
Browse files Browse the repository at this point in the history
feat(Input): add placeholder prop and set for Menu
  • Loading branch information
mruwnik committed Feb 12, 2024
2 parents 04b76d2 + 7d6d25d commit 3fecaa0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/CategoriesNav/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const CategoriesNav = ({categories, activeCategoryId}: CategoriesNavProps
return (
<div className={styles.categoriesGroup}>
<h4>Categories</h4>
<SearchInput onChange={onSearch} />
<SearchInput onChange={onSearch} placeholderText="Filter by keyword" />
{categories
.filter((tag) => tag.name.toLowerCase().includes(search.toLowerCase()))
.map(({tagId, name, questions}) => (
Expand Down
8 changes: 6 additions & 2 deletions app/components/SearchInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ interface SearchInputProps {
* Custom styles
*/
expandable?: boolean
/**
* Custom placeholder
*/
placeholderText?: string
}
export const SearchInput = ({onChange, expandable}: SearchInputProps) => {
export const SearchInput = ({onChange, expandable, placeholderText}: SearchInputProps) => {
const [search, setSearch] = useState('')
const handleSearch = (search: string) => {
setSearch(search)
Expand All @@ -29,7 +33,7 @@ export const SearchInput = ({onChange, expandable}: SearchInputProps) => {
<input
type="search"
name="searchbar"
placeholder="Search articles"
placeholder={placeholderText ?? 'Search articles'}
className="search-input"
onChange={(e) => {
handleSearch(e.currentTarget.value)
Expand Down
4 changes: 3 additions & 1 deletion app/routes/tags.all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const loader = async ({request, params}: Parameters<LoaderFunction>[0]) =
const {data: tags, timestamp} = await loadTags(request)

const tagId = params['*'] && params['*'].split('/')[0]
const currentTag = tagId ? tags.find(({tagId: checkedId, name}) => [checkedId.toString(), name].includes(tagId)) : tags[0]
const currentTag = tagId
? tags.find(({tagId: checkedId, name}) => [checkedId.toString(), name].includes(tagId))
: tags[0]

if (currentTag === undefined) {
throw new Response(null, {
Expand Down

0 comments on commit 3fecaa0

Please sign in to comment.