Skip to content

Commit

Permalink
feat(searchbar): Added OnKeyDown functionality to Searchbars
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Moinuddin <[email protected]>
  • Loading branch information
Muhammed-Moinuddin committed Aug 16, 2024
1 parent 8eed0c2 commit df5187a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/custom/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ export interface SearchBarProps {
onClear?: () => void;
expanded: boolean;
setExpanded: (expanded: boolean) => void;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

function SearchBar({
onSearch,
placeholder,
onClear,
expanded,
setExpanded
setExpanded,
onKeyDown
}: SearchBarProps): JSX.Element {
const [searchText, setSearchText] = React.useState('');
const searchRef = React.useRef<HTMLInputElement | null>(null);
Expand Down Expand Up @@ -131,6 +133,7 @@ function SearchBar({
}}
inputRef={searchRef}
placeholder={placeholder}
onKeyDown={onKeyDown}
style={{
width: expanded ? '150px' : '0',
opacity: expanded ? 1 : 0,
Expand Down
3 changes: 3 additions & 0 deletions src/custom/StyledSearchBar/StyledSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TextField } from '../../base/TextField';

interface SearchBarProps {
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
value?: string;
width?: string;
label: string;
Expand All @@ -13,6 +14,7 @@ interface SearchBarProps {

function StyledSearchBar({
onChange,
onKeyDown,
value,
width,
label,
Expand All @@ -35,6 +37,7 @@ function StyledSearchBar({
type="search"
value={value}
onChange={onChange}
onKeyDown={onKeyDown}
sx={{
margin: 'auto',
height: '5ch'
Expand Down

0 comments on commit df5187a

Please sign in to comment.